// Este es el archivo mas importante
// esta parcialmente copiado de uno de por ahí
// si lo quieres copiar adelante, ya se sabe
// quien roba a un ladrón...

var SelectedLayer = null;

//
// Funciones de referencia de los layers
//

// Atributos de estilo

function setLayer(layerName){
	if(NS){
		var layerRef = eval("document." + layerName);
	} else {
		var layerRef = eval("document.all." + layerName + ".style");
	}
	return layerRef;
}

// Propiedades del documento
function setLayerDocRef(layerName) {
	if(NS) {
		var LayerObj = eval("document." + layerName + ".document");
	} else {
		var LayerObj = eval("document.all." + layerName + ".document");
	}
	return LayerObj;
}

//
// Final de las funciones de referencia de los layers
//

//
// Funciones de visibilidad de los layers
//

function toggleLayerVis(layerName){
	layerName = setLayer(layerName);
	if(layerName.visibility.charAt(0) == "h"){
		layerName.visibility = "visible";
	} else {
		layerName.visibility = "hidden";
	}
}

function showLayer(layerName){
	layerName = setLayer(layerName);
	layerName.visibility = "visible";
}

function hideLayer(layerName){
	layerName = setLayer(layerName);
	layerName.visibility = "hidden";
}

function hideAllLayers(){
	if(NS){
		for(i = 0; i < document.layers.length; i ++){
			document.layers[i].visibility = "hidden";
		}
	} else {
		for(i = 0; i < document.all.tags('DIV').length; i ++){
			document.all.tags('DIV')[i].style.visibility = "hidden";
		}
	}		
}

function showAllLayers(){
	if(NS){
		for(i = 0; i < document.layers.length; i ++){
			document.layers[i].visibility = "visible";
		}
	} else {
		for(i = 0; i < document.all.tags('DIV').length; i ++){
			document.all.tags('DIV')[i].style.visibility = "visible";
		}
	}
}

//
// Final de las funciones de visibilidad de los layers
//

//
// Funciones para el posicionamiento horizontal de layers
//

// Obtener la esquina izquierda del layer

function getLayerX(layerName){
	layerName = setLayer(layerName);
	if(NS){
		return layerName.left;
	} else {
		return layerName.pixelLeft;
	}
}

// Obtener ancho del layer

function getLayerWidth(layerName){
	layerName = setLayer(layerName);
	if(NS){
		var layerWidth = layerName.clip.width;
	} else {
		var widthVar = layerName.width;
		widthVar = Number(widthVar.slice(0,-2));
		var layerWidth = widthVar;
	}
	return layerWidth;
}

// Poner ancho del layer

function setLayerClipWidth(layerName, w){
	layerName = setLayer(layerName);
	if(NS){
		layerName.clip.width = w;
	} else {
		layerName.width = w;
	}
}

//
// Final de las funciones para el posicionamiento horizontal de las layers
//

//
// Funciones para el posicionamiento vertical de las layers
//

// Obtener la esquina izquierda

function getLayerY(layerName){
	layerName = setLayer(layerName);
	if(NS){
		return layerName.top;
	} else {
		return layerName.pixelTop;
	}
}


// Obtener la altura del layer

function getLayerHeight(layerName){
	layerName = setLayer(layerName);
	if(NS){
		var layerHeight = layerName.clip.height;
	} else {
		var heightVar = layerName.height;
		heightVar = Number(heightVar.slice(0,-2));
		var layerHeight = heightVar;
	}
	return layerHeight;
}

// Establecer la altura del layer

function setLayerClipHeight(layerName, h){
	layerName = setLayer(layerName);
	if(NS){
		layerName.clip.height = h;
	} else {
		layerName.clipHeight = h;
	}
}


//
// Final de las funciones para el posicionamiento vertical de las layers
//


//
// Funciones para el posicionamiento general de layers
//

// Mover las layers a una posicion en particular

function moveLayer(layerName, x, y){
	layerName = setLayer(layerName);
	if(NS){
		layerName.moveTo(x,y);
	} else {
		layerName.pixelLeft = x;
		layerName.pixelTop = y;		
	}	
}

// Mover las layers usando incrementos

function moveLayerBy(layerName, deltaX, deltaY){
	layerName = setLayer(layerName);
	if(NS){
		layerName.moveBy(deltaX,deltaY);
	} else {
		layerName.pixelLeft += deltaX;
		layerName.pixelTop += deltaY;
	}	
}

//
// Final de las funciones para el posicionamiento en general de las layers
//

//
// FUNCTION FOR Z INDEX OF LAYERS
//

function setZ(layerName, zOrder){
	layerName = setLayer(layerName);
	layerName.zIndex = zOrder;
}

//
// END FUNCTION FOR Z INDEX OF LAYERS
//

//
// Función para poner el fondo del layer
//

function setLayerBG(layerName, color){
	layerName = setLayer(layerName);
	if(NS){
		layerName.bgcolor = color;
	} else {
		layerName.backgroundColor = color;
	}
}

//
// Final de la función para poner el fondo del layer
//

//
// Función para gestionar los clicks en el layer
//

function checkLayerHit(){
	if(NS){
		for(i = 0; i < document.layers.length; i ++){
			
			currentLayer = document.layers[i];
			if(clickX > currentLayer.left && clickX < currentLayer.clip.width){
				if(clickY > currentLayer.top && clickY < currentLayer.clip.height){
					// set SelectedLayer to name of layer
				}
			}
			
		}
	} else {
		for(i = 0; i < document.all.tags('DIV').length; i ++){
			
			currentLayer = document.all.tags('DIV')[i];
			
			var layerWidth = currentLayer.style.width;
			layerWidth = Number(layerWidth.slice(0,-2));
			
			var layerHeight = currentLayer.style.height;
			layerHeight = Number(layerHeight.slice(0,-2));
			
			if(clickX > currentLayer.style.pixelLeft && clickX < layerWidth){
				if(clickY > currentLayer.style.pixelTop && clickY < layerHeight){
					// set SelectedLayer to name of layer
				}
			}
			
		}
	}
		
}

//
// Final de la función para gestionar los clicks en el layer
//