function ilDisplay(sTitle, sMessage, iW, iH, iT, iL, bFade)
{
	if (!iW) {
		iW = 300;
	}
	if (!iH) {
		iH = 200;
	}

	$('#ilInline, #ilInlineBG').remove();
	if (!$('#ilInline').length)
	{
		$('body').prepend('<div id="ilInline"><div class="ilTitle"><div class="ilClose"></div><div class="ilTitleText">'+sTitle+'</div></div><div class="ilContent">'+sMessage+'</div></div>');
		$('#ilInline .ilTitle .ilClose').click(function(){
			$('#ilInlineBG').fadeOut();
			$('#ilInline').slideUp();
			return false;
		});
	}
	if (!$('#ilInlineBG').length)
	{
		$('body').prepend('<div id="ilInlineBG"></div>');
		$('#ilInlineBG').css('margin-top', '-'+$('body').css('margin-top')).css('margin-left', '-'+$('body').css('margin-left'));
	}

	$('#ilInline').width(iW + (parseInt($('#ilInline .ilContent').css('padding').replace(/px$/, '')) * 2)).height(iH + (parseInt($('#ilInline .ilContent').css('padding').replace(/px$/, '')) * 2) + (parseInt($('#ilInline .ilTitle').css('height').replace(/px$/, ''))));
	$('#ilInline .ilContent').width(parseInt(iW)).height(parseInt(iH));
	if (!iT) {
		iT = ($(window).height() / 2) - (iH / 2) - ($('#ilInline .ilTitle').height() / 2);
	}
	if (!iL)
	{
		iL = ($(window).width() / 2) - (iW / 2);
	}
	iT = Math.round(iT);
	iL = Math.round(iL);
	if (bFade)
	{
		if ($.browser.msie) {
			$('#ilInlineBG').fadeIn(function() {
				$(this).css('filter','alpha(opacity='+$(this).css('alpha')+')');
			});
		}
		else {
			$('#ilInlineBG').fadeIn();
		}
	}
	$('#ilInline').css({
		'top':iT+'px',
		'left':iL+'px'
	}).slideDown();
	return false;
}

function _hookPopUps()
{
	$('*[popup]').unbind('click').click(function(){
		link = this;
		eval("popup = {"+$(link).attr('popup')+"};");
		if (
			(!popup.widget)
			&& (!popup.iframe)
			&& (!popup.proxy)
		)
		{
			alert('No widget/iframe specified for the popup.');
		}
		else
		{
			if ((!popup.title) && (popup.widget))
			{
				popup.title = popup.widget.replace(/_/g, ' ');
			}
			if (popup.size)
			{
				switch(popup.size)
				{
					case 'player':
						popup.width = 480;
						popup.height = 290;
						break;
					case 'brochure':
						popup.width = 720;
						popup.height = 480;
						break;
					case 'page':
						popup.width = 1000;
						popup.height = 600;
						break;
					default:
						popup.width = 640;
						popup.height = 480;
				}
			}
			if (popup.widget) {
				if (popup.gvars) {
					gvars = popup.gvars.replace(/^\?/, '');
					lurl = 'http://bzdo.tv/view/teamklipz/_bizits/ilpopup/ajaxp.php?w='+popup.widget+'&'+gvars+'&cb=?'
				}
				else {
					lurl = 'http://bzdo.tv/view/teamklipz/_bizits/ilpopup/ajaxp.php?w='+popup.widget+'&cb=?';
				}
				$.getJSON(lurl, function(data) {
					ilDisplay(popup.title, data.content, popup.width, popup.height, popup.top, popup.left, popup.fade);
				});
			}
			else if (popup.proxy) {
				$.get('../_bizits/ilpopup/proxy.php?'+escape(popup.proxy), function(html) {
					// TODO: Remove this line once JM creates new pages
					html += '<link rel="stylesheet" type="text/css" href="http://www.teamklipz.com/deps/pages.css" />';
					ilDisplay(popup.title, html, popup.width, popup.height, popup.top, popup.left, popup.fade);
				}, 'html');
			}
			else if (popup.iframe) {
				ilDisplay(popup.title, '<iframe frameborder="0" border="0" src="'+popup.iframe+'" width="'+(popup.width+15)+'" height="'+(popup.height+15)+'" style="margin: -10px;"></iframe>', popup.width, popup.height, popup.top, popup.left, popup.fade);
			}
		}
		return false;
	});
}


$(document).ready(function(){
	_hookPopUps();
})
