function SlbnLightBox(idImg,ancho,alto,backColor){
	//si no existe la base la creamos
	if(!document.getElementById("base")){
		back = document.createElement('div');
		back.id = 'base';
		back.zIndex = 10;
		back.style.display = "none";
		back.style.opacity = " .7";
		back.style.filter = "alpha(opacity=70)";
		back.style.position = "absolute";
		back.style.top = "0px";
		back.style.left = "0px";
		document.body.appendChild(back);
	}	
	
	back = document.getElementById("base");
	
	//Bloqueamos Scroll
	/*
	Modificamos la propiedad OVERFLOW con los siguientes valores:
	scroll: muestra scroll
	hidden: el contenido que sobra queda oculto
	visible: redimensiona el objeto para que "entre" el contenido completo
	auto: si el contenido cabe en el objeto, no ocurre nada, pero si no entra se mostrara scroll
	*/
	SlbnStateScroll("hidden","miBody");
	
	//establecemos tamaño de la base
	back.style.width = document.body.scrollWidth+"px";
	
	//Si el tamaño de la ventana mide mas que el body asignamos el tamaño correspondiente
	if(window.clientY > document.body.scrollHeight)
		back.style.height = document.body.scrollHeight+"px";
	else
		back.style.height = document.body.clientHeight+"px";
	

	//Posicion de la base
	back.style.top = document.body.scrollTop;

	//Asignamos color a la base
	SlbnBackColor(back,backColor);
	
	//Mostramos la base
	back.style.display = 'block';
	
	//Montamos la ventana (nombre del flash, Cargamos enlace )
	SlbnLightBoxMountWindow(SlbnLightBoxImg(idImg,ancho,alto),SlbnLightBoxAHref(),ancho,alto);

	
}


//FUNCION QUE CREA UN OBJETO  IMG Y LO DEVUELVE A QUIEN LLAMA LA FUNCION
function SlbnLightBoxImg(imagen,ancho,alto){
	var imgUrl=imagen;
	var width=ancho;
	var height=alto;
	
	var contenedorFlash = document.createElement('div');
	contenedorFlash.id = 'contenedorFlash';
	
	var obj = document.createElement('object');
	obj.setAttribute('type','application/x-shockwave-flash');
	
	 
	var p_m = document.createElement('param');
	p_m.setAttribute('name','movie');
	p_m.setAttribute('value',imgUrl);
	obj.appendChild(p_m);
	 
	var embed = document.createElement('embed');
	embed.setAttribute('width',width);
	embed.setAttribute('height',height);
	embed.setAttribute('type','application/x-shockwave-flash');
	embed.setAttribute('src',imgUrl);
	
	
	//contenedorFlash.appendChild(obj)
	contenedorFlash.appendChild(embed)
	
	
	return contenedorFlash;
}

//FUNCION QUE CREA UN OBJETO  A href Y LO DEVUELVE A QUIEN LLAMA LA FUNCION
function SlbnLightBoxAHref(){
	
	var link="";
	//Creamos el enlace Si Existe lo reutilizamos
	if(!document.getElementById("linkClose")){
		link = document.createElement('a'); 
		link.id = 'linkClose';
		link.setAttribute('href', 'javascript:void(null)');
		link.onclick = function(){SlbnLightBoxClose(link.id);}
	}else{
		link = document.getElementById('linkClose'); 
		link.url = "javascript: SlbnLightBoxClose();";
	}
	
	return link;
}


//FUNCION QUE MONTA UN MARCO CON LA IMAGEN SELECCIONADA
function SlbnLightBoxMountWindow(imagen, enlace,ancho,alto){
	var width=ancho;
	var height=alto;
	
	//Creamos el contenedor. Si Existe la reutilizamos
	if(!document.getElementById("contenedor")){
		contenedor = document.createElement('div');
		contenedor.id = 'contenedor';
		contenedor.style.zIndex = 110;
		contenedor.style.display = "none";
		contenedor.style.position = "absolute";
		contenedor.style.backgroundColor = "#ffffff";
		contenedor.style.padding = "10px 0 0 0";
		contenedor.style.margin = "10px 0 0 0";
		contenedor.align="center";
		
		contenedor.style.top = ((document.body.clientHeight - height) /2) +"px";
		contenedor.style.left = ((document.body.scrollWidth - width) /2) +"px";
		
	}else{
		contenedor = document.getElementById('contenedor');
	}
	
	contenedor.style.width = width+25+"px";
	contenedor.style.height = height+25+"px";
	
	contenedor.style.display = 'block';
	
	document.body.appendChild(contenedor);
	
	contenedor.appendChild(enlace);
	enlace.appendChild(imagen);
	
	var objBottomNav=document.createElement("div");
	objBottomNav.setAttribute('id','bottomNav');
	objBottomNav.setAttribute('width','100%');
	objBottomNav.setAttribute('align','right');
	
	var objBottomNavCloseLink=document.createElement("a");
	objBottomNavCloseLink.setAttribute('id','bottomNavClose');
	objBottomNavCloseLink.setAttribute('href','javascript:SlbnLightBoxClose()');
	objBottomNav.appendChild(objBottomNavCloseLink);

	var objBottomNavCloseImage=document.createElement("img");
	objBottomNavCloseImage.setAttribute('src',"/contenidos/img/closelabel.gif");
	objBottomNavCloseImage.setAttribute('border','0');
	objBottomNavCloseLink.appendChild(objBottomNavCloseImage);
	contenedor.appendChild(objBottomNav);
	document.getElementById("bottomNav").height="15px";
	document.getElementById("bottomNav").style.padding="10px 12px 5px 0";
	document.getElementById("bottomNav").style.margin="0";
	document.getElementById("bottomNav").style.backgroundColor ="#ffffff";
	
	
}


//FUNCION QUE CIERRA EL VISULIZADOR DE IMÁGENES	
function SlbnLightBoxClose(obj){
	
	document.getElementById("base").style.display="none";
	document.getElementById("contenedor").style.display="none";
	//alert(document.getElementById("contenedor").parentNode.id)
	
	
	var rootContenedor = document.getElementById("contenedor");
	var root = rootContenedor.parentNode;
	root.removeChild(rootContenedor);
	//Leberamos Scroll
	SlbnStateScroll("visible","miBody");
}

//FUNCION QUE CAMBIA EL ESTADO DEL OVERFLOW DEL OBJETO QUE INQUEMOS AL ESTADO QUE SE LE INDIQUE
//Si el parametro OBJ esta vacio se aplicará el cambio al BODY
function SlbnStateScroll(estado,obj){
	var tag=true;
	if(document.getElementById(obj)){
		obj = document.getElementById(obj);
		
	}else{
		obj = document.getElementsByTagName("BODY");
		tag = false;
	}

	
	if(obj && tag)
		obj.style.overflow = estado;
	else
		obj[0].style.overflow = estado;
	
	return true;
}


//FUNCION QUE ASIGNA UN COLOR DE FONDO A UN OBJETO
function SlbnBackColor(obj,color){
	if(color != undefined )
		obj.style.backgroundColor = color;
	else
		obj.style.backgroundColor = "#000000";	
}
