function openSharingBox(url)
{
	Lightbox.open({
		title: __['share-with-fds'],
		url: url,
		height: 500
	});
}

function openEnquiryBox(url)
{
	Lightbox.open({
		title: __['enquiry'],
		url: url,
		height: 500
	});
}

function openEmailAgentBox(url)
{
	Lightbox.open({
		title: __['email-this-agent'],
		url: url,
		height: 300
	});
}

function openReferAgentBox(url)
{
	Lightbox.open({
		title: __['refer-this-agent'],
		url: url,
		height: 300
	});
}

function openSubscribeEmBox(url)
{
	Lightbox.open({
		title: __['subscribe-em'],
		url: url,
		height: 320
	});
}

function openAdvEnquiryBox(url)
{
	Lightbox.open({
		title: __['adv-enquiry'],
		url: url,
		height: 320
	});
}

var Lightbox =
{
	config: {
		title: '',
		width: 515,
		height: 495
	},
	html: '<div id="lightbox"><div class="close-btn"></div><div class="lightbox-top"></div><div class="lightbox-content"><div class="iframe-wrapper"><iframe frameborder="0"></iframe></div></div><div class="lightbox-btm"></div></div>',
	
	init: function (config)
	{
		if (typeof config == 'object')
		{
			if (config.title)
				this.config.title = config.title;
			
			if (config.width)
				this.config.width = config.width;
				
			if (config.height)
				this.config.height = config.height;
				
			this.config.url = config.url;
		}
		
		$('body > #lightbox').remove();
		$('body').append(this.html);
		
		this.obj = $('body > #lightbox');
		this.obj.children('.lightbox-content').css({
			width: this.config.width,
			height: this.config.height
		});
		this.obj.children('.close-btn').click($.proxy(this.close, this));
		$(window).resize($.proxy(this.centering, this));
		
		if (this.config.title)
			this.obj.children('.lightbox-top').html(this.config.title);
		
		this.pngFix();
		this.centering();
	},
	
	// pngFix for IE 6
	pngFix: function()
	{
		if (navigator.userAgent.indexOf('MSIE 6') != -1)
		{
			this.obj.find('.lightbox-top, .lightbox-content, .lightbox-btm').each(function () {
				// e.g. url("http://dev.www.hongkonghomes.com/v2/lang/en/images/common/lightbox_top.png")
				var bg_img = $(this).css('background-image');
				bg_img = bg_img.substring(5, bg_img.length - 2);
				
				this.style.background = 'none';
				this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+bg_img+"', sizingMethod='scale')";
			});
		}
	},
	
	centering: function ()
	{
		var win_w = $(window).width();
		var win_h = $(window).height();
		
		var me_w = this.obj.width();
		var me_h = this.obj.height();
		
		var w = win_w/2 - me_w/2;
		var h = win_h/2 - me_h/2;
		
		if (w < 50)
			w = 50;
		if (h < 50)
			h = 50;
		
		var scroll_top = $(window).scrollTop();
		h += scroll_top;
		
		this.obj.css({
			top: h,
			left: w
		});
	},
	
	open: function (config)
	{
		this.init(config);
		
		this.obj.find('.lightbox-content iframe')
			.attr('src', this.config.url)
			.css({
				width: this.config.width - 19 - 19,
				height: this.config.height
			})
		;
	},
	
	// show: function ()
	// {
		// this.obj.show();
	// },
	
	close: function ()
	{
		this.obj.hide();
	}
};

