





$(document).ready(function(){



	var fake_href = "<a href='#' onclick='return false;'></a>";





	$("ul.photos li").each(function(i){

		if(i==0) $(this).show();



		var li = '<li><a href="#">'+(i+1)+'</a></li>';

		$("ul.galleryLinks").append(li);

	});





	$("ul.galleryLinks a").each(function(i){

		if(i==0) $(this).addClass("sel");

		$(this).click(function(){



			var gLinks = $(this).parents("ul:eq(0)");

			var gLinksId = gLinks.attr("id");



			$("a", gLinks).removeClass("sel");

			$(this).addClass("sel");



			var photosId = gLinksId.split("_links").join("");

			var photos = $("#"+photosId).children();



			photos.each(function(j)

			{

				if(i==j)

				{

					if (j<=7)
					{
						$('#titulo').text("Administración pública");
					}
					else
					{
						$('#titulo').text("Organización de eventos");
					}

					$(this).fadeIn();

				}

				else

				{

					$(this).fadeOut();

				}

			});

			return false;

		});

	});







	//MENU

	$("ul#nav > li").bind("mouseenter",function(){

		if(!$(this).hasClass("sel")) $(this).find("ul").show();

	});



	$("ul#nav > li").bind("mouseleave",function(){

		if(!$(this).hasClass("sel")) $(this).find("ul").hide();

	});





});





var formulario = {

	error: false,

	validate: function(theForm)

	{

		formulario.error = false;

		var e_field = $("#error", theForm).text("");



		formulario.checkHasValue( $("#empresa", theForm) );

		formulario.checkHasValue( $("#persona", theForm) );

		formulario.checkHasValue( $("#email", theForm) );

		formulario.checkIsValidEmail( $("#email", theForm) );



		if(formulario.error){

			e_field.text("Por favor, revise los datos introducidos.");

		}

		else

		{

			$("input[type='submit']", theForm).attr("disabled","disabled");

			var data = {

				empresa: $("#empresa", theForm).val(),

				persona: $("#persona", theForm).val(),

				telefono: $("#telefono", theForm).val(),

				fax: $("#fax", theForm).val(),

				email: $("#email", theForm).val(),

				observaciones: $("#observaciones", theForm).val()

				};

			$.post("submit.php", data, formulario.callback );

			e_field.text("Enviando...");

		}

		return false;

	}

	,

	checkHasValue: function(field)

	{

		if( field.val()=="" ){

			formulario.error = true;

			formulario.markError( field , true);

		}else{

			formulario.markError( field , false)

		}

	}

	,

	checkIsValidEmail: function(field)

	{

		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

		if (!filter.test( field.val() )) {

			formulario.error = true;

			formulario.markError( field , true);

		}else{

			formulario.markError( field , false)

		}

	}

	,

	markError: function(field, hasError)

	{

		if(hasError)

		{

			field.addClass("error");

		}

		else

		{

			field.removeClass("error");

		}

	}

	,

	callback: function(data)

	{

		$("#empresa").val("");

		$("#persona").val("");

		$("#telefono").val("");

		$("#fax").val("");

		$("#email").val("");

		$("#observaciones").val("");

		$("#error").text("Su solicitud ha sido enviada. Muchas gracias.");

		$("input[type='submit']").removeAttr("disabled");

	}



}






