// JavaScript Document
var idioma = $("html").attr("lang");
var pathSite = $("meta[@name=base]").attr("content");

$(document).ready ( function() {

	// Substituim els titols de seccio per les corresponents imatges.
	// ---------------------------------------------------------------------------------------------------------------------
		
	$(".titol").each ( function() {
		var c = this.className.split(/\s+/);
		$(this).html('<img src="../imatges_accessible/img09/'+idioma+'/'+c[1]+'.gif" alt="'+$(this).text()+'" />');
	});
	
	
	// formulari webs ajuntament
	// ---------------------------------------------------------------------------------------------------------------------
	
	$("#envia-form").hide();
	$("#frmLink").addClass("js");
	$("#weblinks").change(function() {
		$("#frmLink").submit();
	});
	
	
	
	// script de navegacio webs destacades
	// ---------------------------------------------------------------------------------------------------------------------
	
	$("#webs-destacadas ul").addClass("js");
	$("#webs-destacadas").append('<img id="esq" src="../imatges_accessible/img09/navegacio-esq.jpg" alt=""  /><img id="dret" src="../imatges_accessible/img09/navegacio-dret.jpg" alt=""  /> ');
	
	$("img#dret, img#esq").animate({opacity:.5});
	
	$("img#esq").css("display","none");
	
	 var cont = 0;
	 var total = $("#webs-destacadas ul li").length / 7;
	 
	 if( (Math.round(total) - total) >= 0) {total=Math.round(total)}
	 else{total=Math.round(total)+1};
	 	
		 
	$("img#dret, img#esq").mouseover(function() {
		$(this).css("cursor","pointer");								  
		$(this).animate({opacity:1});
	}).mouseout(function() {
		$(this).animate({opacity:.5});
	});
	
	
	$("img#dret").click(function() {
		
		if(cont	== 0){$("img#esq:hidden").fadeIn('slow');}				 
		if(cont < total-1){						 
		   
		   $("#webs-destacadas ul").animate({"left": "-=924px"}, 'normal');
		   
		   cont++;
		 
		   
		   if(cont == total-1){$("img#dret").fadeOut('slow');}
		}
	});
	
	$("img#esq").click(function() {
		if(cont	< total){$("img#dret").fadeIn('slow');}
	
		if(cont <= total && cont != 0){	
		   $("#webs-destacadas ul").animate({"left": "+=924px "}, 'normal');
		  cont--;
		}
		if(cont == 0){$("img#esq").fadeOut('slow');}
	});

// script de formulari cercador
	// ---------------------------------------------------------------------------------------------------------------------	
	
	$("#cercador ul").hide();
	
		
	$(document.body).click(function(event){
		var target = $(event.target);
		if (target.is("#cercador")){
			$("#cercador ul").toggle(); 
		}
	});
	
	$(document.body).click(function(event){
		var target = $(event.target);
		if (!target.is("#cercador")){
				$("#cercador ul:visible").hide();  
		}
	});
	
	$("input#cerca, #utilitats ul li.ultim a").focus(function(){
			$("#cercador ul:visible").hide(); 							
	});
	
	
	
	$("#cercador span.select").keypress ( function(event) {
			
				if (keyNum(event)==13)
					$("#cercador ul").toggle(); 
			
				function keyNum(e) {
					var keynum;
					if (window.event) keynum = e.keyCode; // IE
					else if (e.which) keynum = e.which; // Estandars
					return(keynum);
				}
		});
    

	$("a#plenari").click ( function() {

		window.open(this.href, '', '0, 0, 0, 0, 0, 0, 0');
		
		return(false);

	});


	
	
});
/*-----------------------------------------------------------------------------------------*/
