var LightboxItem = Class.create();
LightboxItem.prototype = {
	initialize: function() {		this.d = null;		this.params = { redirect:true };		this.IE6 = false;		var appname = navigator.appName;    	if (appname == "Microsoft Internet Explorer"){        	var appver = navigator.appVersion;			var p = appver.indexOf("MSIE", 0);			if(p >= 0) {				var p2 = appver.indexOf(";", p);				if(p2 >= 0) {					var iever = appver.substring(p + 5, p2);					if (parseInt(iever,10) <= 6) {						this.IE6 = true;					}				}			}    	}	},
	show: function(href) {		if ($("prev")) 			$("prev").parentNode.removeChild($("prev"));		if ($("next")) 			$("next").parentNode.removeChild($("next"));
		var url;		if (/http:\/\/|https:\/\//.test(href))			url = href;		else			url = document.location.protocol + "//" + window.location.host + href;		new Ajax.Request(url, {		method:"get",		asynchronous:false,		onFailure : function(Response) {			alert("ajax request failure.");		},		onException : function (Response) {			alert("ajax request exception.");		},		onComplete : (function(li) {			return function (Response) {				li.open();				li.window_contents.innerHTML = Response.responseText;				li.d.position();				li.d.open();				li.position();				li.listener();				gatrackPageview();			}		})(this)		});	},	bind: function() {		/*		if (/contactssl/.test(window.location.search))			return;		*/		var content = $("item").innerHTML;		this.open();		this.window_contents.innerHTML = content;		$("item").innerHTML = "";		this.d.position();		this.d.open();		this.position();		this.listener();		gatrackPageview();	},	open: function() {		if (this.window_contents)			this.window_contents.innerHTML = "";		if (!this.d) {			var n = document.createElement("div");			document.body.appendChild(n);			this.d = this.dialogFactory(n);		}	},	close: function(params) {		var undefined;		if (params !== undefined) {			for (key in params) {	  			this.params[key] = params[key];	  		} 		}				if (this.d) {			this.d.close();			//this.d.destroy();			//this.d = null;			//delete this.d;		}	},	
	position: function() {		if (this.d) {			var y = window.document.body.scrollTop  || window.document.documentElement.scrollTop;			if (y) {				var d = this.d.container.getDimensions();				var h = window.document.body.clientHeight || window.innerHeight;				if (this.IE6)					h = kl_windowheight();				if (h < d.height) {					Element.setStyle(this.d.container, { top:y+"px" });				}			}			if (Prototype.Browser.IE) {				if ($("control_overlay")) {					var h = window.document.body.scrollHeight  || window.document.documentElement.scrollHeight;					Element.setStyle($("control_overlay"), { height:h+"px" });				}			}		}	},
	listener: function() {		var n = document.getElementsByClassName("thumbnail");		if (n.length) {			for (i = 0; i < n.length; i++) {				Event.observe(n[i], "click", function() { 					var img = new Image(); 					img.src = this.src.replace("/s/", "/l/");					img.onload = function() {						$("picture").src = this.src;					};					$("picture").src = this.src.replace("/s/", "/l/");				}, false);				//n[i].parentNode.setAttribute("href", "#");				n[i].parentNode.setAttribute("href", "javascript:void(0)");			}		}		var n = document.getElementsByClassName("rollover");		if (n.length) {			for (var i = 0; i < n.length; i++) {				Event.observe(n[i], "mouseover", function() {					if (!/\-on/.test(this.getAttribute("src"))) {						var src = this.getAttribute("src");						var suffix = src.substring(src.lastIndexOf('.'), src.length);						this.setAttribute("src", src.replace(suffix, "-on" + suffix));					}				}, false);				Event.observe(n[i], "mouseout", function() {					this.setAttribute("src", this.getAttribute("src").replace("-on", ""));				}, false);			}		}		var d = this.d.container.getDimensions();		var left_prev,left_next;		if ($("prev")) {			if (Prototype.Browser.IE)				left_prev = parseInt(d.width / 2 - (835 / 2) - 60, 10) + "px";			else 					left_prev = -parseInt(Element.getStyle("prev", "width"), 10) - 20 + "px";			Element.setStyle($("prev"), {			left: left_prev,			top: parseInt(d.height / 2 - (parseInt(Element.getStyle("prev", "height"), 10) / 2), 10) + "px",			display:"block"			});		}		if ($("next")) {			if (Prototype.Browser.IE)				left_next = parseInt(d.width / 2 + (835 / 2) + 20, 10) + "px";			else 					left_next = d.width + 20 + "px";			Element.setStyle($("next"), {			left:left_next,			top:parseInt(d.height / 2 - (parseInt(Element.getStyle("next", "height"), 10) / 2), 10) + "px",			display:"block"			});		}						var n = this.window_contents.getElementsByTagName("img");		if (n.length) {			for (var i = 0; i < n.length; i++) {				var img = new Image();				img.src = n[i].src;				Event.observe(img, "load", (function(i) {					return function(e) {						i.src = this.src;					}				})(n[i]), false);			}		}			},
	dialogFactory: function(e) {  	 	this.window_contents = new Element("div", {  	    	className: "window_contents"  	 	});		var d = new Control.Modal(e, Object.extend({  			overlayOpacity:0.8,  			className: 'window',  			afterClose: (function(li) {				return function() {					if ($("prev")) 						$("prev").parentNode.removeChild($("prev"));					if ($("next")) 						$("next").parentNode.removeChild($("next"));		 			if (/show/.test(window.location.pathname)) {						if (li.params.redirect) {							if (/\/item\/list/.test(window.document.referrer))		 						window.location.href = window.location.protocol  + "//" + window.location.host + "/item/list/";		 					else 		 						window.location.href = window.location.protocol  + "//" + window.location.host;						}		 			}	 			}			})(this)		}, {}));		d.container.insert(this.window_contents);		return d;	}}

