var viewport = {
	o: function() {
		if (self.innerHeight) {
			this.pageYOffset = self.pageYOffset;
			this.pageXOffset = self.pageXOffset;
			this.innerHeight = self.innerHeight;
			this.innerWidth = self.innerWidth;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			this.pageYOffset = document.documentElement.scrollTop;
			this.pageXOffset = document.documentElement.scrollLeft;
			this.innerHeight = document.documentElement.clientHeight;
			this.innerWidth = document.documentElement.clientWidth;
    	} else if (document.body) {
			this.pageYOffset = document.body.scrollTop;
			this.pageXOffset = document.body.scrollLeft;
			this.innerHeight = document.body.clientHeight;
			this.innerWidth = document.body.clientWidth;
    	}
		return this;
	},
	init: function(el) {
		$(el).css("left",Math.round(viewport.o().innerWidth/2) + viewport.o().pageXOffset - Math.round($(el).width()/2));
		$(el).css("top",Math.round(viewport.o().innerHeight/2) + viewport.o().pageYOffset - Math.round($(el).height()/2));
	}
};
_lag = {
	pageHeight : null,
	pageWidth : null,
	popped : false,
	fadeout : false,
	target : null,
	temp : null,
	
	hover_box : function(target,fadeout) {
		
		if(_lag.popped == true) {
			$(_lag.target).html(_lag.temp);
		}
						
		_lag.target = target;
		_lag.fadeout = fadeout;
		
		if (typeof document.body.style.maxHeight === "undefined") { //if IE 6
			$("body","html").css({height: "100%", width: "100%"});
		}
		
		if(_lag.popped == false) {
			$('#modal-overlay').css({'opacity' : '0.25', 'display' : 'block'});
			$('#hover_box').css({'display' : 'none', 'width' : 'auto', 'height' : 'auto'});
		}
		
		_lag.getPageHeightWidth();
			
		$('#hover_box').css({
			'display' : 'block',
			'max-width' : '500px'
			});
			
		$('#hover_box .content').css({
			'background-color' : '#FFFFFF',
			'padding' : '20px'
			}).html($(_lag.target).html());
			
		_lag.temp = $(_lag.target).html();
		$(_lag.target).html('');
			
		if($('#hover_box').width() > 500) {
			$('#hover_box').css({'width' : '500px'});
		}
					
		$('#hover_box .right').css({
			'height' : $('#hover_box').height()-12
			});
		$('#hover_box .bottom').css({
			'width' : $('#hover_box').width()-12
			});
		
		if(_lag.fadeout == true) { 
			$('#hover_box').fadeOut(3000);
		}
		
		$('#modal-overlay').click(function() {
			$(_lag.target).html(_lag.temp);
			$('#hover_box').css({'display' : 'none'});
			$('#modal-overlay').css({'display' : 'none'});
			_lag.popped = false;
		});
		viewport.init($('#hover_box'));
		_lag.popped = true;
	},
	getPageHeightWidth : function() {
		_lag.pageHeight = (self.innerHeight) ? self.innerHeight : (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
		_lag.pageWidth = (self.innerWidth) ? self.innerWidth : (document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth;
	}
}
