// common.js: scripts common to all pages on the website

<!--#include virtual="/include/Patron.js" -->
<!--#include virtual="/include/PandoraAPIv2.js" -->

/*@cc_on@*/

/*@if (@_jscript_version >= 5.5) @*/
<!--#include virtual="/include/3rd-party/jquery/jquery.js" -->
<!--#include virtual="/include/3rd-party/jquery/dimensions.js" -->
<!--#include virtual="/include/menuManager.js" -->
/*@end@*/


function showPopupMenu(strPopupContainerID)
{
	var jqBody = $(document.body);
	var jqPopupContainer = $('#' + strPopupContainerID);
	
	//would be nice if jquery had a 'isVisible' property...
	if (jqPopupContainer.css("display") != "block")
	{	//if the menu is not already visible, show it and listen for click events to hide it
		jqPopupContainer.show();
	
	       	var function_hideMenu;
	       	function_hideMenu = function() 
		{
			if (!jqPopupContainer.pastFirstHideCall)
			{	//ignore the first click event - it's just this same call
				//bubbled up.  A better way to do this would be to cancel 
				//bubble on the event.
				//TODO:  determine if all of our supported browsers support 'cancelBubble'
				jqPopupContainer.pastFirstHideCall = true;
			}
			else
			{
				jqPopupContainer.pastFirstHideCall = false;
				jqBody.unbind("click", function_hideMenu);
	
				jqPopupContainer.hide();
			}
		};
		
		jqBody.bind("click", function_hideMenu);
	}

	return jqPopupContainer;
}

function isEmpty(value) {
	return value == null || value == "" || value == "null";
}

function getDiv(divID) {
	if( document.getElementById ) {
		// standard (IE 5+)
		return document.getElementById(divID);
	} else {
		// IE 4
		return document.all[divID];
	}
}

// This script is required to properly display png transparency on IE 6 and 5.5
var bgsleight	= function() {
	function fnLoadPngs() {
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
		for (var i = document.all.length - 1, obj = null; (obj = document.all[i]); i--) {
			if (itsAllGood && obj.currentStyle.backgroundImage.match(/\.png/i) != null) {
				fnFixPng(obj);
				obj.attachEvent("onpropertychange", fnPropertyChanged);
			}
		}
	}

	function fnPropertyChanged() {
		if (window.event.propertyName == "style.backgroundImage") {
			var el = window.event.srcElement;
			if (!el.currentStyle.backgroundImage.match(/x\.gif/i)) {
				var bg	= el.currentStyle.backgroundImage;
				var src = bg.substring(5,bg.length-2);
				el.filters.item(0).src = src;
				el.style.backgroundImage = "url(/images/clearspacer.gif)";
			}
		}
	}

	function fnFixPng(obj) {
		var bg	= obj.currentStyle.backgroundImage;
		var src = bg.substring(5,bg.length-2);
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='crop')";
		obj.style.backgroundImage = "url(/images/clearspacer.gif)";
	}

	return {
		init: function() {
			if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
				window.attachEvent("onload", fnLoadPngs);
			}
		}
	}
}();
bgsleight.init();

function fireComscoreBeacon() {
    COMSCORE.beacon({
     c1:2,
     c2:"6036333",
     c3:"",
     c4:escape(document.location.href),
     c5:"",
     c6:"",
     c15:""
    });
}

/**
 * Binds an object and a function into a single callback delegate.
 * @param caller the object to bind "this" inside of the bound method
 * @param method the methd to bind to the object
 * @return a bound delegate method
 */
function bind(/*Object*/ caller, /*Function*/ method) {
	return function() {
		return method.apply(caller, arguments);
	}
}

/**
 * Binds an object and a method for callback in a specific number of milliseconds.
 */
function bindTimeout(thisObj, method, elapse) {
	return setTimeout(bind(thisObj, method), elapse);
}
function bindInterval(thisObj, method, interval) {
	return setInterval(bind(thisObj, method), interval);
}

