// basado en Static Slide Menu 6.5.
// Site: http://www.absolutegb.com/maximus

// inline branching
var NS6 = (document.getElementById && !document.all) ? true : false;
var IE = (document.all) ? true : false;
var NS = (navigator.appName=="Netscape" && navigator.appVersion.charAt(0)=="4") ? true : false;

////////////////////////////////////////////////////////////////////////////////////////////////////////
// configure photo-layer:

// no quotes on numbers settings!!
var YOffset = 250; // Numero de pixels desde el top del documento
var XOffset = 0; // Numero de pixels desde la foto
var staticYOffset = 30; // Minimo numero de pixels desde el top del documento. Tienes que ser <= YOffset
var slideSpeed = 20; // milisegundos de cada movimiento del menu
var waitTime = 100; // milisegundos que el menu estara abierto hasta que se cierre de nuevo

var capaBGColor = "#FF6600"; // color de fondo de la capa
var capaIsStatic = "yes"; // this sets whether the layer should stay static on the vertical screen
var capaWidth = 160; // ancho de los elementos de la capa. Must be a multiple of 10!

////////////////////  END OF CUSTOMIZATION AREA  ///////////////////

// preload image that is to appear in photo-layer
function preloadImg(name) {
	if (document.images) {
		var theImg = new Image(160, 160);
		theImg.src = name;
	}
	
	moveBack();
}

// Intercambia la imagen de la capa
function swapImg(source, name) {
	document.fotoArtista.src = source;
	document.fotoArtista.alt = name;

	moveOut();
}

//////////////////////////////////////////////////////////////////////////
// Move out and show or move back and hide the photo-layer
var moving = setTimeout('null',1); 

function moveOut() {
	if ((NS6||NS) && parseInt(ssm.left)<0 || IE && ssm.pixelLeft<0) {
		clearTimeout(moving);
		moving = setTimeout('moveOut()', slideSpeed);
		slideMenu(10);
	}
	else {
		clearTimeout(moving);
		moving = setTimeout('null',1);
	}
}

function moveBack() {
	clearTimeout(moving);
	moving = setTimeout('moveBack1()', waitTime);
}

function moveBack1() {
	if ((NS6||NS) && parseInt(ssm.left)>(-capaWidth) || IE && ssm.pixelLeft>(-capaWidth)) {
		clearTimeout(moving);
		moving = setTimeout('moveBack1()', slideSpeed);
		slideMenu(-10);
	}
	else {
		clearTimeout(moving);
		moving=setTimeout('null',1);
	}
}

function slideMenu(num) {
	if (IE) {ssm.pixelLeft += num;}
	if (NS||NS6) {ssm.left = parseInt(ssm.left)+num;}
	if (NS) {
		bssm.clip.right+=num;
		bssm2.clip.right+=num;
	}
}

// Controla el desplazamiento vertical
function makeStatic() {
	if (NS||NS6) {winY = window.pageYOffset;}
	if (IE) {winY = document.body.scrollTop;}
	if (NS6||IE||NS) {
		if (winY!=lastY&&winY>YOffset-staticYOffset) {
			smooth = .2 * (winY - lastY - YOffset + staticYOffset);
		}
		else if (YOffset-staticYOffset+lastY>YOffset-staticYOffset) {
			smooth = .2 * (winY - lastY - (YOffset-(YOffset-winY)));
		}
		else {smooth=0}
		if (smooth > 0) smooth = Math.ceil(smooth);
		else smooth = Math.floor(smooth);
		if (IE) bssm.pixelTop+=smooth;
		if (NS6||NS) bssm.top=parseInt(bssm.top)+smooth

		lastY = lastY+smooth;
		setTimeout('makeStatic()', 1)
	}
}

function initSlide() {
	if (NS6) {
		ssm = document.getElementById("thessm").style;
		bssm = document.getElementById("capaBase").style;
		bssm.clip="rect(0 " + document.getElementById("thessm").offsetWidth +" " + document.getElementById("thessm").offsetHeight + " 0)";
		ssm.visibility = "visible";
	}
	else if (IE) {
		ssm = document.all("thessm").style;
		bssm = document.all("capaBase").style;
		bssm.clip = "rect(0 " + thessm.offsetWidth + " " + thessm.offsetHeight + " 0)";
		bssm.visibility = "visible";
	}
	else if (NS) {
		bssm = document.layers["basessm1"];
		bssm2 = bssm.document.layers["basessm2"];
		ssm = bssm2.document.layers["thessm"];
		bssm2.clip.left = 0;
		ssm.visibility = "show";
	}

	if (capaIsStatic == "yes") makeStatic();	// Mueve la capa al desplazar verticalmente el documento
}

// buildLayer
// assembles content
function buildLayer() {
	if (IE||NS6)
		document.write('<div id="capaBase" style="visibility:hidden; position:absolute; left:' + XOffset + '; top:' + YOffset + '; z-index:20; width:' + (capaWidth+10) +'"><div id="thessm" style="position:absolute; left:' + (-capaWidth) +'; top:0; z-index:20;">');
	if (NS)
		document.write('<layer name="basessm1" top="' + YOffset + '" left=' + XOffset + ' visibility="show"><ilayer name="basessm2"><layer visibility="hide" name="thessm" bgcolor="' + capaBGColor +'" left="' + (-capaWidth) + '">');
	if (NS6)
		document.write('<table border="0" cellpadding="0" cellspacing="0" width="' + (capaWidth+2) +'" bgcolor="' + capaBGColor +'"><tr><td>');

	document.write('<table border="0" cellpadding="0" cellspacing="1" width="' + (capaWidth+2) +'" bgcolor="' + capaBGColor + '">');
	document.write('<tr><td bgcolor="#EAEAEA" width="' + (capaWidth-1) + '"><ilayer><layer width="100%" align="center"><div align="center"><img src="#" name="fotoArtista" height="160" width="160" border="0"><br></div></layer></ilayer></td></tr>');
	document.write('</table>')

	if (NS6)		document.write('</td></tr></table>');
	if (IE||NS6)	document.write('</div></div>');
	if (NS)			document.write('</layer></ilayer></layer>');

	theleft = -capaWidth;
	lastY = 0;
	setTimeout('initSlide();', 1);
}

buildLayer();

