$(document).ready(function() {

	// obrim els enllaços indicats en una finestra nova
	$("a[rel=external]").click(function() {

		window.open($(this).attr("href")).focus();
		return false;

	});

	// amaguem i apliquem estils corresponents
	$("div.hidden > p").hide();
	$("div.hidden > h3").css({ background:"url('media/comu/desplega_mes.jpg') no-repeat left center", paddingLeft:"20px", cursor:"pointer" });

	// activem mostrar/amagar
	$("div.hidden > h3").click(function() {

		$(this).parent().children("p").slideToggle("normal");

		if($(this).css("background").search("desplega_mes") != -1) $(this).css("background", "url('media/comu/desplega_menys.jpg') no-repeat left center");
		else $(this).css("background", "url('media/comu/desplega_mes.jpg') no-repeat left center");

	});

	$('div.images').not('div.image1').hide();

	// intercanvi d'imatges
	$("ul.switcher > li > a").click(function() {

		// si es fa click a la imatge actual, no fem res
		if($(this).attr("class") == "showing") return false;
		// sino, intercanviem les imatges
		else {

			$("a.showing").removeClass("showing");
			$(this).addClass("showing");

			id = $(this).attr('id');
			$('div.images').hide();
			$("div."+id).slideDown("slow");

			var addr = $(this).attr("href"); // adreça de l'enllaç

			// POSAR RUTA A LA FOTOGRAFIA ORIGINAL (hauria de ser l'href de l'enllaç, tal com està)
			$("span.expand > a").attr("href", addr);


			return false;

		}

	});

	//seleccionable de col·lecció
	$('select#coleccio').change(function(){$('form#col_select')[0].submit()});
	$('input#submit_coleccio').hide();

	$("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(''));
	});

});
