var Site = {

	beforeStart : function () {
		// Amaga el codi o que s'ha de visualitzar sense javascript
		var noscript = $$(".noscript");
		noscript.each(function(element) {
			element.addClass("help");
		});
		
	},
	
	start : function() {
		if ($("menu")) {
		    var pageIdentifier = $("menu").className;
			var menu = $$("#menu ul li");
			menu.each(function(element) {
					var aHref = element.getChildren()[0];
					aHref.href = "javascript:" + pageIdentifier + ".menuGoTo('" + aHref.href + "');";
			});
			
			$("inicio").href = "javascript:" + pageIdentifier +".menuGoTo('" + $("inicio").href + "');";
			
		}
		
		
		
		
		
		Site.prepareExternalLinks();
		
		if (window.ie6) {
			fix_inline_PNGs();
			if ($("menu")) {
				($("mnu_nosotros").getChildren()[0]).setStyle("backgroundPosition", "100% 2px");
				($("mnu_audio_video").getChildren()[0]).setStyle("backgroundPosition", "100% 2px");
				($("mnu_presupuestos").getChildren()[0]).setStyle("backgroundPosition", "100% 2px");
			}
			
		}
	},		
	
	prepareExternalLinks : function() {
		var linkList = $$("a");
		linkList.each(function(el) {
			if (el.getProperty('rel')=="external") el.target = "_blank";
		}, this);
	},
	
	getBaseUrl : function() {
		return (document.location.href).substring(0, (document.location.href).lastIndexOf("/") +1);
	}
	
	
};


 function fix_inline_PNGs(){
	var images = $$('img'); // liste de tous les élément <img /> du document
	images.each(function(e){
		var this_src = e.getProperty('src');
		var this_height = e.height;
		var this_width = e.width;
		if (this_src.toUpperCase().contains('.PNG')){
		var this_new = new Element('span', {
			'styles': {
				'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+this_src+'\', sizingMethod=\'scale\')',
				'display': 'inline-block',
				'height': this_height,
				'width': this_width
			}});
			e.replaceWith(this_new);
		}
	});
 } 

Window.addEvent('domready', function() { Site.beforeStart(); });
Window.addEvent('load', function() { Site.start(); });