//[of]:<< detect browser >>
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
//[c]
//Browser detect script originally created by Peter Paul Koch at http://www.quirksmode.org/
function getBrowserInfo() {
	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari'))  browser = "Safari";
	else if (checkIt('omniweb')) browser = "OmniWeb";
	else if (checkIt('opera'))   browser = "Opera";
	else if (checkIt('webtv'))   browser = "WebTV";
	else if (checkIt('icab'))    browser = "iCab";
	else if (checkIt('msie'))    browser = "Internet Explorer";
	else if (!checkIt('compatible')) {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS) {
		if (checkIt('linux'))    OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac";
		else if (checkIt('win')) OS = "Windows";
		else OS 					= "an unknown operating system";
	}
}

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
//[cf]
//[of]:Lightbox
var Lightbox = {
	config: {
		throbber_image  : 'images/lb/loading.gif',
		close_icon_image: 'images/lb/close.png',
		close_icon_style: 'width:12px;height:12px;cursor:pointer'
	},
	active: false,
	yPos: 0,
	xPos: 0,
//[c]	
//[of]:	initialize
	initialize: function() {
//[c]		Add in markup necessary to make this work. Basically two divs:
//[c]		Overlay holds the shadow
//[c]		Lightbox is the centered square that the content is put into.
		config = Lightbox.config;
		body = document.getElementsByTagName('body')[0];
		overlay = document.createElement('div');
		overlay.id = 'overlay';
		lbox = document.createElement('div');
		lbox.id = 'lightbox';
		lbox.className = 'loading';
		lbox.innerHTML =
			'<table border="0" cellpadding="0" cellspacing="0" width="100%">' +
			'<tr><td id="lbTitle" width="100%">&nbsp;</td>' +
			'<td style="background-color:#F1F3F5">' +
			'<img src="'+config.close_icon_image+'" border="0" style="'+config.close_icon_style+'" alt="Close" hspace="4" class="mylb-action" rel="deactivate" />' +
			'</td></tr></table>' +
			'<div id="lbContent"></div>' +
			'<div id="lbLoadMessage"><div style="background-color:#FFF8EF;padding:10px"><img src="'+config.throbber_image+'" /><br /><br />&nbsp;&nbsp;Loading...</div></div>';
		body.appendChild(overlay);
		body.appendChild(lbox);
		Lightbox.overlay = overlay;
		Lightbox.element = lbox;
		Lightbox.content = $('lbContent');
		conts = document.getElementsByClassName('lbtrigger-loading');
		for (i = 0; i < conts.length; i++)
			conts[i].style.display = 'none';
		conts = document.getElementsByClassName('lbtrigger-container');
		for (i = 0; i < conts.length; i++)
			conts[i].style.display = 'block';
	},
//[cf]
//[of]:	activate
	activate: function(evnt) {
		if (Lightbox.active) return;
		elem = Event.element(evnt);
		
		with (Lightbox) {
			if (browser == 'Internet Explorer') {
				getScroll();
				prepareIE('100%', 'hidden');
				setScroll(0,0);
				hideElems('select', 'hidden');
				hideElems('applet', 'hidden');
			}
			
			display('block', elem.getAttribute('href'));
			active = true;
		}
	},
//[cf]
//[of]:	deactivate
	deactivate: function() {
		with (Lightbox) {
			if (browser == "Internet Explorer") {
				setScroll(0, Lightbox.yPos);
				prepareIE("auto", "auto");
				hideElems('select', "visible");
				hideElems('applet', "visible");
			}
			display('none');
			active = false;
		}
	},
//[cf]
//[of]:	action
	action: function(evnt) {
		elem = Event.element(evnt);
		hndr = this[elem.getAttribute('rel')];
		if(hndr) hndr(evnt);
	},
//[cf]
//[of]:	insert
	insert: function(evnt) {
		elem = Event.element(evnt);
		try {
			url = elem.getAttribute('href') || elem.form.getAttribute('action');
		} catch (err) { return; }
		Lightbox.loadInfo(url, elem.form);
	},
//[cf]
//[of]:	display

	display: function(disp, url) {
		Lightbox.overlay.style.display = disp;
		with (Lightbox.element) {
			style.display = disp;
			className = 'loading';
		}
		if (disp != 'none') Lightbox.loadInfo(url);
	},
//[cf]
//[of]:	loadInfo
	loadInfo: function(url, form) {
		Lightbox.element.className = 'loading';
		res = new Ajax.Request(
			url, {
			method: 'POST',
			parameters: form ? Form.serialize(form.id) : '',
			onComplete: Lightbox.processInfo
			});
	},
//[cf]
//[of]:	processInfo
	processInfo: function(response) {
		with (Lightbox) {
			content.innerHTML = response.responseText;
			element.className = 'done';
		}
	},
//[cf]
//[c]
//[of]:	getScroll
	getScroll: function() {
		if (self.pageYOffset) {
			Lightbox.yPos = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){
			Lightbox.yPos = document.documentElement.scrollTop; 
		} else if (document.body) {
			Lightbox.yPos = document.body.scrollTop;
		}
	},
//[cf]
//[of]:	prepareIE
	prepareIE: function(height, overflow) {
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		bod.style.overflow = overflow;
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		htm.style.overflow = overflow; 
	},
//[cf]
//[of]:	setScroll
	setScroll: function(x, y) {
		window.scrollTo(x, y);
	},
//[cf]
//[of]:	hideElems
	hideElems: function(tagName, visibility) {
		elems = document.getElementsByTagName(tagName);
		for (i = 0; i < elems.length; i++) {
			elems[i].style.visibility = visibility;
		}
	},
//[cf]
//[of]:	set_title
	set_title: function(title) {
		$('lbTitle').innerHTML = title;
	}
//[cf]
}
//[cf]
//[c]
Event.observe(document, 'click', function(evnt) {
	elem = Event.element(evnt);
	handled = true;
	
	if (Element.hasClassName(elem, 'mylb-on'))
		Lightbox.activate(evnt);
	else
	if (Element.hasClassName(elem, 'mylb-action'))
		Lightbox.action(evnt);
	else
		handled = false;
	
	if (handled) {
		Event.stop(evnt);
		
		if (elem.tagName == 'A') elem.onclick = function() { return false; }
/*		else
		if (elem.tagName == 'INPUT') elem.form.onsubmit = function() { return false; }
*/	}
}, false);
//[c]
Event.observe(window, 'load', getBrowserInfo, false);
Event.observe(window, 'unload', Event.unloadCache, false);
