$(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(''));
	});
	
	//molla de pa
	if($('ul#mollapa').length){
		$('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();
		});
	}


});
