/**
 * @author Javier
 */

var timer;
var pics = new Array();
var current=0;

$(document).ready(function(){
	
	$("#main_logo").html('<img src="/images/gui/caxao.gif" />');
	$("#main_logo").click(function(){ location='/?demo=1'; });
	
	$(".nav li").each(
		function(i){
			var img = $("a",$(this)).html();
			
			img = img.replace(/ /g,"_");
			$("a",this).html("<img src='/images/nav/" + img.toLowerCase() + ".png' />");
			/*
			$("a",this).hover(
				function(){
					var img1 = $("img",$(this)).attr("src");
					img1 = img1.replace(/\./,'_over.');
					$("img",$(this)).attr("src",img1);
				},
				function(){
					var img2 = $("img",$(this)).attr("src");
					img2 = img2.replace(/\_over\./,".");
					$("img",$(this)).attr("src",img2);
				}
			);
			*/
		}
	);
	
	if ($("h1").length>0) {
		var title = $("h1").html().replace(/ /g,"_").toLowerCase();
		title = title.replace(/é/,'e');
		$("h1").html('<img src="/images/titles/'+title+'.png" />');
	}
	
	if ($("#intro").length>0) {
		$("#intro").flash({
			src:'media/intro.swf',
			width: 980,
			height:440,
			wmode:'transparent'
		});
	}
	
	if ($("#send").length > 0) {
		$("#send").click(function(){
			$("#contacto").submit();
		});
	}
	if ($("#contacto").length > 0) {
		$("#contacto").validate({
			rules: {
				names: "required",
				emails: {
					required: true,
					email: true
				}
			},
			messages: {
				names: "Your name is required",
				emails: {
					required: "A valid email account is required",
					email: "A valid email account is required"
				}
			}
		});
	}
	
	if ($(".slide img").length > 0) {
		$(".slide img").each(function(i){
			pics.push($(this));
			if (i != 0) {
				$(this).hide();
			}
		});
		
		slide = setInterval("doSlide()", 5000);
	}
	
});


function doSlide(){
	var next = current+1;
	if (next>pics.length-1) next=0;
	$(pics[current]).fadeOut();
	$(pics[next]).fadeIn();
	current++;
	if (current>pics.length-1) current=0;
}


