/**
 * GoldenLightBox
 * @author: Edmilson Silva
 * @copyright GoldenLight [ edmilson.silva@goldenlight.biz ]
 * 24.03.2010
 * Requerido jQuery 1.2.x (+)
 * version 0.0.2
 */
var GoldenLightBox = function(Parametros){
	/**
	 * Parāmetros{
	 * Itens: array(largura, altura, conteudo[, positionTop, positionLeft]  )}
	 */
    this.Novo = (function(){
		
	 var caminho = location.protocol +"//"+ window.location.hostname+"/";
        var largura = document.body.clientWidth //|| document.documentElement.clientWidth || window.innerWidth;//window.innerWidth; screen.availHeight
	 var altura = document.body.clientHeight  //|| document.documentElement.clientHeight || window.innerHeight;//window.innerHeight;screen.availWidth

	 var larg = Parametros.Itens[0];
        var alt = Parametros.Itens[1];

        var alt_light = ($(document).scrollTop() + $(window).height()) - alt + 20;//document.scrollWidth+"px";//document.clientWidth+"px";
        var larg_light = ($(document).scrollLeft() + $(window).width()) - larg;//document.scrollHeight+"px";//document.clientHeight+"px";
        
	 var _top = ((Parametros.Itens[3])?(Parametros.Itens[3]):((alt-alt_light) / 2) - 130);
	 var _left = ((Parametros.Itens[4])?(Parametros.Itens[4]):((larg_light) / 2));
		//
	 largura = (largura < screen.width)?screen.width-20:largura;
	 altura = (altura < screen.height)?screen.height-20:altura;

		var element = document.getElementById("Geral");
		if(element) return;
		//div geral para o conteudo
        __DivGeral__ = document.createElement("div");
        __DivGeral__.id = "Geral";
        $(__DivGeral__).attr("style","top:"+_top+"px;left:"+_left+"px;height:auto;width:"+ larg + "px;margin: 0 auto;position:fixed;background:#FFF;z-index:15001");

	 //$(__DivGeral__).css("left",_left + "px");
        //__DivGeral__.style.left = left + "px";
        //__DivGeral__.style.height = "auto";//alt+"px";
        //__DivGeral__.style.width = larg + "px";
        //__DivGeral__.style.margin = "0 auto";
        //__DivGeral__.style.position = "fixed";
        //__DivGeral__.style.opacity = 1;
        //__DivGeral__.style.filter = "alpha(opacity=100)";
        //__DivGeral__.style.background = "#FFF";
        //__DivGeral__.style.zIndex = "15001";
        
        __Div_LightBoxFechar__ = document.createElement("div");
        __Div_LightBoxFechar__.id = "Fechar";
        $(__Div_LightBoxFechar__).attr("style","top:"+(_top-20)+"px;left:"+_left+"px;height:20px;width:"+(larg+6) + "px;margin: 0 auto;position: fixed");

        //__Div_LightBoxFechar__.style.left = left + "px";
        //__Div_LightBoxFechar__.style.height = "20px";//alt+"px";
        //__Div_LightBoxFechar__.style.width = (larg+6) + "px";
        //__Div_LightBoxFechar__.style.margin = "0 auto";
        //__Div_LightBoxFechar__.style.position = "fixed";

        __Div_LightBoxFechar__.onclick = (function(){
            //document.body.removeChild(___DivGeral__);
        });
        
        __Div_LightBox__ = document.createElement("div");
        __Div_LightBox__.id = "Conteudo";
        $(__Div_LightBox__).attr("style","top:" + _top + "px;left:"+_left + "px;position:fixed;height:"+(($(window).height() < 545)?(alt-40)+"px":"auto")+";min-height:"+(($(window).height() < 545)?(alt-40):alt)+"px;width:"+(larg)+"px;border:3px solid #BEBEBE;background-color:#BEBEBE;margin:0 auto;overflow:auto;");
       //__Div_LightBox__.style.left = left + "px";
       //__Div_LightBox__.style.height = "auto";//alt+"px";
       //__Div_LightBox__.style.minHeight = alt + "px";
       //__Div_LightBox__.style.width = (larg) + "px";
	//__Div_LightBox__.style.border = "3px solid #BEBEBE";
	//__Div_LightBox__.style.backgroundColor = "#BEBEBE";
       //__Div_LightBox__.style.margin = "0 auto";
       //__Div_LightBox__.style.position = "fixed";
       //__Div_LightBox__.style.overflow = "auto";
       //__Div_LightBox__.style.padding = "0 5px";
       //__Div_LightBox__.onclick = (function(){
       //document.body.removeChild(___DivGeral__);
       //});
        
        ___DivFundo__ = document.createElement("div");
        ___DivFundo__.id = "_All";
 	 $(___DivFundo__).attr("style","background:#000;position:absolute;width:"+largura+"px;height:"+altura+"px;opacity:0.85;top:0;left:0;filter:alpha(opacity=85);z-index:15000");
        //___DivFundo__.style.background = "#000000";
        //___DivFundo__.style.position = "absolute";
        //___DivFundo__.style.width = largura + "px";
        //___DivFundo__.style.height = altura + "px";
        //___DivFundo__.style.opacity = 0.85;
        //___DivFundo__.style.top = "0px";
        //___DivFundo__.style.left = "0px";
        //___DivFundo__.style.filter = "alpha(opacity=85)";
        ///___DivFundo__.style.zIndex = "15000";
        ___DivFundo__.onclick = (function(){
            document.body.removeChild(___DivFundo__);
            var element = document.getElementById("_All");
            if (element) 
                document.body.removeChild(element);
            
            document.body.removeChild(__DivGeral__);
            var element = document.getElementById("Geral");
            if (element) 
                document.body.removeChild(element);
        });

        __DivFechar__ = document.createElement("div");
		//__DivFechar__.style.mozBorderRadius = "10px 10px 0 0";
		$(__DivFechar__).attr("style","float:left;padding:0 5px;height: 20px;width:"+(larg-20)+"px;background: url('"+caminho+"images/GoldenLightBox.png') repeat-x scroll 0 -23px transparent;");

		__DivFecharEsq__ = document.createElement("div");
		$(__DivFecharEsq__).attr("style","float: left; background: url('"+caminho+"images/GoldenLightBox.png') repeat scroll 0pt 0pt transparent; height: 20px; width: 8px;");
		
		__BntFechar__ = document.createElement("div");
		__BntFechar__.id = "BntFechar";
		$(__BntFechar__).attr("style","cursor:pointer; float: right; width: 20px; height: 20px; background: url('"+caminho+"images/GoldenLightBox.png') repeat scroll 44px -1px transparent;");
         
		__BntFechar__.onmouseover = (function(){
			this.style.background = "url('"+caminho+"images/GoldenLightBox.png') repeat scroll 25px -1px transparent";
		});
		__BntFechar__.onmouseout = (function(){
			this.style.background = "url('"+caminho+"images/GoldenLightBox.png') repeat scroll 44px -1px transparent";
		});
		__BntFechar__.onclick = (function(){
            var element = document.getElementById('_All');
            while (element) {
                document.body.removeChild(element);
                element = document.getElementById('_All');
            }
            var element = document.getElementById('Geral');
            while (element) {
                document.body.removeChild(element);
                element = document.getElementById('Geral');
            }
        });
		
		__DivFecharDir__ = document.createElement("div");
		$(__DivFecharDir__).attr("style","float: left; height: 20px; width: 8px; background: url('"+caminho+"images/GoldenLightBox.png') repeat scroll 8px -1px transparent");
        

        
        //
        __DivFechar__.appendChild(__BntFechar__);
		__Div_LightBoxFechar__.appendChild(__DivFecharEsq__);
		__Div_LightBoxFechar__.appendChild(__DivFechar__);
		__Div_LightBoxFechar__.appendChild(__DivFecharDir__);
        
        __DivGeral__.appendChild(__Div_LightBoxFechar__);
        __DivGeral__.appendChild(__Div_LightBox__);
        
        document.body.appendChild(__DivGeral__);
        document.body.appendChild(___DivFundo__);
		
		__Div_LightBox__.innerHTML = (Parametros.Itens[2]);
    });
	/**
	 * Function para Fechar o Light para objetos.....
	 * 
	 * Exemplo: 
	 * 	Objeto = new GoldenLightBox(Itens:[largura, altura, conteudo, positionTop, positionLeft]);
	 * 	Objeto.Novo();
	 * 	fechar.onclick = (function (){
	 * 		Objeto.Fechar();
	 *	});
	 */
	this.Fechar = (function (){
		var element = document.getElementById('_All');
        while (element) {
            document.body.removeChild(element);
            element = document.getElementById('_All');
        }
        var element = document.getElementById('Geral');
        while (element) {
            document.body.removeChild(element);
            element = document.getElementById('Geral');
        }
	});
	
}

