// Ajuntament de Barcelona 
// www.bcn.cat | www.bcn.es


// Definició de variables globals
// ---------------------------------------------------------------------------------------------------------------------
var idioma = $("html").attr("lang");
var pathSite = $("meta[name=base]").attr("content");


$(document).ready ( function() {
	// Substituïm els títols per imatges
	// ---------------------------------------------------------------------------------------------------------------------
	$("h2").each ( function() {
		var st = '';
		var lText = $(this).text();
		var lHref = $(this).find("a").attr("href");
		var lFile = this.className.split('-');
		var lFileType = 'jpg';
		var lFileTypeLocated = false;
		var lPath = pathSite+'/img/'+idioma+'/';
		var lExtension = new Array('jpg', 'gif', 'png');
		
		for (var i=0; i<lExtension.length && !lFileTypeLocated; i++) {		
			if (lExtension[i]==lFile[lFile.length-1]) {
				lFileType = lFile.pop();
				lFileTypeLocated = true;
			}
		}
		lPath += lFile.join('-')+'.'+lFileType;
		if (lFileTypeLocated){
			var sFinal = '<img src="'+lPath+'" alt="'+lText+'" />';
			if (lHref != null) sFinal = '<a href="'+lHref+'" title="'+lText+'">' + sFinal + '</a>';
			$(this).html(sFinal);
		}
	});
	// Marquem els enllaços que s'obren en un popup
	// ---------------------------------------------------------------------------------------------------------------------
	$("a.obrirPopup").click ( function() {
		window.open(this.href, '', '0, 0, 0, 0, 0, 0, 0');
		return(false);
	});
});

