﻿var LightBoxLite = {
	SetWindowBackground: function(sColor) {
		this._fullWindowBgColor = sColor;
	}, 
	
	SetLightOptions: function(nWidth, nHeight, sBgColor) {
		this._lightWindowWidth = nWidth;
		this._lightWindowHeight = nHeight;
		this._lightWindowBgColor = sBgColor;
	}, 
	
	SetClosingElement: function(sElementId) {
		this._AddClosingElement(sElementId);
	}, 
	
	ShowInnerElement: function(oElement) {
        this._innerElement = oElement;
        this._CreateFullWindow();
        this._CreateLightWindow();
        this._fullWindow.style.display = "";
        this._innerElement.style.display = "";
        if (document.attachEvent)
        {        
            document.attachEvent("onclick",this._BodyClick);
        }
        else if (navigator.appName=="Netscape")
        {
            window.addEventListener("onclick",this._BodyClick,false); 
        }
        //document.body.onclick = this._BodyClick;
        this._FocusFirstText(this._innerElement);
	}, 
	
	Close: function() {
		if (this._fullWindow)
			this._fullWindow.style.display = "none";
		
		if (this._innerElement)
			this._innerElement.style.display = "none";
			
		if (document.detachEvent)
        {        
            document.detachEvent("onclick",this._BodyClick);
        }
        else if (navigator.appName=="Netscape")
        {
            window.removeEventListener("onclick",this._BodyClick,false); 
        }
        
	}, 
	
	Reload: function(sElementToFocus) {
		LightBoxLite.Close();
		LightBoxLite.ShowInnerElement(LightBoxLite._innerElement);
		if (typeof sElementToFocus != "undefined") {
			_ge(sElementToFocus).focus();
		}
	}, 
	
	FindNodeDeep: function(oParent, oNode) {
		if (oParent == oNode)
			return true;
		for (var i=0; i<oParent.childNodes.length; i++) {
			var bFound = LightBoxLite.FindNodeDeep(oParent.childNodes[i], oNode);
			if (bFound)
				return true;
		}
		return false;
	}, 
	
	ChangeIdDeep: function(oParent, sToAppend) {
		if ((typeof oParent.id != "undefined") && (oParent.id.length > 0))
			oParent.id = sToAppend + oParent.id;
		
		for (var i=0; i<oParent.childNodes.length; i++)
			LightBoxLite.ChangeIdDeep(oParent.childNodes[i], sToAppend);
	}, 
	
	_CreateFullWindow: function() {
	    if (this._fullWindow)
	        return;
		var oDiv = document.createElement("div");
		oDiv.id = "LightBoxLiteFullWindow";
		oDiv.style.width = "100%";
		oDiv.style.height = "100%";
		oDiv.style.position = "absolute";
		oDiv.style.top = "0px";
		oDiv.style.left = "0px";
		oDiv.style.backgroundColor = this._fullWindowBgColor;
		oDiv.style.filter = "alpha(opacity=75)";
		oDiv.style.opacity = "0.75";
		oDiv.style.display = "none";
		this._fullWindow = oDiv;
		document.body.appendChild(this._fullWindow);
	}, 
	
	_CreateLightWindow: function() {
	    if (!this._innerElement)
	        return;
		var oDiv = this._innerElement;
		oDiv.style.position = "absolute";
		oDiv.style.width = this._lightWindowWidth + "px";
		oDiv.style.height = this._lightWindowHeight + "px";
		//oDiv.style.padding = "5px";
		oDiv.style.textAlign = "left";
		//oDiv.style.border = "1px solid #000";
		oDiv.style.backgroundColor = this._lightWindowBgColor;
		oDiv.style.left = "50%";
		oDiv.style.top = "50%";
		oDiv.style.marginLeft = (-1*parseInt(this._lightWindowWidth/2)) + "px";
		oDiv.style.marginTop = (-1*parseInt(this._lightWindowHeight/2)) + "px";
		oDiv.style.filter = "alpha(opacity=100)";
		oDiv.style.opacity = "1.00";
		oDiv.style.display = "none";
		oDiv.style.zIndex = 99;
	}, 
	
	_AddClosingElement: function(sElementId) {
		this._closingElements[sElementId] = true;
	}, 
	
	_BodyClick: function(event) {
		if (typeof event == "undefined")
			event = window.event;
		
		var oSender = event.target || event.srcElement;
		if (oSender.id && oSender.id.length > 0 && LightBoxLite._closingElements[oSender.id]) {
			LightBoxLite.Close();
			return;
		}
		var sNodeName = oSender.nodeName.toLowerCase();
		if (sNodeName == "a" || sNodeName == "button" || (sNodeName == "input" && oSender.type == "button")) {
			//LightBoxLite.Reload();
			return;
		}
		
		if (LightBoxLite.FindNodeDeep(LightBoxLite._innerElement, oSender))
			return;
		
		//LightBoxLite.Close();
	}, 
	
	_FocusFirstText: function(oParent) {
	    var arrInputs = oParent.getElementsByTagName("input");
	    var oInput;
	    for (var i=0; i<arrInputs.length; i++) {
			oInput = arrInputs[i];
			if (oInput.type == "text") {
				try {
					oInput.focus();
				} catch (ex) {}
				return;
			}
	    }
	    if (arrInputs.length == 0)
	    {
	        arrInputs = oParent.getElementsByTagName("textarea");
	        for (var i=0; i<arrInputs.length; i++) 
	        {
			    oInput = arrInputs[i];
				try 
				{ 
				    oInput.focus();
				} catch (ex) {}
				return;
	        }
	    }
	}, 
	_innerElement: 0, 
	_fullWindow: 0, 
	_lightWindow: 0, 
	_closingElements: new Array(), 
	_fullWindowBgColor: "#1D242A", 
	_lightWindowWidth: 220,
	_lightWindowHeight: 335, 
	_lightWindowBgColor: "#EEEFF3"
}

