//rotation************
//Define Global vars for nextNews
i = 0;
time = 10000;
element = '#slide .rotation';
var actNextNews;
//End Define Global vars for nextNews


function nextNews()
{
    var amount = jQuery(element).length;
    if(amount > i+1)//amount > that number order (i+1) of .content
							{
	jQuery(element).eq(i).fadeOut(1000);
                                    jQuery(element).eq(i+1).fadeIn("1000");
									i++;
	clearTimeout(actNextNews);
							}
							else
							{
	jQuery(element).eq(i).fadeOut(1000);
                                    jQuery(element).eq(0).fadeIn(1000);
									i = 0;
	clearTimeout(actNextNews);
	}
   if(time != 0) actNextNews = setTimeout(nextNews,time);
}
//********************



$(document).ready(function(){
    Shadowbox.init();
	
	//rotation************
	$(element).eq(i).css({display:"block"});
	actNextNews = setTimeout(nextNews,time);
	//********************
	//TERMINAR EL ROTATION Y CARGAR LA IMAGEN SEGUN EL BOTON QUE SELECCIONO
	$(".img-butons a").click(function(){//cuando hago click sobre el thumbnail
                                    //console.log("asdfsadf");
                                    var id = $(this).attr("href");

									$("#slide").attr("id","noslide");
									$(".rotation").css({display:"none"});
									$("#"+id).css({display:"block"});
                                    //load_img;
                                    return false; //esto es para que no ejecute el link y vaya a directamente a la imagen
                                    });
	
	//*********************************************************************
	$("div.in").find("a.clicked").each(function(){

		$(this).click(function(){
					
			if(!($(this).siblings().css("display") == "block")){
								
				$("div.out_a").removeClass("out_b");				
				$(".all").hide("slow");
				$(this).siblings().show("normal");
				$(this).parent().parent().addClass("out_b");

				return false;
				
			}else{
				
				$(this).siblings(".all").hide("slow");
				$(this).siblings().hide("normal");
				$(this).parent().parent().removeClass("out_b");
				
				return false;
				
			}
			
			/*if($(this).parent().parent().css() == "out_a"){
			}else{
				$(this).parent().parent().removeClass("out_b");
			}*/
			
			
		  });
		
	
	//(".header_down ul li ul.submenu").children("li:hover").css("background", "url(images/bg_header_down.jpg) repeat-x");	
		
	   });
	

	var setMenu = function(){    jQuery(".header_down table tr > td .link_pos").hover(function(){

 					                //jQuery(".header ul li ul").stop();
                                    //jQuery(".header ul li").children("ul").stopAll();
                                    
                                    //jQuery(".header ul li").children("ul").css({display:"none"});
                                    //jQuery(".header ul li").not(this).unbind();
                                    jQuery(this).children("ul").slideToggle("fast");							
									//jQuery(this).children("ul").css({display:"block"});
									
								},function(){
                                    //jQuery(".header ul li ul").stop();
                                   // jQuery(".header ul li").children("ul").stopAll();
								   	jQuery(this).children("ul").slideToggle("fast");
									//jQuery(this).children("ul").css({display:"none"});
									//jQuery(".header ul li").unbind();
									//setMenu();

											});
											
};
setMenu();
	
	
	var setMenu2 = function(){    jQuery(".header_down ul li").hover(function(){

 					                jQuery(".header2 ul li ul").stop();
                                    //jQuery(".header ul li").children("ul").stopAll();
                                    
                                    jQuery(".header2 ul li").children("ul").css({display:"none"});
                                    jQuery(".header2 ul li").not(this).unbind();
                                    								
									jQuery(this).children("ul").css({display:"block"});
									
								},function(){
                                    jQuery(".header2 ul li ul").stop();
                                   // jQuery(".header ul li").children("ul").stopAll();
									jQuery(this).children("ul").css({display:"none"});
									jQuery(".header2 ul li").unbind();
									//setMenu();
									
											});
											
};
//setMenu2();

	var setMenu2 = function(){    jQuery(".header_down ul li").hover(function(){

 					                jQuery(".header ul li ul").stop();
                                    //jQuery(".header ul li").children("ul").stopAll();
                                    
                                    jQuery(".header ul li").children("ul").css({display:"none"});
                                    jQuery(".header ul li").not(this).unbind();
                                    								
									jQuery(this).children("ul").css({display:"block"});
									
								},function(){
                                    jQuery(".header ul li ul").stop();
                                   // jQuery(".header ul li").children("ul").stopAll();
									jQuery(this).children("ul").css({display:"none"});
									jQuery(".header ul li").unbind();
									//setMenu();
									
											});
											
};
//setMenu2();
	
	

 jQuery("#SelectOption").change(function(){

									   if(jQuery("#SelectOption").val() == "Other")
									   {
										   jQuery("#FieldOthers").css("display","block");
										   jQuery("#FieldOthers").val("Enter Other Option");

									   }
									   else
									   {
										   jQuery("#FieldOthers").css("display","none");
										   jQuery("#FieldOthers").val("");
									   }

									   });
									   
    jQuery("form#formInterest").submit(function() {

			
			if (!isFormValid('#formInterest'))
			{
				alert("Please fill in the required fields marked with a *");
				return false;
			} else
			{
				return true;
			}

  });
  
  jQuery("form#formContact").submit(function() {


			if (!isFormValid('#formContact'))
			{
				alert("Please fill in the required fields marked with a *");
				return false;
			} else
			{
				return true;
			}

  });
  
  jQuery("form#formInvitation").submit(function() {


			if (!isFormValid('#formInvitation'))
			{
				alert("Please fill in the required fields marked with a *");
				return false;
			} else
			{
				return true;
			}

  });
	
});

