/************ LIGHTBOX EFFECT **************/

function lightboxCreate (w, h, title) {
	if (typeof w == 'undefined') var w = 400;
	if (typeof h == 'undefined') var h = 224;
	if (typeof title == 'undefined') var title = '';
	var lb, html = '', pad = 5;
	lightboxClose();
	html += '<div id="lb-dimmer" onclick="lightboxClose();" style="background-color: #222; zoom: 1; opacity: 0.5; -moz-opacity: 0.5; -khtml-opacity: 0.5; filter: alpha(opacity=50); position: absolute; z-index: 9999998; left: 0; top: 0; width: '+document.body.scrollWidth+'px; height: '+document.body.scrollHeight+'px;"></div><div id="lb-dialog" style="background-color: #900; text-align: left; font-size: 120%; position: absolute; z-index: 9999999; left: 100px; top: 100px; width: '+w+'px; padding: '+pad+'px;"><p style="padding: 0 5px; margin: 0 0 5px 0; color: #FFF;"><a href="javascript:void(lightboxClose());" style="float: right; color: #FFF; margin-left: 1em;"><b>Close</b></a>'+title+'&nbsp;</p><div id="lb-content"></div></div>';
	lb = document.createElement('DIV');
	lb.id = 'lightbox';
	lb.innerHTML = html;
	document.body.appendChild(lb);
	lightboxPos(w, h, pad);
	onscroll = function () { eval('lightboxPos('+w+', '+h+', '+pad+');') };
	return document.getElementById('lb-content');
}

function lightboxPos (w, h, pad) {
	var lbd, d;
	d = (typeof document.documentElement != 'undefined' ? document.documentElement : document.body);
	if (lbd = document.getElementById('lb-dialog')) {
		var x, y;
		x = (typeof d.scrollLeft != 'undefined' ? d.scrollLeft : window.pageXOffset) + (typeof d.clientWidth != 'undefined' ? d.clientWidth : window.innerWidth)/2 - w/2 - pad;
		y = (typeof d.scrollTop != 'undefined' ? d.scrollTop : window.pageYOffset) + (typeof d.clientHeight != 'undefined' ? d.clientHeight : window.innerHeight)/2 - h/2 - pad;
		lbd.style.left = x+'px';
		lbd.style.top = y+'px';
	}
}

function lightboxClose () {
	var lb;
	if (lb = document.getElementById('lightbox')) lb.parentNode.removeChild(lb);
	onscroll = function () {};
	if (typeof nowPlaying != 'undefined') delete nowPlaying;
}

if (document.referrer.match(/(google|yahoo|live|search|q=)/)) {
	onload = function () {
		var lbc = lightboxCreate(500, 250, 'Looking for coverage of the Beijing 2008 Olympics?');
		var html = '';
		html += '<div style="background-color: white; padding: 20px 20px 10px 20px;"><a href="/olympics/">Go to our <strong>Beijing 2008</strong> Olympics site</a></div>';
		html += '<div style="background-color: white; padding: 10px 20px 20px 20px;"><a href="javascript:void(0);" onclick="lightboxClose();">Stay on our <strong>Athens 2004</strong> Olympics site</a></div>';
		lbc.innerHTML = html;
	}
}
