		// JavaScript Document
	
	
	


$(document).ready(function(){
			var MAX_ANIM = 15;			   
			var t=true;	
			var c=0;
	function runEffect() { 
		var randomnumber=Math.floor(Math.random()*11);
		var nombre = "#";
		c++;
		switch(randomnumber){
			case 0:
				nombre += "cero";
			break;
			case 1:
				nombre += "primero";
			break;
			case 2:
				nombre += "segundo";
			break;
			case 3:
				nombre += "tercero";
			break;
			case 4:
				nombre += "cuarto";
			break;
			case 5:
				nombre += "quinto";
			break;
			case 6:
				nombre += "sexto";
			break;
			case 7:
				nombre += "septimo";
			break;
			case 8:
				nombre += "octavo";
			break;
			case 9:
				nombre += "noveno";
			break;
			case 10:
				nombre += "decimo";
			break;
			default:
				nombre += "cero";
			break;
			
			}
			if(t&&(c<MAX_ANIM)){
				$(nombre).find("img").animate({left:'50px'},{queue:true,duration:500}).delay(1500).animate({left:'25px'},{queue:true,duration:500});
				setTimeout(runEffect, 3000);
			}
	}					   
	
		
	runEffect();

   //navegacio
						   
						   
   $("#nav a").each(function(){
	
      var href = $(this).attr("href");
	  var posx = $(this).attr("x");
	  var posy = $(this).attr("y");
      $(this).click(function(){
		
		if(!($(this).hasClass('actiu'))){
			 $("#nav li").find(".actiu").find("img").animate({left:'25px'},{queue:true,duration:500});
			 $("#nav li").children().removeClass('actiu');
			 $(this).addClass("actiu");
			 $("#front").hide(); //Le damos efecto    
			 $("#front").load(href); //Le damos efecto
			 $(this).attr({ href: "#"});
			 $("#front").attr({style:"top:"+posy+";left:"+posx+";"});
			 $(this).find("img").animate({left:'50px'},{queue:false,duration:500});
		}
      });
	  
	  $(this).hover(function () { //ROLLOVER
		t=false;
							  
	  if(!($(this).hasClass('actiu'))){/*
		 $("#nav li").children('[class!="actiu"]').find("img").delay(500).animate({left:'0px'},{queue:true,duration:500});
		 $("#nav li").children('[class="actiu"]').children('.gif').attr({src: "img/21x21_cruz.gif"});*/
     	 $(this).find("img").animate({left:'50px'},{queue:true,duration:500});
     	 $(this).children(".txtlink").show("fast");
         $("#front").hide(); //Le damos efecto  
		 $("#nav li").children('[class="actiu"]').children('.txtlink').hide();  
	  }
		 
   	  }, function () { //ROLLOUT
	  if(!($(this).hasClass('actiu'))){
		// $("#nav li").children('[class!="actiu"]').children('.gif').attr({src: "img/cuad_reposo.gif"});
      	 $(this).find("img").animate({left:'25px'},{queue:true,duration:500});
     	 $(this).children(".txtlink").hide("fast");
		 $("#nav li").children('[class="actiu"]').children('.txtlink').show();
		 //$("#nav li").children('[class="actiu"]').children('.gif').attr({src: "img/21x21_cruz.gif"}); 
         $("#front").delay(500).show(); //Le damos efecto    
	  }
      });
	  
	  
   });
	
   
   
});
