// JavaScript Document
$(function(){
		   	
	$(".menu_item").click(function(){
		
		$(".menu_children",this).slideToggle();
		
		$(".expand").not($(this)).each(function(){
			$(".menu_children",this).slideUp();
			$('.menu_arrow',this).attr('src','images/menu_arrow.png');
		});
		
		if($('.menu_arrow',this).attr("src")=='images/menu_arrow.png'){
			$('.menu_arrow',this).attr("src",'images/menu_arrow_down.png')
		}
		else{
			$('.menu_arrow',this).attr("src",'images/menu_arrow.png')
		}
	});	   
//	$("div.expand").hover(function(){
//		$ct = $(this).children().size()*7.5;
//		$(this).stop().animate({height:$ct+"px"},'slow');
//		}, function(){
//		$(this).stop().animate({height:"17px"},'slow');
//	});	   
	$(".sub_item, sub_menu").click(function(){
		//$(this).parent().stop().animate({height:"17px"});
	});	   
});

$(document).ready(function(){
						   
	$("a[rel='productos']").colorbox({innerWidth:"520px", innerHeight:"345px", iframe:true});
	$("a.prod_receta").colorbox({innerWidth:"520px", innerHeight:"345px", iframe:true});
	
	$('.pane_content').jScrollPane({showArrows:false});
	
	//contact validation
	$(".text-input").val("");  
	$(".button_contact").click(function() {  
		 // validate and process form here  
		 var p_nombre = $("input#p_nombre").val();
		 if (p_nombre == "") {  
		   alert ("Nombre y Apellido es un campo requerido");
		   $("input#p_nombre").focus();  
		   return false;  
		 }  
		 		 
		 var p_telefono = $("input#p_telefono").val();  
		 if (p_telefono == "") {  
		   alert ("Teléfono es un campo requerido");
		   $("input#p_telefono").focus();  
		   return false;  
		 }  
		 
		 var p_comentario = $("textarea#p_comentario").val();  
		 if (p_comentario == "") {  
		   alert ("Comentarios es un campo requerido");
		   $("input#p_comentario").focus();  
		   return false;  
		 }  
		
		 var email = $("input#p_correo").val();
		 if(isValidEmailAddress(email)==false)
				{
					alert ("Escribe una direccion de correo valida");
					$("input#p_correo").focus();  
					return false;  
				}
	});

});

function isValidEmailAddress(emailAddress) {
 		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
 		return pattern.test(emailAddress);
}

