$(document).ready(function() {   
  
  	var scrollpos = $(window).height() + $(window).scrollTop() - 300;	
		$('#social').css({ top: scrollpos });
  
  	 $(window).scroll(function(){
				
				var scrollpos = $(window).height() + $(window).scrollTop() - 300;
				$('#social').animate({top: scrollpos +"px" },{queue: false, duration: 600});	
					
		 });
  
  	 function makeVisible(){
  	 		$(this).children('a').addClass('dropped');
  	 		$(this).children('ul.dropdown').css({ display: 'block' });
  	 }
  	  
  	 function makeInvisible(){
  	  	$(this).children('ul.dropdown').css({ display: 'none' });
  	 		$(this).children('a').removeClass('dropped');
  	 }
  	 
  	 function chColor1(){
	 	 		$(this).parent('li').children('a').css({ color: '#bf9b98' });	
	 	 }
 	
	 	 function chColor2(){
	 	 		$(this).parent('li').children('a').css({ color: '#7f1913' });
	 	 }
  	  
  	var configintent = {    
	     sensitivity: 100, 
	     interval: 0,     
	     over: makeVisible,   
	     timeout: 0,  
	     out: makeInvisible    
		};
		var configintent2 = {    
	     sensitivity: 100,    
	     interval: 0,     
	     over: chColor1,  
	     timeout: 0,
	     out: chColor2 
		};
	
		$('li.dd').hoverIntent( configintent );
		$('ul.dropdown').hoverIntent( configintent2 );


		function echeck(str) {
	
				var at="@"
				var dot="."
				var lat=str.indexOf(at)
				var lstr=str.length
				var ldot=str.indexOf(dot)
				if (str.indexOf(at)==-1){
				   return false
				}
				
				if (str.indexOf(at)==-1 || str.indexOf(at)== 0 || str.indexOf(at)==lstr){
				   return false
				}
				
				if (str.indexOf(dot)==-1 || str.indexOf(dot)== 0 || str.indexOf(dot)==lstr){
				    return false
				}
				
				if (str.indexOf(at,(lat+1))!=-1){
				  return false
				}
				
				if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
				  return false
				}
				
				if (str.indexOf(dot,(lat+2))==-1){
				  return false
				}
				
				if (str.indexOf(" ")!=-1){
				  return false
				}
	
				return true
		}

	  $('a#send').click(function(){
				
				var name_len = $("input#names").attr('value').length;
        var email_len = $("input#email").attr('value').length;
        var captcha_len = $("input#captcha").attr('value').length;        
        var comment_len = $("#comment").attr('value').length;

				var email_val = $("input#email").attr('value');

				if(name_len < 3){
        
          alert('Моля, въведете име!');
          $("input#names").focus();
        
        }else if(email_len < 3 || echeck(email_val) == false){
        
        	alert('Моля, въведете реален email');
          $("input#email").focus();
        
        }else if(comment_len < 3){
        
        	alert('Моля въведете вашето запитване');
          $("#comment").focus();
        
        }else if(captcha_len != 5){
        
        	alert('Моля, въведете 5 цифрения код от картинката!');
          $("input#captcha").focus();
        
        }else{

					$('form#contacts').submit();

				}				

		});

		$("a.framebox").fancybox({
				'hideOnContentClick': false
		});



});  

jQuery(window).bind("load", function() {
	jQuery("div#slider1").codaSlider();
});