/*
-- Webinar Overlay v0.2 --
by Andrew Murphy - 2010/10/26
copyright Delvinia Interactive Inc. - 2010
http://www.delvinia.com/
Requires jQuery v1.4.1
*/

// Initialization
//
// called when the user clicks on the webinar banner
function openWebinar(overlay_url)
{
	// determine where to position the overlay vertically so that
	// it's vertically centered within the visible area shown of the page
	// keeping it just below the top of the page
	var overlay_height = 570;
	var page_height = f_clientHeight();
	var page_scroll = f_scrollTop();
	var top = Math.floor((page_height - overlay_height) / 2);
	if(top < 0)
	{
		top = 10;
	}
	
	// add the overlay's elements to the page
	$("body").append(
		"<div id='webinar-overlay-bg'>" +
		"</div>" +
		"<div id='webinar-overlay-vert' style='top: " + top + "px;'>" +
			"<div id='webinar-overlay'>" +
				"<div id='webinar-overlay-close'>" +
					"<a href='#' onclick='JavaScript:removeWebinarOverlay();'><img src='/caa/webinar_overlay/close.jpg' width='22' height='22' border='0' alt='CLOSE' title='CLOSE'></a>" +
				"</div>" +
				"<iframe id='webinar-iframe' src=\"" + overlay_url + "\" frameBorder='0'></iframe>" +
			"</div>" + 
		"</div>"
	);
}

// determining the browser's height and vertical scroll position
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

// called when the user clicks to remove the overlay
function removeWebinarOverlay()
{
	$("#webinar-overlay-bg").remove();
	$("#webinar-overlay-vert").remove();
}


