var bOpenedRecommend = false;
var bFirstCourse = false;
var bTabClicked;
var iPositions = 1;
/*
var bTabCosts = false;
var bTabTime = false;
var bTabLocation = false;
*/
$(document).ready(function(){


	// MENU HEADER
	$("#header li:not(.active-trail)").mouseover(function(){
		if ($(this).attr("class").indexOf("clicked") != -1) return;
		$(this).attr("class", "over");
	})
	
	$("#header li:not(.active-trail)").mouseout(function(){
		if ($(this).attr("class").indexOf("clicked") != -1) return;
		$(this).attr("class", "out");
	})
	
	$("#header li").click(function(){
		window.location = $(this).find("a").attr("href");
	})
	
	$("#edit-submit").mouseover(function(){
		$(this).css("background-position", "0px -30px");
	})
	$("#edit-submit").mouseout(function(){
		$(this).css("background-position", "0px 0px");
	})
	


	// CONTACT
	$("#button-contact").click(function(){				
		if (!bOpenedRecommend) {
			$("#block-spread-0").show("fast")
			$(this).attr("class", "over clicked");
		} else {
			$("#block-spread-0").hide("fast")
			$(this).attr("class", "over");
		}		
		bOpenedRecommend = !bOpenedRecommend		
	})	
	$("#close-spread").click(function(){
		bOpenedRecommend = false;
		$("#block-spread-0").hide("fast")	
		$("#button-contact").attr("class", "out");	
	})	
	$("#block-spread-0").find("form").attr("action", "gracias-por-recomendarnos");
	$("#block-spread-0").find("input[type=text]").focus(function(){		
		if ($(this).attr("title") == "") $(this).attr("title", $(this).val());
				
		if ($(this).attr("title") == $(this).val()) $(this).val("");		
	})
	$("#block-spread-0").find("input[type=text]").blur(function(){
		if ($(this).val().split(" ").join("") == "") $(this).val( $(this).attr("title") )
	})

	$("#edit-submit-1,#edit-submit-2").click(function(){
	
		var regexp = new Array();
		regexp[0] = /^.{3,}$/;
		regexp[1] = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
		regexp[2] = /^.{3,}$/;
		regexp[3] = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
		var component = new Array("edit-sender-name", "edit-sender-mail", "edit-friend-name", "edit-spread-mail-0");

		var flag = true;
		
		for (var x=0;x<regexp.length;x++) {
			if (regexp[x].test($("#" + component[x]).val()) && $("#" + component[x])[0].defaultValue != $("#" + component[x]).val()) {
				$("#" + component[x]).css("border", "2px solid #fff");
			} else {
				$("#" + component[x]).css("border", "2px solid #f00");
				flag = false;
			}
		}				
		if (!flag && $("#spread-error").length == 0) {
			$("#" + component[component.length-1]).after("<p id='spread-error' class='error'>Por favor verifica los campos marcados con rojo.</p>")
		} 		
		if (flag) $("#spread-error").remove();
		return flag;
	})
	
	
	// FIRST COURSE
	$("#first-course-link").click(function(){
		bFirstCourse = !bFirstCourse;
		if (bFirstCourse) {
			$(this).text("Cerrar info");
			$("#first-course").show("fast");
			$(".col3").css("border-bottom", "2px solid #ccc");
			$("body").animate({ scrollTop: $("body").attr("scrollHeight") }, 2000);

		} else {
			$(this).text("Ver detalles");
			$(".col3").css("border-bottom", "");
			$("#first-course").hide("fast");
		}
	})	
	$("#first-course").hide(0);
	
	
	
	// MENU LEFT
	$("#left li:not(.active)").mouseover(function(){	
		$(this).attr("class", $(this).attr("class").split("out").join("") + " over" );
	})
	$("#left li:not(.active)").mouseout(function(){
		$(this).attr("class", $(this).attr("class").split(" over").join(""));
	})
	$("#left li").click(function(){
		window.location = $(this).find("a").attr("href");
	})
	
	
	
	// MENU BOTTOM
	$("#button-bottom li").mouseover(function(){
		if (bTabClicked == this) return;
		$(this).attr("class",  $(this).attr("class").split("out").join("") + " over" );
	})	
	$("#button-bottom li").mouseout(function(){
		if (bTabClicked == this) return;
		$(this).attr("class",  $(this).attr("class").split("over").join("") + " out" );
	})	
	$("#button-bottom li").click(function(){		
		
		//alert($("#tab-hours").attr("id"))
		//alert($(this).attr("id"))
		//alert($("#tab-hours").get(0) == this)
		
		//if ($("#button-time").get(0) == this) $("#hour-sept").trigger("click");
		
		var arr1 = new Array("#tab-hours", "#tab-costs", "#tab-location");
		var arr2 = new Array("#button-time", "#button-costs", "#button-location");
		
		if (bTabClicked != this) {		
		bTabClicked = this
		for (var i = 0; i<arr1.length; i++) {
			if ($(arr2[i]).get(0) == this) {
				$(arr1[i]).show("fast");
			} else {
				$(arr1[i]).hide("fast");
				$(arr2[i]).attr("class", "no-clicked" );
			}
		}
		$(this).attr("class", "clicked");	
			
		} else {
			
			for (var i = 0; i<arr1.length; i++) {
				if ($(arr2[i]).get(0) == this) {
					$(arr1[i]).hide("fast");
					$(this).attr("class",  $(this).attr("class").split("clicked").join("") + " over");
					break;
				}
			}
			
			bTabClicked = undefined;			
		}
		
	})	
	$("#tab-costs").hide(0);
	$("#tab-hours").hide(0);
	$("#tab-location").hide(0);
	
	
	
	
	// FORMULARIO
	$("#webform-client-form-6").find("input[type=text]").focus(function(){		
		if ($(this).attr("title") == "") $(this).attr("title", $(this).val());
				
		if ($(this).attr("title") == $(this).val()) $(this).val("");		
	})
	$("#webform-client-form-6").find("input[type=text]").blur(function(){
		if ($(this).val().split(" ").join("") == "") $(this).val( $(this).attr("title") )
	})
	
	$("#webform-client-form-6").find("textarea").focus(function(){		
		if ($(this).attr("title") == "") $(this).attr("title", $(this).val());
				
		if ($(this).attr("title") == $(this).val()) $(this).val("");		
	})
	$("#webform-client-form-6").find("textarea").blur(function(){
		if ($(this).val().split(" ").join("") == "") $(this).val( $(this).attr("title") )
	})
	
		
		
	$("#edit-submit").click(function(){
	
			var regexp = new Array();
			regexp[0] = /^.{3,}$/;
			regexp[1] = /^.{3,}$/;
			regexp[2] = /^.{3,}$/;
			regexp[3] = /^.{3,}$/;
			regexp[4] = /^.{6,}$/;
			regexp[5] = /^.{3,}$/;
			regexp[6] = /^.{3,}$/;
			
			var component = new Array();
			component[0] = "nombres";
			component[1] = "apellido-paterno";
			component[2] = "apellido-materno";
			component[3] = "generoescoge";
			component[4] = "direccion-de-correo-electronico";
			component[5] = "asunto--titulo-del-mensaje";
			component[6] = "tus-comentarios";
			
			
		for (var x=0;x<regexp.length;x++) {
			
			var re = regexp[x].test($("#" + component[x]).val());
			var de = $("#edit-submitted-" + component[x])[0].defaultValue != $("#edit-submitted-" + component[x]).val()
			var se = $("#edit-submitted-" + component[x]).val() != "Género"
					
			//alert($("#edit-submitted-" + component[x])[0].defaultValue)		
					
			if (re && de && se) {
				$("#edit-submitted-" + component[x]).css("border", "1px solid #fff");
			} else {
			
				//alert(re +":"+ de +":"+ se)
				$("#edit-submitted-" + component[x]).css("border", "1px solid #f00");
				flag = false;
			}
		}				
		if (!flag && $("#contact-error").length == 0) {
			$("#webform-component-tus_comentarios").after("<p id='contact-error' class='error'>Por favor verifica los campos marcados con rojo.</p>")
		} 		
		if (flag) $("#contact-error").remove();
		return flag;
	});
	
	
	
	$(".las-26-posturas-inside ul").each(function(){
		$(this).css("background-image", "url('sites/all/themes/bikram/img/positions/"+iPositions+"-BYC.jpg')")
		iPositions++;
	})
	
		
		
})

