


/** { [object.window.imgDisplay]
* Scott McDonald
* param o as object :: holder for all params
* param o->anchor :: pointer to link which opened the image
* param o->path :: path to image
* @dependency :: [function.window.AddListener]
* @dependency :: [function.window.Catch]
* @dependency :: [function.window.DOM.isParentNode]
* @dependency :: [function.window.DOM.setElem]
* @dependency :: [function.window.getPepper]
* @dependency :: [function.window.getSourceFromEvent]
* @dependency :: [function.window.PositionElementToElement]
* @dependency :: [function.window.RemoveListener]
* @dependency :: [function.window.trace]
* @dependency :: [variable.window.tooltip]
*
* @edit :: Wednesday, January 14, 2009 - logic to autosize on height too large to fit window;
* @edit :: Tuesday, January 27, 2009 - updated for compiling
**/
function imgDisplay(o){

	try {
		if(window.IMGDISPLAY_OUTPUTLAYER){
			window.IMGDISPLAY_OUTPUTLAYER.close();
		};
		var target = this;
		this.image = undefined;
		this.ImgLayer = undefined;
		this.ONCLICK = undefined;

		try{
			this.anchor = o.anchor;
			this.path = o.path;
			this.design = o.design;
			if(!this.path || !this.anchor){return;};

			this.ONCLICK = this.anchor.onclick;
			if(this.ONCLICK==undefined){this.ONCLICK = this.anchor.href;};

			if(this.ONCLICK != undefined){
				this.anchor.onclick = function(){
					window.tooltip.show("please wait for image to load...");
				};
			};
		} catch(e){};

		if(this.path){
			var img = this.image = new Image();
			img.id = "imgDisplayImage";
			img.onload = function() {
				try {
					var imgLayer = target.ImgLayer = setElem("div");
					imgLayer.id = "imgDisplayLayer";
					imgLayer.style.position = "absolute";
					imgLayer.style.top = 0;
					imgLayer.style.left = 0;
					imgLayer.style.textAlign = "center";
					imgLayer.style.border = "1px solid #CCCCCC";
					imgLayer.style.width = this.width + 10 + "px";
					imgLayer.style.height = this.height + 40 + "px";
					imgLayer.style.padding = "5px";
					imgLayer.style.backgroundColor = "#FFFFFF";
					imgLayer.style.verticalAlign = "middle";
					imgLayer.appendChild(this);
					window.document.body.appendChild(imgLayer);
					imgLayer.appendChild(setElem("br"));
				} catch (e) { };

				try {
					var imgClose = setElem("a");
					imgClose.id = "imgDisplay_closeLink";
					imgClose.href = "javascript:;";
					imgClose.onclick = function() { target.close(); };
				} catch (e) { };

				imgClose.innerHTML = "Click To Close";
				imgLayer.appendChild(imgClose);

				window.IMGDISPLAY_OUTPUTLAYER = target;
				window.IMGDISPLAY_OUTPUTLAYER_ONRESIZE = function() {
					try {
						target.position();
					} catch (e) { Catch(this.cFilePath + "->IMGDISPLAY_OUTPUTLAYER_ONRESIZE(0)", e, true); };
				};

				window.IMGDISPLAY_OUTPUTLAYER_ONCLICK = function(e) {
					try {
						if (!isParentNode(getSourceFromEvent(e), target.ImgLayer)) {
							if (getSourceFromEvent(e) != target.anchor) {
								target.close();
							};
						};
					} catch (e) { Catch(this.cFilePath + "->IMGDISPLAY_OUTPUTLAYER_ONCLICK(0)", e, true); };
				};

				AddListener(window, "scroll", window.IMGDISPLAY_OUTPUTLAYER_ONRESIZE);
				AddListener(window, "resize", window.IMGDISPLAY_OUTPUTLAYER_ONRESIZE);
				AddListener(document, "click", window.IMGDISPLAY_OUTPUTLAYER_ONCLICK);
				target.position();
				target.anchor.onclick = target.ONCLICK;
			};

			img.onerror = function() { trace("Could Not Load: " + this.src); };
			img.src = this.path + "?getPepper="+getPepper();
		};
	} catch(e){Catch("imgDisplay->class",e,true);};

	this.position = function(){
		try {
			if(this.image){
				if((this.image.height+40)>window.height()){
					var per = (window.height()-40)/this.image.height;
					this.image.height = this.image.height*per;
					this.image.width = this.image.width*per;
					this.ImgLayer.style.width = this.image.width + 10 + "px";
					this.ImgLayer.style.height = this.image.height + 40 + "px";
				};
			};
			PositionElementToElement(this.ImgLayer,this.anchor);
		} catch(e){Catch("imgDisplay->position",e,true);};
	};

	this.close = function() {
		try {
			RemoveListener(window, "scroll", window.IMGDISPLAY_OUTPUTLAYER_ONRESIZE);
			RemoveListener(window, "resize", window.IMGDISPLAY_OUTPUTLAYER_ONRESIZE);
			RemoveListener(document, "click", window.IMGDISPLAY_OUTPUTLAYER_ONCLICK);
			this.ImgLayer.parentNode.removeChild(this.ImgLayer);
			window.IMGDISPLAY_OUTPUTLAYER = undefined;
		} catch (e) { Catch("imgDisplay->close", e, true); };
	};
};
/** } [function.window.imgDisplay] **/
