var dom = document.getElementById ? true:false;
var ns = navigator.appName.indexOf("Netscape")!=-1 ? true:false;
var ns4 = document.layers ? true:false;
var ie4 = document.all ? true:false;
var mac = navigator.appVersion.indexOf('Mac')!=-1 ? true:false;

function init() {
	blurLinks();
	if (op_activa==2) {
		document.onmousemove = mouseMove;
	}
}

function init_x() {
	blurLinks();
}

function preload(imgObj,imgSrc) {
	eval(imgObj+" = new Image()");
	eval(imgObj+".src = '"+imgSrc+"'");
}

function changeImg(imgObj,imgSrc) {
	if (navigator.appVersion >= "3") {
		var imatge = eval(imgSrc+".src");
		document.images[imgObj].src = imatge;
	}
}

function blurLinks() {
	if (dom) {
		lnks = document.getElementsByTagName('a');
		for (i=0;i<lnks.length;i++) {
			lnks[i].onfocus = new Function("if(this.blur) this.blur()");
		}
	} else if (ie4) {
		for (var i in document.links) {
			document.links[i].onfocus = document.links[i].blur;
		}
	}
}

var y, x, showing_tooltip = false;
function mouseMove(e) {
	y = (ns)? e.pageY : event.y+document.body.scrollTop;
	x = (ns)? e.pageX : event.x+document.body.scrollLeft;
	if (showing_tooltip) {
		document.getElementById('tooltipDiv').style.left = (x+20)+"px";
		document.getElementById('tooltipDiv').style.top = y+"px";
	}
	return true;
}

function showTooltip(id) {
	document.getElementById('tooltipDiv').innerHTML = "<img src=\"videos/"+id+".jpg\" width=\"80\" height=\"60\" alt=\"\" />";
	showing_tooltip = true;
}

function hideTooltip() {
	showing_tooltip = false;
	document.getElementById('tooltipDiv').style.top = "-500px";
	document.getElementById('tooltipDiv').innerHTML = "";
}

function openWindow(url,nom,ww,hh,xx,yy,toolbarx,directoriesx,statusbarx,scrollbarsx,menubarx) {
	eval(nom+"=window.open('"+url+"','"+nom+"','toolbar="+toolbarx+",directories="+directoriesx+",status="+statusbarx+",scrollbars="+scrollbarsx+",menubar="+menubarx+",width="+ww+",height="+hh+",left="+xx+",top="+yy+",x="+xx+",posy="+yy+"')");
}

function displayAccions() {
	if (document.getElementById("accionsDiv").style.display=="none") {
		document.getElementById("accionsDiv").style.display = "";
	} else {
		document.getElementById("accionsDiv").style.display = "none";
	}
}

function displayRetractos() {
	for (i=1;i<ids_retractos.length;i++) {
		var so = new SWFObject("swf/retractos.swf", "flash", "50", "50", "6", "#000000");
		so.addVariable("id", i);
		so.addParam("scale", "noscale");
		so.addParam("menu", "false");
		so.addParam("quality", "high");
		so.write("flashcontentretracto"+i);
	}
}

var ids_retractos = new Array(), noms_retractos = new Array();

function showRetracto(id) {
	document.getElementById("visor").innerHTML = "<img src=\"retractos/large/"+id+".jpg\" id=\"imatgeretracto\" alt=\"\" onload=\"centrarRetracto()\" style=\"display: none; float: right;\" /><br /><div style=\"float: right; width: 300px; text-align: right; font-size: 10px;\"><p style=\"width: 300px; line-height: 15px;\">"+noms_retractos[id]+"</p></div>";
}

function centrarRetracto(id) {
	var hh = document.getElementById("imatgeretracto").height;
	var marge = 105;
	if (hh>300) {
		marge = 380-hh;
	}
	if (marge<0) {
		marge = 0;
	}
	document.getElementById("imatgeretracto").style.marginTop = marge+"px";
	document.getElementById("imatgeretracto").style.display = "";
}

