if(typeof ss == 'undefined') {
	ss = {};
}

ss.Popup = Class.create({
	modal: null,
	content: null,
	innerContent: null,
	title: null,
	scrollOff: null,
	
	showing: false,

	initialize: function() {
		var modal = $(document.createElement('div'));
		modal.addClassName('modal');	
		modal.setOpacity(.5);			
		modal.hide();
		document.body.appendChild(modal);
		
		var content = $(document.createElement('div'));
		content.addClassName('modalContent');		
		var title = $(document.createElement('div'));
		title.addClassName('title');
		content.appendChild(title);
		this.title = title;
		ndiv = $(document.createElement('div'));
		ndiv.addClassName('content');
		content.appendChild(ndiv);
		this.innerContent = content;
		this.content = content;
		content.hide();
		document.body.appendChild(content);
		
		this.modal = modal;
	},
	
	modalFullscreen: function() {
		var dim = document.viewport.getDimensions();
		this.modal.setStyle({height:dim.height+'px',
						width:dim.width+'px'});
	},
	
	// Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
	prepareIE: function(overflow){
		bod = document.getElementsByTagName('body')[0];
		bod.style.overflow = overflow;
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.overflow = overflow; 
	},
	saveScroll:function() {
		this.scrollOff = document.viewport.getScrollOffsets();
	},
	returnScroll: function() {
		this.setScroll(this.scrollOff.left,this.scrollOff.top)
	},
	setScroll: function(left,top) {
		window.scrollTo(left,top);
	},
	
	setContent: function(dom) {
		this.innerContent.appendChild(dom);
	},
	setTitle: function(title) {
		this.title.innerHTML = title;
	},
	
	show: function() {
		if(this.showing)
			return false;
		
		this.saveScroll();
		this.setScroll(0,0);
		//this.prepareIE('hidden');
		this.modalFullscreen();
		
		this.modal.show();
		this.content.show();
		this.showing = true;
	},
	
	hide: function() {
		if(!this.showing)
			return false;
		
		//this.prepareIE('auto');
		this.returnScroll();
		
		this.modal.hide();
		this.content.hide();
		this.showing = false;
	},
	
	remove: function() {
		this.hide();
		document.body.removeChild(this.modal);
		document.body.removeChild(this.content);
	}
});

