var mlightbox = Class.create();
mlightbox.prototype = {

	yPos : 0,
	xPos : 0,

	initialize: function() {
	},

	activate: function(){
		if (browser == 'Internet Explorer'){
			this.getScroll();
			this.prepareIE('100%', 'hidden');
			this.setScroll(0,0);
			this.hideSelects('hidden');
		}
		this.displayLightbox("block");
	},
	
	// Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
	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; 
	},
	
	// In IE, select elements hover on top of the lightbox
	hideSelects: function(visibility){
		selects = document.getElementsByTagName('select');
		for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = visibility;
		}
	},
	
	// Taken from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
	getScroll: function(){
		if (self.pageYOffset) {
			this.yPos = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){
			this.yPos = document.documentElement.scrollTop; 
		} else if (document.body) {
			this.yPos = document.body.scrollTop;
		}
	},
	
	setScroll: function(x, y){
		window.scrollTo(x, y); 
	},
	
	displayLightbox: function(display){
		$('overlay').style.display = display;
		$('mlightbox').style.display = display;
	},
	
	// Display Ajax response
	show_content: function(content){
		this.activate();
		info = "<div id='mlbContent'>" + content + "</div>";
		new Insertion.Before($('mlbLoadMessage'), info)
		$('mlightbox').className = "done";
		this.actions();
	},
	
	// Search through new links within the lightbox, and attach click event
	actions: function(){
		lbActions = document.getElementsByClassName('lbAction');

		for(i = 0; i < lbActions.length; i++) {
			Event.observe(lbActions[i], 'click', this[lbActions[i].rel].bindAsEventListener(this));
			lbActions[i].onclick = function(){return false;};
		}

	},


        // Example of creating your own functionality once lightbox is initiated
        deactivate: function(){
                Element.remove($('mlbContent'));

                if (browser == "Internet Explorer"){
                        this.setScroll(0,this.yPos);
                        this.prepareIE("auto", "auto");
                        this.hideSelects("visible");
                }

                this.displayLightbox("none");
        }
}
var _lb_control = new mlightbox();
function set_lb_content(content) {
try {
        Element.remove($('mlbContent'));
} catch (ex) {
}
	_lb_control.show_content(content);
}

