/****************************
inspired by
Greased Lightbox v0.12
May 25, 2006
Copyright (c) 2006, Joe Lencioni
http://shiftingpixel.com/lightbox
*****************************/

var lightWin = {

	alert : function(title, text, parameters) {
		if(lightWin.isShowing) lightWin.hide();
		parameters = parameters || {};

		var lightWinTitle = $('lightWinTitle');
		var lightWinContent = $('lightWinContent');
		var lightWinButtons = $('lightWinButtons');

		var okLabel = parameters && parameters.okLabel ? parameters.okLabel : "Ok";
		var buttons = "<form><input type='button' value='" + okLabel + "' onclick='lightWin.okCallback(event)'/></form>";

		lightWin.okCB = parameters.ok || null;
		lightWin.cancelCB = parameters.ok || null;

		lightWinTitle.style.display = "";
		lightWinTitle.innerHTML = title;
		lightWinContent.innerHTML = text;
		lightWinButtons.innerHTML = buttons;

		lightWin.showWindow(parameters);
	},

	confirm : function(title, text, parameters) {
		if(lightWin.isShowing) lightWin.hide();
		parameters = parameters || {};

		var lightWinTitle = $('lightWinTitle');
		var lightWinContent = $('lightWinContent');
		var lightWinButtons = $('lightWinButtons');

		var okLabel = parameters.okLabel ? parameters.okLabel : "Ok";
		var cancelLabel = parameters.cancelLabel ? parameters.cancelLabel : "Cancel";
		var buttons = "<form><input type='button' value='" + cancelLabel + "' onclick='lightWin.cancelCallback(event)'/> <input type='button' value='" + okLabel + "' onclick='lightWin.okCallback(event)'/></form>";

		lightWin.okCB = parameters.ok || null;
		lightWin.cancelCB = parameters.cancel || null;

		lightWinTitle.style.display = "";
		lightWinTitle.innerHTML = title;
		lightWinContent.innerHTML = text;
		lightWinButtons.innerHTML = buttons;

		lightWin.showWindow(parameters);
	},

	wait : function(title) {
		if(lightWin.isShowing) lightWin.hide();
		var arrayPageSize					= lightWin.getPageSize();
		var arrayPageScroll 				= lightWin.getPageScroll();
		this.showOverlay(arrayPageScroll, arrayPageSize);

		// center loader and error message
		var objLoadingText					= $('lightWinLoadingText');
		objLoadingText.innerHTML			= title || "Loading...";

		var objLoading						= $('lightWinLoading');
		objLoading.style.visibility			= 'hidden';
		objLoading.style.display			= 'block';
		lightWin.center(objLoading, arrayPageScroll, arrayPageSize);
		objLoading.style.visibility			= 'visible';

		this.eventResize = this.recenter.bindAsEventListener(this);
		Event.observe(window, "resize", this.eventResize);
		Event.observe(window, "scroll", this.eventResize);
	},

	link : function(title, link, parameters) {
		if(lightWin.isShowing) lightWin.hide();
		parameters = parameters || {};

		var lightWinTitle = $('lightWinTitle');
		var lightWinContent = $('lightWinContent');
		var lightWinButtons = $('lightWinButtons');

		var arrayPageSize					= lightWin.getPageSize();
		var arrayPageScroll 				= lightWin.getPageScroll();
		if(parameters.fullSize) {
			var w = arrayPageSize[2] - 60;
			var h = arrayPageSize[3] - 80;
			parameters.fullSize = 0;
		} else {
			var w = 400;
			var h = 300;
		}
		parameters.width = w;
		parameters.height = h;

		var useif = parameters.useiframe && Ajax;
		if(useif)
			var content = "<table width='100%' height='100%'><tr><td align='center'>" +
				"<iframe id='popup_linkcontent' width='" + w + "' height='" + h + "' src='" + link + "' style='border:0'></iframe>" +
				"</td></tr></table>";
		else var content = "<div id='popup_linkcontent' style='margin:5px'>loading...</div>";

		lightWinTitle.style.display = "";
		lightWinTitle.innerHTML = title;
		lightWinContent.innerHTML = content;
		lightWinButtons.innerHTML = "";

		lightWin.showWindow(parameters);

		if(!useif) new Ajax.Updater("popup_linkcontent", link, {method:'get'});
	},

	image : function(event, img) {
		if(lightWin.isShowing) lightWin.hide();
		// let shift+click and ctrl+click (but not ctrl+shift+click) through without lightbox
		if ((event.shiftKey || event.ctrlKey) && !(event.shiftKey && event.ctrlKey)) return true;

		// if this is a real event stop the click and set the link, otherwise, just set the link
		if (event.currentTarget) {
			Event.stop(event);
			var link						= event.currentTarget;
		} else {
			var link						= event;
		}

		if (img == null || img == '') img = link.getAttribute('href');
		lightWin.currentAddress		= unescape(unescape(lightWin.getAddress(link)));

		// make ctrl+shift+click follow link without lightbox
		if (event.shiftKey && event.ctrlKey) {
			window.location.href			= lightWin.currentAddress;
			return true;
		}

		// get the caption from the title attribute of the link. if that doesn't exist, look for it in the title attribute of the image.
		var capt							= link.getAttribute('title');

		if (capt == null || capt == '') {
			try {
				var imgObj					= link.firstChild;
				capt						= imgObj.getAttribute('title');
			} catch (e) { }
		}
		if (capt == null || capt == '') {
			try {
				var imgObj					= link.firstChild;
				capt						= imgObj.getAttribute('alt');
			} catch (e) { }
		}

		this.wait('Loading Image...');

		var lightWinTitle = $('lightWinTitle');
		var lightWinContent = $('lightWinContent');
		var lightWinButtons = $('lightWinButtons');

		lightWinTitle.style.display = "none";
		lightWinContent.innerHTML = "<p align='center'><img id='lightWinImage' onclick='lightWin.hide(event)' /></p>" +
			"<p align='center' id='lightWinCaption'></p>";
		lightWinButtons.innerHTML = "";

		lightWinContent.style.width = "";
		lightWinContent.style.height = "";

		var objImage						= $('lightWinImage');
		var objImageCaption					= $('lightWinCaption');
		var objLightbox						= $('lightWin');
		var objOverlay						= $('lightWinOverlay');
		var objLoading						= $('lightWinLoading');
		var imgPreload						= $('lightWinPreload');

		// preload image
		preloaderDone = function() {
			objImage.src					= img;
			objImage.removeAttribute('width');
			objImage.removeAttribute('height');
			lightWin.aspectRatio		= null;

			if (capt) {
				objImageCaption.innerHTML		= capt;
			} else {
				objImageCaption.innerHTML		= img;
			}

			// dimensions
			objImageCaption.innerHTML			= objImageCaption.innerHTML + '<br/><br/>(width: ' + objImage.width + 'px; height: ' + objImage.height + 'px;)';

			// center lightbox and make sure that the top and left values are not negative
			// and the image placed outside the viewport
			objLightbox.style.visibility	= 'hidden';
			objLightbox.style.display		= 'block';
			
			var arrayPageSize					= lightWin.getPageSize();
			var arrayPageScroll 				= lightWin.getPageScroll();
			lightWin.center(objLightbox, arrayPageScroll, arrayPageSize);
			objLoading.style.display		= 'none';
			objLightbox.style.visibility	= 'visible';

			// if it went bigger than the page
			if (objLightbox.offsetHeight > objOverlay.offsetHeight) objOverlay.style.height		= objLightbox.offsetHeight + 'px';
			if (objLightbox.offsetWidth > objOverlay.offsetwidth) objOverlay.style.width		= objLightbox.offsetWidth + 'px';

			// clean it up a bit for memory's sake
			Event.stopObserving(imgPreload, "load", preloaderDone);
			Event.stopObserving(imgPreload, "error", lightWin.noImage);
			imgPreload.src					= '';

			return false;
		} // end preloaderDone()

		if (imgPreload.src != img) {
			Event.observe(imgPreload, "load", preloaderDone);
			Event.observe(imgPreload, "error", lightWin.noImage);
			imgPreload.src					= img;
		} else {
			preloaderDone();
		}
	},

	dynlink : function(event, url) {
		if(lightWin.isShowing) lightWin.hide();
		// let shift+click and ctrl+click (but not ctrl+shift+click) through without lightbox
		if ((event.shiftKey || event.ctrlKey) && !(event.shiftKey && event.ctrlKey)) return true;

		// if this is a real event stop the click and set the link, otherwise, just set the link
		if (event.currentTarget) {
			Event.stop(event);
			var link						= event.currentTarget;
		} else {
			var link						= event;
		}

		if (url == null || url == '') url = link.getAttribute('href');
		lightWin.currentAddress		= unescape(unescape(lightWin.getAddress(link)));

		// make ctrl+shift+click follow link without lightbox
		if (event.shiftKey && event.ctrlKey) {
			window.location.href			= lightWin.currentAddress;
			return true;
		}

		// get the caption from the title attribute of the link. if that doesn't exist, look for it in the title attribute of the image.
		var capt							= link.getAttribute('title');

		if (capt == null || capt == '') {
			try {
				var imgObj					= link.firstChild;
				capt						= imgObj.getAttribute('title');
			} catch (e) { }
		}

		this.wait('Loading Page...');

		var lightWinTitle = $('lightWinTitle');
		var lightWinContent = $('lightWinContent');
		var lightWinButtons = $('lightWinButtons');

		lightWinTitle.innerHTML = capt == null || capt == '' ? 'Content' : capt;
		lightWinContent.innerHTML = "<table width='100%' height='100%'><tr><td align='center'>" +
				"<iframe id='lightWinFrame' width='100%' height='100%' style='border:0'></iframe>" +
				"</td></tr></table>";
		lightWinButtons.innerHTML = "";

		lightWinContent.style.width = "";
		lightWinContent.style.height = "";

		var objLightbox						= $('lightWin');
		var objFrame						= $('lightWinFrame');
		var objOverlay						= $('lightWinOverlay');
		var objLoading						= $('lightWinLoading');
		var framePreload					= $('lightWinPreloadFrame');

		// preload image
		preloaderFrameDone = function() {
			objFrame.src				= url;
			lightWin.aspectRatio		= null;

			// center lightbox and make sure that the top and left values are not negative
			// and the image placed outside the viewport
			objLightbox.style.visibility	= 'hidden';
			objLightbox.style.display		= 'block';

			var arrayPageSize					= lightWin.getPageSize();
			var arrayPageScroll 				= lightWin.getPageScroll();
			lightWin.center(objLightbox, arrayPageScroll, arrayPageSize);
			objLoading.style.display		= 'none';
			objLightbox.style.visibility	= 'visible';

			// if it went bigger than the page
			if (objLightbox.offsetHeight > objOverlay.offsetHeight) objOverlay.style.height		= objLightbox.offsetHeight + 'px';
			if (objLightbox.offsetWidth > objOverlay.offsetwidth) objOverlay.style.width		= objLightbox.offsetWidth + 'px';

			// clean it up a bit for memory's sake
			Event.stopObserving(framePreload, "load", preloaderFrameDone);
			Event.stopObserving(framePreload, "error", lightWin.noImage);
			framePreload.src					= '';

			return false;
		} // end preloaderFrameDone()

		if (framePreload.src != url) {
			Event.observe(framePreload, "load", preloaderFrameDone);
			Event.observe(framePreload, "error", lightWin.noImage);
			framePreload.src = url;
		} else {
			preloaderFrameDone();
		}
	},

	// private functions

	// getAddress()
	// extracts an address out of a linkObj
	getAddress : function(linkObj) {
        var address                            = linkObj.getAttribute('href');
       
        // for creammonkey users because Safari doesn't like stopping events even though it says it does...
        if(/Safari/.test(navigator.userAgent))
            linkObj.onclick = function() { return false; };
        return address;
    }, // end getAddress()

	// getPageScroll()
	// Returns array with x,y page scroll values.
	// Core code from - quirksmode.org
	getPageScroll : function() {
		var yScroll;

		if (self.pageYOffset) {
			yScroll 						= self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll 						= document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			yScroll 						= document.body.scrollTop;
		}

		arrayPageScroll 					= new Array('', yScroll) 
		return arrayPageScroll;
	}, // end getPageScroll()

	// getPageSize()
	// Returns array with page width, height and window width, height
	// Core code from - quirksmode.org
	// Edit for Firefox by pHaez
	getPageSize : function() {
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {	
			xScroll							= document.body.scrollWidth;
			yScroll							= window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll							= document.body.scrollWidth;
			yScroll							= document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll							= document.body.offsetWidth;
			yScroll							= document.body.offsetHeight;
		}

		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth						= self.innerWidth;
			windowHeight					= self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth						= document.documentElement.clientWidth;
			windowHeight					= document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth						= document.body.clientWidth;
			windowHeight					= document.body.clientHeight;
		}

		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight) pageHeight = windowHeight;
		else pageHeight = yScroll;

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth) pageWidth = windowWidth;
		else pageWidth = xScroll;

		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}, // end getPageSize()
	
	// center()
	// centers the object in the page
	center : function(objToCenter, arrayPageScroll, arrayPageSize) {
		var objTop						= arrayPageScroll[1] + ((arrayPageSize[3] - 10 - objToCenter.offsetHeight) / 2);
		var objLeft						= (arrayPageSize[0] - objToCenter.offsetWidth) / 2;

		objToCenter.style.top			= (objTop < 0) ? "0px" : objTop + "px";
		objToCenter.style.left			= (objLeft < 0) ? "0px" : objLeft + "px";

		// I don't know exactly why, but it doesn't always center it properly if this isn't done twice...		
		objToCenter.style.top			= (objTop < 0) ? "0px" : objTop + "px";
		objToCenter.style.left			= (objLeft < 0) ? "0px" : objLeft + "px";
	}, // end center()

	recenter: function(event) {
		var arrayPageSize					= lightWin.getPageSize();
		var arrayPageScroll 				= lightWin.getPageScroll();
		var objLightbox						= $('lightWin');
		var objLoading						= $('lightWinLoading');
		
		try {
		objLightbox.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - objLightbox.offsetHeight) / 2) + 'px');
		objLightbox.style.left = (((arrayPageSize[0] - objLightbox.offsetWidth) / 2) + 'px');	
		objLoading.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - objLoading.offsetHeight) / 2) + 'px');
		objLoading.style.left = (((arrayPageSize[0] - objLoading.offsetWidth) / 2) + 'px');	
		} catch(e) { }
	},

	// currentAddress
	// address of the link that was clicked on. updated from show() and is used in noimage()
	currentAddress : null,
	
	showWindow :  function(parameters) {
		var lightWinContent = $('lightWinContent');

		var arrayPageSize					= lightWin.getPageSize();
		var arrayPageScroll 				= lightWin.getPageScroll();
		this.showOverlay(arrayPageScroll, arrayPageSize);

		var objLightbox = $('lightWin');

		if(parameters.width) lightWinContent.style.width = parameters.width + "px";
		else lightWinContent.style.width = "";

		if(parameters.height) lightWinContent.style.height = parameters.height + "px";
		else lightWinContent.style.height = "";

		if(parameters.fullSize) {
			var w = arrayPageSize[2] - 60;
			lightWinContent.style.width = w + "px";
			var h = arrayPageSize[3] - 120;
			lightWinContent.style.height = h + "px";
		}

		objLightbox.style.visibility		= 'hidden';
		objLightbox.style.display			= 'block';
		lightWin.center(objLightbox, arrayPageScroll, arrayPageSize);
		objLightbox.style.visibility		= 'visible';

		this.eventResize = this.recenter.bindAsEventListener(this);
		Event.observe(window, "resize", this.eventResize);
		Event.observe(window, "scroll", this.eventResize);
	},

	showOverlay : function(arrayPageScroll, arrayPageSize) {
		lightWin.isShowing			= true;

		// prep objects
		var objOverlay						= $('lightWinOverlay');

		// set height of Overlay to take up whole page and show
		objOverlay.style.height				= (arrayPageSize[1] + 'px');
		objOverlay.style.display			= 'block';

		// hides flash movies that peek through the overlay
		var objects = document.getElementsByTagName("object");
        for (i = 0; i != objects.length; i++)
                objects[i].style.visibility = "hidden";

        var embeds = document.getElementsByTagName("embed");
        for (i = 0; i != embeds.length; i++)
                embeds[i].style.visibility = "hidden";
		
        var embeds = document.getElementsByTagName("select");
        for (i = 0; i != embeds.length; i++)
                embeds[i].style.visibility = "hidden";

	}, // end showOverlay()

	okCallback : function(event) {
		if(lightWin.okCB)  {
			if(!lightWin.okCB()) return;
		}
		lightWin.hide(event);
		lightWin.okCB = null;
		lightWin.cancelCB = null;
	},

	cancelCallback : function(event) {
		lightWin.hide(event);
		if(lightWin.cancelCB) lightWin.cancelCB();
		lightWin.okCB = null;
		lightWin.cancelCB = null;
	},

	// hide()
	// Stops the preloader in case it hasn't finished and then hides all of the lightbox components
	hide : function(event) {
		if(event) {
			Event.stop(event);
		}
		Event.stopObserving(window, "resize", this.eventResize);
		Event.stopObserving(window, "scroll", this.eventResize);

		lightWin.isShowing			= false;
		//lightWin.aspectRation		= null;
		
		// get objects
		var objLoading						= $('lightWinLoading');
		var objError						= $('lightWinError');
		var objOverlay						= $('lightWinOverlay');
		var objLightbox						= $('lightWin');
		var imgPreload						= $('lightWinPreload');
		var framePreload					= $('lightWinPreloadFrame');

		// stop preloader
		try {
			Event.stopObserving(imgPreload, "load", preloaderDone);
			Event.stopObserving(imgPreload, "error", lightWin.noImage);
			Event.stopObserving(framePreload, "load", preloaderFrameDone);
			Event.stopObserving(framePreload, "error", lightWin.noImage);
		} catch(e) { }
		imgPreload.src						= '';

		// show flash movies again
		var objects							= document.getElementsByTagName("object");
        for (i = 0; i != objects.length; i++) {
			objects[i].style.visibility		= "visible";
        }

		var embeds							= document.getElementsByTagName("embed");
        for (i = 0; i != embeds.length; i++) {
			embeds[i].style.visibility		= "visible";
        }

		var embeds							= document.getElementsByTagName("select");
        for (i = 0; i != embeds.length; i++) {
			embeds[i].style.visibility		= "visible";
        }

		// hide everything
		objLoading.style.display			= 'none';
		objError.style.display				= 'none';
		objOverlay.style.display			= 'none';
		objLightbox.style.display			= 'none';
		
	}, // end hide()

	aspectRatio: null,
        
	// resize()
	resize : function(event, resizeByAmount) {
		Event.stop(event);
		
		// resize the image
		var objImage						= $('lightWinImage');
		var imgPreload						= $('lightWinPreload');

        if (!this.aspectRatio) this.aspectRatio = objImage.height / objImage.width;
                
		if (resizeByAmount == 0) {
                    objImage.removeAttribute('width');
                    objImage.removeAttribute('height');
		} else {
			var newWidth					= objImage.width + (objImage.width * (resizeByAmount/100));
			var newHeight					= this.aspectRatio * newWidth;
			if (newWidth > 30 || newHeight > 30) {
				objImage.width				= newWidth;
				objImage.height				= newHeight;
			}
		}
		
		// re-center the lightbox
		var objLightbox						= $('lightWin');
		var arrayPageSize					= lightWin.getPageSize();
		var arrayPageScroll 				= lightWin.getPageScroll();
		lightWin.center(objLightbox, arrayPageScroll, arrayPageSize);
	}, // end resize()
	
	// noImage()
	// Displays a nice error message when no image can be found.
	noImage : function(event) {
		var objLoading						= $('lightWinLoading');
		var objError						= $('lightWinError');
		var arrayPageSize					= lightWin.getPageSize();
		var arrayPageScroll 				= lightWin.getPageScroll();
		
		objError.style.visibility			= 'hidden';
		objError.style.display				= 'block';
		
		lightWin.center(objError, arrayPageScroll, arrayPageSize);
		
		objLoading.style.display			= 'none';
		objError.style.visibility			= 'visible';
	}, // end noImage()

	// lastMove
	// keeps track of which arrow key user last used (1 = right, -1 = left)
	lastMove : 1,

	// isShowing
	// true if lightbox is currently showing. updated by show() and hide()
	isShowing : false,

	// handleKey(event)
	// handles keypress. If 'x' is pressed then it hides the lightbox. If a left or right arrow is pressed it cycles through images on a page
	handleKey : function(event) {
		if (lightWin.isShowing) {
			var keycode							= event.which;
			var key								= String.fromCharCode(keycode).toLowerCase();
			
			switch(key) {
				case 'x':
					lightWin.cancelCallback(event);
					break;
				default:
					switch(event.keyCode) {
						// esc key
						case 27:
							lightWin.cancelCallback(event);
							break;
					} // end switch(event.keyCode)
					break;
			} // end switch(key)
		} // end if
	}, // end getKey()
	
	// init()
	// Function runs on window load, going through link tags looking for links to images.
	// These links receive onclick events that enable the lightbox display for their targets.
	// The function also inserts html markup at the top of the page which will be used as a
	// container for the overlay pattern and the inline image.
	init : function() {

		greasedLanguage.init();

		// set up list of searchDefs to use based on how includeRegExp matches window.location.href
		var currentURL						= window.location.href;
		var searchDefsToUse					= new Array();
		
		// set variables
		var links							= document.getElementsByTagName('a');
		var link							= null;
		
		var objBody							= document.getElementsByTagName("body").item(0);
		var pngOverlay						= "url('/i/overlay.png')";

		// CSS
		var head = document.getElementsByTagName('head')[0];
		var styleSheet						= document.createElement('style');
		styleSheet.setAttribute('id','lightWinCSS');
		styleSheet.setAttribute('type','text/css');
		head.appendChild(styleSheet);

/*
		var cssStr						= ''+
		'#lightWinOverlay { position:absolute; top:0; left:0; z-index:200000; width:100%; background-image:url(/i/overlay.png); cursor:pointer }'+
		'* html #lightWinOverlay { background-color: transparent; back\ground-color: transparent; background-image: none; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/i/overlay.png", sizingMethod="scale"); } '+
		'#lightWinLoading { position: absolute; z-index: 200005; color: #666; font-weight: bold; font-family: "Trebuchet MS", Tahoma, Arial, Verdana, sans-serif; text-align: center; line-height: 2em; }'+
		'p#lightWinLoadingText { margin: 0; padding: 25px 0 5px 0; font-size: 45px; color: #666; font-weight: bold; font-family: "Trebuchet MS", Tahoma, Arial, Verdana, sans-serif; line-height: 1em; text-align: center; }'+
		'p#lightWinLoadingHelp { margin: 0; padding: 5px 0; font-weight: normal; font-size: 11px; color: #000; font-family: "Trebuchet MS", Tahoma, Arial, Verdana, sans-serif; line-height: 1em; text-align: center; }'+
		'#lightWinError { position: absolute; z-index: 200005; text-align: center; background: #000; color: #aaa; padding: 10px; border: 1px solid #444; -moz-border-radius: 10px; font-family: verdana, sans-serif; font-size: 11px; }'+
		'p#lightWinErrorMessage { color: #fff; font-size: 45px; font-weight: bold; margin: 10px 20px; font-family: "Trebuchet MS", Tahoma, Arial, Verdana, sans-serif; text-decoration: none; border: none; text-align: center; cursor: pointer; }'+
		'#lightWinError a, #lightWin a { color: #aaa; text-decoration: none; border-bottom: 1px solid #777; }'+
		'#lightWin { position: absolute; z-index: 200005; background: #fff; color: #000; padding: 5px; border: 1px solid #E2E1C7; -moz-border-radius: 10px; font-family: verdana, sans-serif; font-size: 11px; }'+
//		'#lightWinTitle { text-align: center; border:1px solid #E2E1C7; background-color:#F3F3E7; font-weight:bold; font-size:1.1em }'+
		'#lightWinClose { float:right; padding:2; cursor: pointer }'+
		'#lightWinContent { padding-top:5px; overflow:auto }'+
		'#lightWinButtons { text-align: center; padding-top:5px }'+
		'img#lightWinImage { border: none; cursor: pointer; }'+
		'img#lightWinImage, img#lightWinPreload {  max-height: none; max-width: none; }'+
		'#lightWin, #lightWinOverlay, #lightWinError, #lightWinLoading, img#lightWinPreload, iframe#lightWinPreloadFrame  { display: none; }'+
		'#lightWinCaption { color: #aaa; padding: 10px 0; font-size:90% }';

		if(styleSheet.styleSheet) { // IE
			styleSheet.styleSheet.cssText = cssStr;
		} else {
			var cssText	= document.createTextNode(cssStr);
			styleSheet.appendChild(cssText);
		}
*/

		this.eventHide = lightWin.cancelCallback.bindAsEventListener(lightWin);

		// overlay div
		var objOverlay						= document.createElement("div");
		objOverlay.setAttribute('id','lightWinOverlay');
		objBody.insertBefore(objOverlay, objBody.firstChild);
		Event.observe(objOverlay, "click", this.eventHide);

		// loader div
		var objLoading						= document.createElement("div");
		objLoading.setAttribute('id','lightWinLoading');
		objBody.insertBefore(objLoading, objBody.nextSibling);
		Event.observe(objLoading, "click", this.eventHide);
		
		var loadingGif = document.createElement('img');
		loadingGif.src = "/i/waiting.gif";
		loadingGif.style.border					= 'none';
		
		objLoading.appendChild(loadingGif);

		// loading text
		var objLoadingText					= document.createElement("p");
		objLoadingText.setAttribute('id','lightWinLoadingText');
		objLoadingText.innerHTML			= greasedLanguage[greasedLanguage.language][0].loading;
		objLoading.appendChild(objLoadingText);
		
		// helper message
		var objLoadingHelp					= document.createElement("p");
		objLoadingHelp.setAttribute('id','lightWinLoadingHelp');
		objLoadingHelp.innerHTML			= greasedLanguage[greasedLanguage.language][0].loadingSub;
		objLoading.appendChild(objLoadingHelp);

		// error div
		var objErrorBox						= document.createElement("div");
		objErrorBox.setAttribute('id','lightWinError');
		objBody.insertBefore(objErrorBox, objBody.nextSibling);

		// error message
		var objError						= document.createElement("p");
		objError.setAttribute('id','lightWinErrorMessage');
		objErrorBox.appendChild(objError);
		Event.observe(objError, "click", this.eventHide);

		// lightbox div
		var objLightbox						= document.createElement("div");
		objLightbox.setAttribute('id','lightWin');
		objLightbox.style.width = 'auto';
//		objLightbox.innerHTML = "<div id='lightWinClose'><img src='/Images/c.gif' onClick='lightWin.hide(event)' width=13 height=13 /></div><div id='lightWinTitle'></div><div id='lightWinContent'></div><div id='lightWinButtons'></div>";
		objLightbox.innerHTML = "<div id='lightWinTitle' style='width:auto'></div><div id='lightWinContent' style='width:auto'></div><div id='lightWinButtons' style='width:auto'></div>";
		objBody.insertBefore(objLightbox, objOverlay.nextSibling);

		// empty preloader
		var objPreload						= document.createElement("img");
		objPreload.setAttribute('id','lightWinPreload');
		objBody.insertBefore(objPreload, objBody.firstChild);
		
		var objPreloadFrame					= document.createElement("iframe");
		objPreloadFrame.setAttribute('id','lightWinPreloadFrame');
		objBody.insertBefore(objPreloadFrame, objBody.firstChild);

		this.eventKey = lightWin.handleKey.bindAsEventListener(lightWin);
		Event.observe(document, "keypress", this.eventKey);

	} // end init()
	
} // end lightWin

var greasedLanguage = {
	// Some of the translations here are very rough. If you can do better, please send me any changes (joe@shiftingpixel.com). I will be very happy.
	
	// english
	en : [
		{
			loading			: 'Loading...',
			loadingSub		: 'Click anywhere to cancel',
			error			: 'Content unavailable'
		}
	], // end english

	// francais
	fr : [
		{
			loading			: 'Chargement...',
			loadingSub		: 'Cliquez n\'importe où pour annuler',
			error			: 'Contenue indisponible'
		}
	], // end francais
	
	// language
	// the correct language for localization is set in init()
	language : 'en',
	
	// init()
	// sets this.language to the correct value based on navigator.language
	init : function() {
		if(navigator.language) { this.language = this[navigator.language.substring(0,2)] ? navigator.language.substring(0,2) : 'en'; }
	} // end init()

}; // end greasedLanguage
