// JavaScript Document
var idioma = $("html").attr("lang");

$(document).ready(function(){
	
	/* PNGFix pel PNG de la capçalera */
	
	$(document).pngFix();
		
	/*Print*/
	
	$(".print img").click(function(){ print();});

	/** Image Gallery **/
	
	$("#thumbnail li a").click(function(){
			$("#large img").attr({"src": $(this).attr("href"), "title": $("> img", this).attr("title")});
				
			return false;
		});

	$("#large>img").load(function(){$("#large>img:hidden").fadeIn("slow")});
	
	
	/** Image carousel **/
	

		
	$("dl#llistat-actes dd").each(function(){	
		
		$(this).css("cursor","pointer");
		$(this).siblings("dt").css("cursor","pointer");
		
		$(this).click(function(){
			
			window.open($(this).children("a").attr("href"),"_self");
		},$(this).prev("dt").click(function(){
			
			window.open($(this).next("dd").children("a").attr("href"),"_self");					  
											  
		}));
		
		
		$(this).html($(this).children("a").addClass("link-actes"));
	
	});
	
	
	
	$("#llistat-benvingudes div").each(function(){	
		
		$(this).css("cursor","pointer");
		
		$(this).click(function(){
			
			window.open($(this).find("a").attr("href"),"_self");
		});
		
		
		$(this).find("a").addClass("link-benvinguda");
	
	});
	
	
	
	
	$("dl#llistat-actes dd").mouseover(function(){
  	    $(this).prev("dt").css("background-color","#00C0F3");
		$(this).css("background-color","#00C0F3");
		$(this).children("a").css("color","#FFF");	
		
	}).mouseout(function(){
       $(this).prev("dt").css("background-color","#fff");
	   $(this).css("background-color","#FFF");
       $(this).children("a").css("color","#555");	
	});
	
	
	
	$("dl#llistat-actes dt").mouseover(function(){ 
			$(this).css("background-color","#00C0F3"); 
			$(this).next("dd").css("background-color","#00C0F3"); 
			$(this).next("dd").children("a").css("color","#FFF"); 	
	}).mouseout(function(){
	     	$(this).css("background-color","#FFF");
			$(this).next("dd").css("background-color","#FFF");
			$(this).next("dd").children("a").css("color","#555");	

	});
	
	
	/** main menu **/
	
	$("#main-menu ul li ul").hide();
	
	var atrclass = $("body").attr("class");
	
	$("#main-menu ul li ul."+atrclass+"-3").show();
	$("#main-menu ul li ul."+atrclass+"-2").show();
	$("#main-menu ul li ul."+atrclass+"").show();
	
	

	$("#main-menu ul li span").each(function(){
		$(this).addClass("active");	
	});
	
	if($("body").hasClass("section-how-to-get")){
		$("#main-menu ul li ul.m-sobre-bcn-2").show();
		$("#main-menu ul li ul.m-sobre-bcn-2").prev("span").removeClass("active");
	}
	
	if($("body").hasClass("m-cami-locals")){
		$("#main-menu ul li ul.m-cami-locals").show();
		$("#main-menu ul li ul.m-cami-locals").prev("span").removeClass("active");
		$("#main-menu ul li ul.m-cami-3").show();
		$("#main-menu ul li ul.m-cami-2").hide();
	}
	
	$("#main-menu ul li ul."+atrclass+"-2").prev("span").removeClass("active");
	$("#main-menu ul li ul."+atrclass+"-3").prev("span").removeClass("active");
	$("#main-menu ul li ul."+atrclass+"").prev("span").removeClass("active");
	
	
	$("#main-menu ul li span").click(function(){
			if($(this).hasClass("active")){
				$(this).removeClass("active");
				$(this).siblings("ul").slideDown('slow');
				$(this).parents("map").siblings("map").find("ul li ul").slideUp('slow');
				$(this).parents("map").siblings("map").find("span").addClass("active");
			}
			else {				
				$(this).addClass("active");
				$(this).siblings("ul").slideUp('slow');
			}
			//$("#main-menu ul li ul:visible").siblings("span").bind('click');
			//$(this).unbind('click');
	});
	
	
	/** extreure la URL */
	
	
	
	var urlarray = window.location.toString().split("/");
	
	$("#main-menu ul li a").each(function(){
		
	if($(this).attr("href") == urlarray[urlarray.length-1]){
		$(this).parent("li").html($(this).text());	
	}
	
	
	});
										
	
	
	
	$("#main-menu ul li").find("a",function(){
		
		alert($(this).html());
		
	});

	

	
	
	

	/** box information **/
	
	$(".box-information, #temps").mouseover(function(){ $(this).css("cursor","pointer"); });
	
	$(".box-information, #temps").click(function(){
		
		var url = $(this).attr("id");
	
		switch(url){
			
			case "information" :
			  window.open("../"+idioma+"/informacio-turistica.html", "_self");
			break;
			 
			case "how-to" :
			  window.open("../"+idioma+"/com-arribar.html", "_self");
			break;
			
			case "accomodation" :
			  window.open("../"+idioma+"/on-allotjarse.html", "_self");
			break;
			
			default :
			 window.open("http://www.bcn.es/cgi-bin/pt.pl?url=http://www.bcn.es/temps/catala/", "");
			break;
		
		}
	
	});
	
	
	/** Image capcalera **/

	if($("#welcome").length > 0) { // Es la welcome
	
		totalImatges = 14;
		valorRandom = (Math.floor(Math.random() * totalImatges) + 1);
		switch(valorRandom){
			case 1: case 2:	case 3: case 4:
				nImatge = 1;
			break;
			case 5: case 6: case 7: 
				nImatge = 2;
			break;
			case 8: case 9:
				nImatge = 3;
			break;
			case 10: case 11:
				nImatge = 4;
			break;
			case 12:
				nImatge = 5;
			break;
			case 13: case 14:
				nImatge = 6;
			break;
		}
		$("#header").css("background", "url(../img/header-"+nImatge+".jpg) no-repeat");
	}
	else{ // Es una pagina interior
		totalImatges = 8; //Numero d'imatges que hi ha a la capçalera.
		var nImatge = Math.floor(Math.random() * totalImatges) + 1; // Li sumo 1 pq no hi hagi aparegui el 0
		$("#header").css("background", "url(../img/second-header-"+nImatge+".jpg) no-repeat");
	}
	
	
});
