var fadingTimeOut=6000;
var divFading=0;
$(document).ready(function(){
   //Close all the opened tabs
   $("div#noticiesHome div.itemNoticia").not(":first").hide();
   $("div#finalCapsaNoticies div").toggle();
   
   //right menu
   	$("div#leftmenuEndHomeEEES a").toggle();
   	$("div.leftnotShowedHomeEEES").hide();
   	$("div#rightmenuEndHomeEEES a").toggle();
   	$("div.rightnotShowedHomeEEES").hide();
	$("div.rightMitesInterior").not(":first").hide();
	$("div.rightMitesInterior").css("position","absolute");
  
   
   
   //set up all the tab openers  
   $("div#finalCapsaNoticies div.persianaPlegada a").click(function(){
		$("div#noticiesHome div.itemNoticia").not(":first").show("slow");
	   $("div#finalCapsaNoticies div").toggle();
	});
	$("div#finalCapsaNoticies div.persianaDesplegada a").click(function(){
		$("div#noticiesHome div.itemNoticia").not(":first").hide("slow");
	   $("div#finalCapsaNoticies div").toggle();
	}); 
	
	
	$("div#leftmenuEndHomeEEES a.buttonMenu").click(function(){
		$("div#leftmenuEndHomeEEES a").toggle();
		if ($("div.leftnotShowedHomeEEES").is(":hidden")) {
			$("div#leftTestimoni").animate({height: "0px"}, "fast" );	
			$("div#leftTestimoni p").fadeOut("fast");			
	        $("div.leftnotShowedHomeEEES").slideDown("fast");
		
	    } else {
			$("div#leftTestimoni").animate({height: "90px"}, "fast" );	
			$("div#leftTestimoni p").fadeIn("fast");
			$("div.leftnotShowedHomeEEES").slideUp("fast");
	    }

	});
	
	

	$("div#rightmenuEndHomeEEES a.buttonMenu").click(function(){
		$("div#rightmenuEndHomeEEES a").toggle();
		if ($("div.rightnotShowedHomeEEES").is(":hidden")) {
			$("div#rightTestimoni").animate({height: "0px"}, "fast" );	
			$("div#rightTestimoni p").fadeOut("fast");			
	        $("div.rightnotShowedHomeEEES").slideDown("fast");
		
	    } else {
			$("div#rightTestimoni").animate({height: "90px"}, "fast" );	
			$("div#rightTestimoni p").fadeIn("fast");
			$("div.rightnotShowedHomeEEES").slideUp("fast");
	    }
	}); 
	//set up the images fading  in and out
	setTimeout("changeFading()", fadingTimeOut);
	
	$("div.rightMitesSelector a.rightMitesSelectorRight").click(function(){
		var divs=$("div.rightMitesInterior");

		if(divs.length>0){
			nextDivFading=(divFading+1)%divs.length;
			$("div.rightMitesInterior").eq(divFading).fadeOut("slow");	
			$("div.rightMitesInterior").eq(nextDivFading).fadeIn("slow");
			divFading=nextDivFading;
		}
	}); 
	
	$("div.rightMitesSelector a.rightMitesSelectorLeft").click(function(){
		var divs=$("div.rightMitesInterior");
		
		if(divs.length>0){
			nextDivFading=(divFading-1)%divs.length;
			if(nextDivFading<0)
				nextDivFading=divs.length-1;
			$("div.rightMitesInterior").eq(divFading).fadeOut("slow");	
			$("div.rightMitesInterior").eq(nextDivFading).fadeIn("slow");
			divFading=nextDivFading;
		}
	});  
});

var imgFading=0;
function changeFading(){
	var imgs=$("div#imatgeLinksHome img");
	if(imgs.length>0){
		nextImgFading=(imgFading+1)%imgs.length;
		if(imgFading==0){
			$("div#imatgeLinksHome img.notVisible").fadeOut("slow");	
		}else{
			$("div#imatgeLinksHome img").eq(imgFading).fadeIn("slow");
		}
		imgFading=nextImgFading;
		setTimeout("changeFading()", fadingTimeOut);
	}
}

