$(document).ready(function() {
	//stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
	{
		//$(".footer_holder").css("position", "static");
	};
	
	$("a.fancybox").fancybox();
	$("a#inline").fancybox();
	
	// Image hover replacement
	$(".do_hover").mouseenter(function() {
		$(this).attr("src",$(this).attr("src").replace(".png","_on.png"));
	}).mouseleave(function(){
		$(this).attr("src", $(this).attr("src").replace("_on.png",".png"));
	});
	
	// Footer Handler
	 $(".footer_handle").click(function(){
		$(this).css("display","none");
		$(".footer_content").css("display","");
		$(".footer_holder").stop().animate({
			height: "300px"
		}, 300);
	})
	
	$(".footer_holder").mouseleave(function(){
		$(".footer_handle").css("display","");
		$(".footer_content").css("display","none");
		$(".footer_holder").stop().animate({
			height: "30px"
		}, 300);
	});

	// Ajax Search
	$(".q").keyup(function() { 
		if($("#q").val().length > 1){
			if($("#q").attr("lang") == "2"){
				des = "/he/searchAjax";
			}else{
				des = "/en/searchAjax";
			}
			$.ajax({
				url: des,
				type: "get",
				data: ({
					q: $("#q").val()
				}),
				success: function(data) {
					if(data.length > 5){
						$(".search_result").html(data);
						$(".search_result").css("display", "");
					}else{
						$(".search_result").css("display", "none");
					}
				}
			});
		}else{
			$(".search_result").css("display", "none");
		}
	}); 	
	
});

function chkSearch(){
	if($("#q").val().length<2){
		return false;
	}else{
		return true;
	}
}

function chkContact(){
	tmp = "";
	if($("#fname").val().length<1){
		tmp += $("#fname_err").val() +" \n";
	}
	if($("#phone").val().length<9){
		tmp += $("#phone_err").val() +" \n";
	}
	if($("#email").val().length<5 || $("#email").val().indexOf("@")==-1 || $("#email").val().indexOf(".")==-1){
		tmp += $("#email_err").val() +" \n";
	}
	if(tmp!=""){
		alert(tmp);
		return false;
	}else{
		return true;
	}
}
function chkContactTedy(){
	tmp = "";
	if($("#fname2").val().length<1){
		tmp += $("#fname_err").val() +" \n";
	}
	if($("#phone2").val().length<9){
		tmp += $("#phone_err").val() +" \n";
	}
	if($("#email2").val().length<5 || $("#email2").val().indexOf("@")==-1 || $("#email2").val().indexOf(".")==-1){
		tmp += $("#email_err").val() +" \n";
	}
	if(tmp!=""){
		alert(tmp);
		return false;
	}else{
		return true;
	}
}