function isFormValid(thisform){
	var ok = true;

	jQuery("form"+thisform+"").find(".required").each(function(){
		if(this.value == "")
			ok = false;
	});

    jQuery("form"+thisform+"").find(".email").filter(".required").each(function(){
		if(!valid_email(this.value))
			ok = false;
	});

return ok;
}



function valid_email(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
}

function another(n){
    jQuery("#formInvitation #another").val(n);
    
    	if (!isFormValid('#formInvitation'))
			{
				alert("Please fill in the required fields marked with a *");
				return false;
			} else
			{
                document.formInvitation.submit();
			}
    
}
/*	RSVP FORM	*/
function showRSVPForm(){
						
						jQuery(".rsvpform .bodyRSVP").css("display","block");
					jQuery(".rsvpform .message").css("display","none");
					jQuery(".rsvpformBg").show("slow");
}
function closeRSVPForm(){
						$(".rsvpformBg").hide("slow");
}
function rsvpSubmit(){
	var ok = true;
	jQuery("form#formrsvp").find(".required").each(function(){
		if(this.value == "")
			ok = false;
	});

    jQuery("form#formrsvp").find(".email").filter(".required").each(function(){
		if(!valid_email(this.value))
			ok = false;
	});
	
	if(ok)
	{
		var firstname = jQuery("#formrsvp input#firstname").val();
		var lastname = jQuery("#formrsvp input#lastname").val();
		var email = jQuery("#formrsvp input#email").val();
		var number = jQuery("#formrsvp input#number").val();
		var comments = jQuery("#formrsvp #comments").val();
		var headerForm = jQuery("#formrsvp #headerForm").val();
		var title = jQuery("#formrsvp #title").val();
		var subject = jQuery("#formrsvp #subject").val();
		var thanks = jQuery("#formrsvp input#thanks").val();
		var max = jQuery("#formrsvp #max").val();		
		
		$.post("libs/form_engine.php",
        		  { first_name: firstname,
					last_name: lastname,
					email: email,
					number: number,
					comments: comments,
					headerForm: headerForm,
					title: title,
					subject: subject,
					thanks: thanks,
					max: max
					},
        		  function(data){
					jQuery(".rsvpform .bodyRSVP").css("display","none");
					jQuery(".rsvpform .message").css("display","block");					
        		  }
        		);
		
	}
	else alert('Please fill in the required field marked with a *');
}