preload("fletxa_blanca","images/fletxa_blanca.gif");
preload("fletxa_vermella","images/fletxa_vermella.gif");

var ids_trayectos = new Array(), noms_trayectos = new Array(), h_trayectos = new Array();

function displayTrayectos() {
	for (i=0;i<ids_trayectos.length;i++) {
		var so = new SWFObject("swf/trayectos.swf", "flash", "50", "50", "6", "#000000");
		so.addVariable("id", i);
		so.addVariable("imatge", ids_trayectos[i]);
		so.addParam("scale", "noscale");
		so.addParam("menu", "false");
		so.addParam("quality", "high");
		so.write("flashcontenttrayecto"+i);
	}
}

function showTrayecto(id) {
	document.getElementById("visor").innerHTML = "<img src=\"trayectos/large/"+ids_trayectos[id]+".jpg\" id=\"imatgetrayecto\" height=\""+h_trayectos[id]+"\" alt=\"\" onload=\"centrarTrayecto()\" style=\"display: none; float: right;\" /><br /><div style=\"float: right; width: 300px; padding-bottom: 25px; text-align: right; font-size: 10px;\"><p style=\"width: 300px; line-height: 15px;\">"+noms_trayectos[id]+"</p></div>";
}

function centrarTrayecto(id) {
	var hh = document.getElementById("imatgetrayecto").height;
	var marge = 105;
	if (hh>300) {
		marge = 380-hh;
	}
	if (marge<0) {
		marge = 0;
	}
	document.getElementById("imatgetrayecto").style.marginTop = marge+"px";
	document.getElementById("imatgetrayecto").style.display = "";
}

var noms_imatges_accions = new Array();

function showImatgeAccio(id) {
	document.getElementById("visor_imatge").innerHTML = "&nbsp;";
	document.getElementById("visor_imatge").innerHTML = "<img src=\"accions/large/"+id+".jpg\" alt=\"\" style=\"border-top: 1px solid #000000;\" /><br /><div style=\"width: 300px; margin-top: 8px;\"><p style=\"width: 300px; line-height: 15px;\">"+noms_imatges_accions[id]+"</p></div>"
}

var noms_imatges_silencis = new Array();

function showImatgeSilencio(id) {
	document.getElementById("visor_imatge").innerHTML = "&nbsp;";
	document.getElementById("visor_imatge").innerHTML = "<img src=\"elsilencio/large/"+id+".jpg\" alt=\"\" style=\"border-top: 1px solid #000000;\" /><br /><div style=\"width: 345px; margin-top: 8px;\"><p style=\"line-height: 15px;\">"+noms_imatges_silencis[id]+"</p></div>";
}

var mp3_discografia =  new Array();

function displayDisc(id) {
	var eps = "<img src=\"discografia/large/"+id+".jpg\" width=\"280\" height=\"280\" alt=\"\" />";
	if(mp3_discografia[id]==1) {
		eps += "<div id=\"flashcontentplayer\" style=\"width: 32px; height: 12px;\"></div>";
	} else {
		eps += "<div style=\"width: 32px; height: 12px;\">&nbsp;</div>";
	}
	document.getElementById("visor_e").innerHTML = eps;
	if(mp3_discografia[id]==1) {
		var so = new SWFObject("swf/player.swf", "flash", "32", "12", "6", "#000000");
		so.addVariable("id", "discografia/mp3/"+id+".mp3");
		so.addParam("scale", "noscale");
		so.addParam("menu", "false");
		so.addParam("quality", "high");
		so.write("flashcontentplayer");
	}
}

function toogleTreball(id) {
	if (document.getElementById("thumb_treball_"+id).style.display=="none") {
		document.getElementById("treball_"+id).style.display = "none";
		document.getElementById("thumb_treball_"+id).style.display = "";
	} else {
		document.getElementById("thumb_treball_"+id).style.display = "none";
		document.getElementById("treball_"+id).style.display = "";
	}
}