$(window).load(function() {
	// $.gaTracker('UA-12002717-1');
	//external links
	$("a[rel=external]").attr("target", "_blank");
	$("a[rel=external]").attr("class", "external");
	$("a[href$=.pdf]").attr("target", "_blank");
	$("a[href$=.pdf]").attr("class", "pdf");

	// evitem spam als correus
	$("a[href*='(ELIMINAR)']").each(function(i){
		omg = $(this).attr('href');
		omg2 = $(this).text();
		$(this).attr('href', omg.split('(ELIMINAR)').join(''));
		$(this).text(omg2.split('(ELIMINAR)').join(''));
	});
	
	$("#interior #content_main ul.llista_caixa li:last").addClass("last");
	$("#interior #content_main ul.llista_fons.llista_separadors li:last").addClass("last");
	
	$("#site_info #logos img:last").addClass("last");
	
	
	// afegir /web per posar carpeta web TEMPORAL CAL Borrar-ho
	/*$("#serveis a[href^='/']").each(function(i){
		omg = $(this).attr('href');
		
		$(this).attr('href', ('/web')+ omg);
		
	});
	
	$("#content_main a[href^='/']").each(function(i){
		omg = $(this).attr('href');
		
		$(this).attr('href', ('/web')+ omg);
		
	});
	$("img[src^='/media']").each(function(i){
		omg = $(this).attr('src');
		
		$(this).attr('src', ('/web')+ omg);
		
	});*/
	
	// final borrar borrar
	
	
	//molla de pa
	if($('ul#mollapa').length){
		$('ul#mollapa li:first').addClass('first');
		$('ul#mollapa li:last').addClass('last');
		$('ul#mollapa li:not(:first) a').append('<span></span>');
		$('ul#mollapa li:not(:first) a').addClass('cami');
	}
	if($('#situacio ul').length){
		$('#situacio ul li:last').addClass('last');
		$('#situacio ul li:not(:first) a').append('<span></span>');
		$('#situacio ul li:not(:first) a').addClass('cami');
	}
	
	//desplegable centres
	if($('#desplegable_centres')){
		$('#desplegable_centres #desplegat').hide();
		/*
		$('#desplegable_centres h2').toggle(
			function(){
				$('#desplegable_centres #desplegat').show();
			},function(){
				$('#desplegable_centres #desplegat').hide();
			}
		);*/
		$('#desplegable_centres h2').toggle(
				function(){
					$('#desplegable_centres #desplegat').css({height: '1px'}).show().animate({ height: '160px' }, 'slow');
				},function(){
					$('#desplegable_centres #desplegat').css({height: '160px'}).animate({ height: '1px' }, 'slow',function(){$('#desplegable_centres #desplegat').hide()});
				}
			);

	}
	
	//presentació centres - tota la capa enllaça
	if($('div.presentacio_centres').length){
		$('div.presentacio_centres').click(function(){
			if($(this).find("a").attr("rel")=="external"){
				window.open($(this).find("a").attr("href"));
			}else{
				window.location=$(this).find("a").attr("href");
			}			
			return false;
		});
		$('div.presentacio_centres').css('cursor','pointer');
	}
	
	//reemplaça l'span destacat per un paràgraf destacat
	$('span.destacat').each(function(){
		$(this).wrap('<p class="destacat"></p>');
	});
	
	//esborrar input del cercador
	if($('#cercador_unitat').length){
		$('#cercador_unitat input').click(function(){
			$('#cercador_unitat input').val('');
		});
	}
	
	//colorbox
	if($('p.ampliar a').length){
		$('p.ampliar a').colorbox({ width:"620", height:"750", iframe:true }); //620*420
	}
	if($('a[rel="ampliar"]').length){
		$('a[rel="ampliar"]').colorbox({ rel:'nofollow' });
	}
	
	//igualar altures
	if($('ul#llistat_galeria li').length){
		$('ul#llistat_galeria li').equalHeights();
		$("ul#llistat_galeria li").resize(function(){
			$('ul#llistat_galeria li').equalHeights();
		});
	}
	
	//posar span al llistat subportada
	$("#interior.sub #content_main ul li").append("<span></span>");
	
	//posar span al llistat de la subportada coneix-nos
	$("#colConeixB ul li.video").append("<span></span>");

	
	//subportada homologació botons
	$("#interior.sub #content_main.homologacio .colB ul li:first").addClass("qualificat");
	$("#interior.sub #content_main.homologacio .colB ul li:last").addClass("acreditat");

	// initialize scrollable
	//$(".scrollable").scrollable();
	$(".scrollable").scrollable({circular: true}).autoscroll(5000);
	
	/*Llistes caixa dreta: afegim la classe 'ultim' a ultim li dins de #opcionsdreta */
	function ultimFill() {
		
		$('#nav_sub ul li:last-child').addClass('ultim');/* tb al menú*/
		$('#nav_sub ul li:first-child').addClass('primer');/* tb al menú*/
	}
	$(document).ready(ultimFill);
});
