var SFBLightBox = function(){}

SFBLightBox.prototype.init = function(){
	
	this.$overlay = $('<div class="lb2_overlay">&nbsp;</div>').hide().fadeTo(0,0);
	
	this.$lightBox = $('<table class="lb2" cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td valign="top" class="lb2_tl" width="9px" height="10px"><span class="lb2_spacer">a</span></td><td valign="top" class="lb2_top" height="10px"><span class="lb2_spacer">a</span></td><td valign="top" class="lb2_tr" width="9px" height="10px"><span class="lb2_spacer">a</span></td></tr><tr><td valign="top" class="lb2_left" width="9px"><span class="lb2_spacer">a</span></td><td valign="top" class="lb2_content" id="lb2_content"></td><td valign="top" class="lb2_right" width="9px"><span class="lb2_spacer">a</span></td></tr><tr><td valign="top" class="lb2_bl" width="9px" height="10px"><span class="lb2_spacer">a</span></td><td valign="top" class="lb2_bottom"><span class="lb2_spacer">a</span></td><td valign="top" class="lb2_br" width="9px" height="10px"><span class="lb2_spacer">a</span></td></tr></table>').hide();
	
	$('body').append(this.$overlay).append(this.$lightBox);
	
	this.$lightBoxContent = $('#lb2_content');
	
	this.isIE = $.browser.msie;
	
}

SFBLightBox.prototype.show = function(selector){
	
	var ref = this;
	
	this.$elem = $(selector).show();
	
	this.$lightBox.show()
	
	if(!$.browser.msie){
		this.$lightBox.css('opacity', 0);
	}
	
	var width = parseInt(this.$elem.outerWidth());
	var height = parseInt(this.$elem.outerHeight());
	var tableWidth = width + 18;
	
	var marginTop = -(height * 0.5);
	var marginLeft = -(width * 0.5);
	
	var css = {
		top: '50%',
		left: '50%',
		marginTop: marginTop,
		marginLeft: marginLeft
	}
	
	this.$lightBox.attr('width', tableWidth).css(css);
	
	this.$lightBoxContent.html(this.$elem.show().append('<a class="pop_up_close_btn_x" href="#">x</a><a class="pop_up_close_btn" href="#">Close</a>'));
	
	this.$lightBoxContent.attr('width', width);
	
	var $document = $(document);
	
	$(window).bind('resize', function(){
		
		var css = {
			width: $document.width(),
			height: $document.height()
		}
		
		ref.$overlay.css(css);
		
	});
	
	var css = {
		width: $document.width(),
		height: $document.height(),
		display: 'block'
	}
	
	this.$overlay.css(css).stop().fadeTo(300, 0.4).bind("click", function(){ref.hide();});											 
	
	setTimeout(function(){
		
		if(ref.isIE){
			ref.$lightBox.show();
		}
		else{
			ref.$lightBox.stop().fadeTo(300, 1); 
		}
		
	}, 200);
	
	/* Assign the close click actions */
	
	this.$elem.find('.pop_up_close_btn_x, .pop_up_close_btn').click(function(){
		ref.hide();
	});
	
}

SFBLightBox.prototype.hide = function(){
	
	var ref = this;
	
	this.$lightBox.hide();
	
	this.$elem.find("a.pop_up_close_btn, a.pop_up_close_btn_x").remove();
	
	$('body').append(this.$elem.hide());
	$('body').unbind('resize');
	
	this.$overlay.fadeTo(300, 0, function(){
		ref.$overlay.hide().unbind('click');
	});
		
}
