


function _Util(){}
_Util.prototype.makeBlockAnchor = function(item){
    var firstAnchor = $(item).find("a").get(0);
    if(firstAnchor == null || firstAnchor.href == null){ return null; }
    if(item._doneMakeBlockAnchor != null){ return firstAnchor; }	// only do it once
    var href = firstAnchor.href;
    if(href.length >= 11 && href.substring(0, 11).toLowerCase() == "javascript:"){
		href = href.substring(11, href.length);
		eval("item.onclick = function(){ " + href + "; };");
    }else{
		item.onclick = function(){ document.location = firstAnchor.href; };
    }
    item._doneMakeBlockAnchor = true;
    return firstAnchor;     // return the anchor if successful
}
_Util.prototype.getRandom = function(){
    return (Math.random() + "") * 1000000000000000000;
}
_Util.prototype.concatUrls = function(url1, url2){
    if (this.stringEndsWith(url1, "/")){ url1 = url1.substr(0, url1.length - 1); }a
	if (!this.stringBeginsWith(url2, "/")){ url2 = "/" + url2; }
	return url1 + url2;
}
_Util.prototype.stringBeginsWith = function(text, partial){
	if(text == null || partial == null || text == "" || partial == ""){ return false; }
	if(text.length < partial.length){ return false; }
	return (text.substr(0, partial.length) == partial);
}
_Util.prototype.stringEndsWith = function(text, partial){
	if(text == null || partial == null || text == "" || partial == ""){ return false; }
	if(text.length < partial.length){ return false; }
	return (text.substr(text.length - partial.length, text.length) == partial);
}
_Util.prototype.getElementPosition = function(element) {
	if(element == null) return null;
    var result = new Object();
    result.x = 0;
    result.y = 0;
    result.width = 0;
    result.height = 0;
    if (element.offsetParent) {
        result.x = element.offsetLeft;
        result.y = element.offsetTop;
        var parent = element.offsetParent;
        while (parent) {
            result.x += parent.offsetLeft;
            result.y += parent.offsetTop;
            var parentTagName = parent.tagName.toLowerCase();
            if (parentTagName != "table" &&
                parentTagName != "body" && 
                parentTagName != "html" && 
                parentTagName != "div" && 
                parent.clientTop && 
                parent.clientLeft) {
                result.x += parent.clientLeft;
                result.y += parent.clientTop;
            }
            parent = parent.offsetParent;
        }
    }
    else if (element.left && element.top) {
        result.x = element.left;
        result.y = element.top;
    }
    else {
        if (element.x) {
            result.x = element.x;
        }
        if (element.y) {
            result.y = element.y;
        }
    }
    if (element.offsetWidth && element.offsetHeight) {
        result.width = element.offsetWidth;
        result.height = element.offsetHeight;
    }
    else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
        result.width = element.style.pixelWidth;
        result.height = element.style.pixelHeight;
    }
    return result;
}
_Util.prototype.setElementHeight = function(element, height) {
    if (element && element.style) {
        element.style.height = height + "px";
    }
}
_Util.prototype.setElementWidth = function(element, width) {
    if (element && element.style) {
        element.style.width = width + "px";
    }
}
_Util.prototype.setElementX = function(element, x) {
    if (element && element.style) {
        element.style.left = x + "px";
    }
}
_Util.prototype.setElementY = function(element, y) {
    if (element && element.style) {
        element.style.top = y + "px";
    }
}
_Util.prototype.getIsIntEng = function() {
	var language = navigator.userLanguage;
	if(language == null){ return false; }
	language = language.toLowerCase();
	if(language == "en-au"){ return true; }
	if(language == "en-gb"){ return true; }
	if(language == "en-ie"){ return true; }
	return false;
}
_Util.prototype.trim = function(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
_Util.prototype.ltrim = function(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
_Util.prototype.rtrim = function(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
var Util = new _Util();


function _XmlTools(){}
_XmlTools.prototype.getXmlObject = function(xmlString){
    var xmlObject = null;
	if (window.ActiveXObject){
		//parses the XML for IE browsers
		xmlObject = new ActiveXObject("Microsoft.XMLDOM");
		xmlObject.async = false;
		xmlObject.loadXML(xmlString); //parses the XML for IE browsers
	}else if (window.XMLHttpRequest){
		xmlObject = (new DOMParser()).parseFromString(xmlString, "text/xml"); //parses the XML for Mozilla browsers
	}
	return xmlObject;
}
_XmlTools.prototype.getTagInnerValue = function(element, tagName, defaultValue){
    if(defaultValue == null){ defaultValue = ""; }
    var subElements = element.getElementsByTagName(tagName);
    if(!subElements || subElements.length == 0){ return defaultValue; }
    if(subElements[0].firstChild == null){ return defaultValue; }
    return subElements[0].firstChild.nodeValue;
}
_XmlTools.prototype.getFirstElement = function(element, tagName){
    var elements = element.getElementsByTagName(tagName);
    if(!elements || elements.length == 0){ return null; }
    return elements[0];
}
var XmlTools = new _XmlTools();




// javascript object to encapsulate common page functionality
//
function PageController(){
	this._idCounter = -1;
	// config
	this.isEditMode = false;
    this.searchUrlFormat = '/WebApplications/BetSearch/Search.aspx?searchType=bet&c=all&searchQuery={0}';
    this.enableAds = true;
    this.enableAdsPlaceholder = true;
    this.enableOmniture = true;
    this.enableFlash = true;
    this.coAd=false;
    this.enableFlashPlaceholder = true;
    this.s = null;
    this.baseDartTarget = null;
    this.useInterstitial = true;
    this.currentDateKey = null;   
    this.coAdServeCount = -1;  // specified in ThemeController.  if specified, the key will be passed into flash to allow time sensitive changes.
    
    //register all the possible control layouts
    this.layoutManager = new LayoutManager();
	this.layoutManager.registerLayout({
	
		name : 'threeColumn', 
		layout : new ColumnLayout({        
			columns : [                
				{
					width: 310
				},
	            
				{
					width: 310                    
				},
	            
				{
					width: 300
				}
			],
			spans : [                
				{                    
					//column the span starts at
					start : 0,
					//number of columns it spans
					span : 1,
					//css class used the designate this span
					css : 'oneThirdColLeft'
				},
	            
				{                    
					start : 1,
					span : 1,
					css : 'oneThirdColMiddle'
				},
	            
				{                    
					start : 2,
					span : 1,
					css : 'oneThirdColRight'
				},
	            
				{
					start : 0,
					span : 2,
					css : 'twoThirdsColLeft'
				},
	            
				{
					start : 1,
					span : 2,
					css : 'twoThirdsColRight'
				},
				{
					start : 0,
					span : 3,
					css : 'fullCol'
				}                
			]        
		})
	});
    
    this.layoutManager.registerLayout({
    
		name : 'fourColumn',
		layout : new ColumnLayout({            
			columns : [                
				{
					width: 186
				},
				{
					width: 287
				},
				{
					width: 287
				},
				{
					width: 160
				}
			],        
			spans : [
				{
					start : 0,
					span : 1,
					css : 'oneFourthColLeft'
				},
				{
					start : 1,
					span : 1,
					css : 'oneFourthColMidLeft'
				},
				{
					start : 2,
					span : 1,
					css : 'oneFourthColMidRight'
				},
				{
					start : 3,
					span : 1,
					css : 'oneFourthColRight'
				},
				{
					start : 0,
					span : 2,
					css : 'oneHalfColLeft'
				},
				{
					start : 1,
					span : 2,
					css : 'oneHalfColMiddle'
				},
				{
					start : 2,
					span : 2,
					css : 'oneHalfColRight'
				},
				{
					start : 0,
					span : 3,
					css : 'threeFourthsColLeft'
				},
				{
					start : 1,
					span : 3,
					css : 'threeFourthsColRight'
				},
				{
					start : 0,
					span : 4,
					css : 'fullCol'
				}
			]
		})
	});
	
}
PageController.prototype.onLoad = function(){
	if(this.enableOmniture){
		// call omniture for the page 
		this.callOmnitureForPage();
    }
	this.setupMenus();
	this.setupSearch();
	this.setupContent();
}
PageController.prototype.initialize = function(rootUrl){
    if(rootUrl == null || rootUrl == "/"){ rootUrl = ""; }
    this.rootUrl = rootUrl;
}
PageController.prototype.writeJavaScriptInclude = function(url, appendRootUrl){
    if(url == null || url == ""){ return; }
    if(appendRootUrl){ url = Util.concatUrls(this.rootUrl, url); }
    document.write("<script type=\"text/javascript\" src=\"" + url + "\"></script>");
}
PageController.prototype.writeCssInclude = function(url, appendRootUrl){
    if(url == null || url == ""){ return; }
    if(appendRootUrl){ url = Util.concatUrls(this.rootUrl, url); }
    document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"" + url + "\" media=\"all\" />");
}
PageController.prototype.setDartValues = function(categoryKey, subCategoryKey, pageName){
    this.baseDartTarget = categoryKey + ";sub=" + subCategoryKey + ";n=" + pageName;
}
PageController.prototype.setBaseDartTarget = function(baseDartTarget){
	this.baseDartTarget = baseDartTarget;
}
PageController.prototype.setOmnitureValues = function(server, channel, prop3, prop4, pageName){
    this.omniServer = server;
    this.omniChannel = channel;
    this.omniProp3 = prop3;
    this.omniProp4 = prop4;
    this.omniPageName = pageName;
}
PageController.prototype.setOriginServeDate = function(year, month, day, hour, minute, second){
	this.originServeDate = new Date(year, month, day, hour, minute, second, 0);
}
PageController.prototype.callOmnitureForPage = function(){
    this.callOmniture(this.omniServer, this.omniChannel, this.omniPageName, this.omniProp3, this.omniProp4, null, null);
}
PageController.prototype.callOmnitureForVideoPlay = function(channelKey, subsectionKey, showKey, episodeKey, segmentKey){
	//alert(channelKey + " - " + subsectionKey + " - " + showKey + " - " + episodeKey + " - " + segmentKey);
	if(channelKey == null || subsectionKey == null || showKey == null || episodeKey == null || segmentKey == null){ return; }
    this.callOmniture(this.omniServer, channelKey, segmentKey, subsectionKey, null, showKey, episodeKey);
}
PageController.prototype.callOmniture = function(server, channel, pageName, prop3, prop4, prop5, prop6){
	if(s == null){ return; }	
	if(!this.enableOmniture){ return; }	
	//alert(server + "; " + channel + "; " + pageName + "; " + prop3 + "; " + prop4 + "; " + prop5 + "; " + prop6);
	// You may give each page an identifying name, server, and channel on the next lines.
	s.server = server;
	s.channel = channel;
	s.pageName = pageName;
	s.prop3 = prop3;
	s.prop4 = prop4;
	if(prop5){ s.prop5 = prop5; }    // used for video
	if(prop6){ s.prop6 = prop6; }   // used for video
	//Populate some Omniture JavaScript variables from the BET cookie JSONuUser. If a cm_JSONUser cookie is 
	//present then parse it into its appropriate parts (GUID, AGE, Gender, Zip and State)
	var myJSONUser = this.readCookie("cm_JSONUser");	//Get the cookie values
	if(myJSONUser != null){
		//Parse the cookie through JSON
		var parseJSONUser = JSON.parse(myJSONUser);
		//Set the Omniture GUID
		s.prop1 = parseJSONUser.uid;
		//We can set this value to 'Logged In' because the cookie is present therefore the user must be 'Logged In'
		s.prop2 = "Logged In";
		//s.prop5 & s.prop6 are used by BOB (BET On Blast)
		//Set the Age
		s.prop7 = parseJSONUser.age;
		//Set the Gender
		s.prop8 = parseJSONUser.gender;
		//Set the State
		s.prop9 = parseJSONUser.state;
		//Set the Zip
		s.prop10 = parseJSONUser.zip;
		//Set the date registered
		s.prop11 = parseJSONUser.rdate;
	}else{
		//If we are here we know this user is not logged in
		s.prop1 = "";
		s.prop2 = "Not Logged In";
	}

	// E-commerce Variables 
	s.events = "";

	//Set the Commerce varaible values from previously derrived Traffic variable. 
	s.eVar1 = s.prop1;
	s.eVar2 = s.prop2;
	//Each event for Omniture has its own Literal defined below. Any web page that causes an event to fire can then set the appropriate Omniture variable.

	// ************* DO NOT ALTER ANYTHING BELOW THIS LINE ! *************
	//alert(s.t);
	//alert(s);
	var s_code = s.t();     // this makes the call
	//alert(s_code);
	//alert(s_code == "");
	/*
	if(s_code != null && s_code != ""){
		document.write(s_code);
		//alert(s_code);
	}
	if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-');
	*/
}
PageController.prototype.getNextTile=function(){
	if(this.currentTile==null)
	{
		this.currentTile=0;
	}
	this.currentTile++;
	return this.currentTile;
}
PageController.prototype.getPlaceholderHtml = function(width, height){
    return "<div style=\"width:" + width + "px;height:" + height + "px;background:#CCCCCC;\"></div>";
}
PageController.prototype.writeAdHtml = function(adType){	
    document.write(this.getAdHtml(adType));
    //var html = this.getAdHtml(adType);
    //document.write(html);
    //document.write("<textarea cols=\"80\" rows=\"6\" style=\"clear:both;\">" + html + "</textarea>");
}
PageController.prototype.getAdHtml = function(adType){
    var width, height;    
    switch(adType){
        case AdType.HeaderAd:
            width = 728;
            height = 90;
            break;
        //case AdType.PageAd:			// removed 2008-09-10
        //    break;
        case AdType.FooterAd:
            width = 728;
            height = 90;
            break;
        case AdType.LeftNavSponsorAd:
            width = 135;
            height = 35;
            break;
        case AdType.SkyscraperAd:
            width = 160;
            height = 600;
            break;
        case AdType.MediumRectangleAd:
            width = 300;
            height = 250;
            break;
        case AdType.CoAd:
				width = 300;
				height = 250;
				this.coAd=true;
				break;
        default:
            return "";
    }    
    if(!this.enableAds){ return this.enableAdsPlaceholder ? this.getPlaceholderHtml(width, height) : ""; }
    /*if(this.currentTile == null){ this.currentTile = 0; }
    this.currentTile++;*/
    if(adType==7)
		{return this.handleCoAd(width,height,this.getNextTile());}
    return this.getAdScriptInclude(width, height,this.getNextTile());  
}
PageController.prototype.handleCoAd=function(width,height,tile){
		var p=jQuery("#pageAdDiv2 dl dd");
		p.append('<div style="background:#D7D5D6;height:250px;width:300px;overflow:hidden;"></div>');
		p.append('<div class="clearFloats"></div>');
}

PageController.prototype.reloadCoAd=function(width,height,tile){	
	var p=jQuery("#pageAdDiv2 dl dd");
	var adS=this.baseDartTarget;
	adS+='mid='+this.getNextCoAdSlot()+";";
	var ord=this.getDartOrd();
	var adString='<nolayer>';adString+='<iframe id="adi_01" src="http://ad.doubleclick.net/adi/www.bet.com/'+adS+'sz='+width+'x'+height+';tile='+tile+';ord='+ord+'?" width="'+width+'" height="'+height+'" frameborder="0" border="0" marginwidth="0" marginheight="0" align="left" scrolling="no" style="height: '+height+'; width: '+width+'>';adString+='</iframe>';adString+='</nolayer>';
	adString+='<ilayer id="ad_01" visibility="hidden" width='+width+' height='+height+'></ilayer>';
	p.html(adString);
	p.append('<div class="clearFloats"></div>');

}

PageController.prototype.getNextCoAdSlot=function(){
	if(this.coAdServeCount==null)
	{
	this.coAdServeCount=-1;
	}
	this.coAdServeCount++;return this.coAdServeCount;
}
PageController.prototype.getDartOrd=function(){
if(this.dartOrd==null)
{this.dartOrd=Util.getRandom();}
return this.dartOrd;
}
PageController.prototype.writeFlashHtml = function(width, height, file, version, id, wmode, vars, loop, appendDartTarget, allowScriptAccess){
	var html = this.getFlashHtml(width, height, file, version, id, wmode, vars, loop, appendDartTarget, allowScriptAccess);
    document.write(html);
    //alert(html);
    //document.write("<br/><textarea cols=\"80\" rows=\"30\">" + html + "</textarea><br/>");
}
PageController.prototype.getFlashHtml = function(width, height, file, version, id, wmode, vars, loop, appendDartTarget, allowScriptAccess) {
    if(!this.enableFlash){ return this.enableFlashPlaceholder ? this.getPlaceholderHtml(width, height) : ""; }
	if (file == null || file == "") { return ""; }
	// if the filename has a querystring use & to add to it
	var qs = (file.indexOf("?") > -1) ? "&" : "?";
	var d = new Date();
	file = file + qs; 
	switch (version) {
		case 7:
			minorVersion = 19;
			break;
		case 6:
			minorVersion = 79;
			break;
		case 5:
			minorVersion = 30;
			break;
		default:
			minorVersion = 0;
	}
	if(appendDartTarget){
	    file += "&dartString=" + this.dartTarget;
	}
	if(this.currentDateKey){
	    file += "&currDateKey=" + this.currentDateKey;
	}
	var html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,' + minorVersion + ',0"';
	html += ' width="' + width + '" height="' + height + '" id="' + id + '" align="">';
	html += '<param name="movie" value="' + file + '"/><param name="loop" value="' + loop + '"/><param name="quality" value="high"/><param name="wmode" value="' + wmode + '"/>';
	html += '<param name="FlashVars" value="' + vars + '">';
	if(allowScriptAccess != null){
		html += '<param name="allowScriptAccess" value="' + allowScriptAccess + '">';
	}
	html += '<embed src="' + file + '" loop="' + loop + '" quality="high" wmode="' + wmode + '" width="' + width + '" height="' + height + '" name="' + id + '" flashVars="' + vars + '" align=""';
	if(allowScriptAccess != null){
		html += ' allowScriptAccess="' + allowScriptAccess + '"';
	}
	html += ' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
	return html;
}

PageController.prototype.getAdScriptInclude = function(width, height, tile) {
    //if(this.dartOrd == null){ this.dartOrd = Util.getRandom(); }
    //var ord = Util.getRandom();
    var ord=this.getDartOrd();   // dart ordinal needs to have page scope
	var adS = "www.bet.com/" + this.baseDartTarget;
	if(this.useInterstitial && tile == 1){
		adS += "dcopt=ist;";
	}
	adS += "sz=" + width + "x" + height + ";tile=" + tile + ";ord=" + ord + "?";
	//alert(adS);
	var output = '<script type="text/javascript" src="http://ad.doubleclick.net/adj/' + adS +'" ></script>';
	if ((!document.images && navigator.userAgent.indexOf("Mozilla/2.") >= 0)  || navigator.userAgent.indexOf("WebTV")>= 0) {
		output += '<a href="http://ad.doubleclick.net/jump/' + adS +'" target="_blank">';
		output += '<img src="http://ad.doubleclick.net/ad/' + adS + '" width="' + width + '" height="' + height + '" border="0" alt="" /></a>';
	}
	return output;
}
// dom mods
PageController.prototype.addBlockHover = function(selector, hoverCssClass){
	$(selector).hover( function(){ $(this).addClass(hoverCssClass); }, function(){ $(this).removeClass(hoverCssClass); } );
}
PageController.prototype.makeBlockAnchors = function(selector, hoverCssClass){
	if(hoverCssClass){ this.addBlockHover(selector, hoverCssClass); }
	$(selector).each( 
        function(index, item){
            Util.makeBlockAnchor(item);    // makes the whole element work as if it was the first anchor within the element
        }
    );
}
PageController.prototype.makeBlockAnchorsWithOverlays = function(selector, hoverCssClass){
	if(hoverCssClass){ this.addBlockHover(selector, hoverCssClass); }
	$(selector).each( 
        function(index, item){
            var anchor = Util.makeBlockAnchor(item);    // makes the whole element work as if it was the first anchor within the element
            if(anchor){     // make it an anchor.  if it works, add overlay
                // add overlay
                var buttonText = anchor.innerHTML;
                //$(item).append("<div class=\"overlay\"><div class=\"overlayBG\"></div><div class=\"overlayButton\"><div class=\"overlayButton1\"><div class=\"overlayButton2\"><span>" + buttonText + "</span></div></div></div>");
                $(item).append("<div class=\"overlay\"><div class=\"overlayBG\"></div><div class=\"overlayButton\"><div class=\"overlayButtonLeft\"></div><div class=\"overlayButtonMiddle\"><span>" + buttonText + "</span></div><div class=\"overlayButtonRight\"></div></div></div>");
            }
        }
    );
}
// begin cookie functions
PageController.prototype.createCookie = function(name, value, days){
	var expires = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		expires = "; expires=" + date.toGMTString();
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}
PageController.prototype.readCookie = function(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(";");
	for(var i=0; i<ca.length; i++){
		var c = ca[i];
		while (c.charAt(0) == " "){ c = c.substring(1, c.length); }
		if (c.indexOf(nameEQ) == 0){ return c.substring(nameEQ.length, c.length); }
	}
	return null;
}
PageController.prototype.killCookie = function(name){
	this.createCookie(name, "", -1);
}
PageController.prototype.cookieCheck = function(){
	var cookieName = "BET_Test_Cookie";
	var cookieValue = "A Test";
	this.createCookie(cookieName, cookieValue);
	var cookieSuccess = (this.readCookie(cookieName) == cookieValue);
	this.killCookie(cookieName);
	return cookieSuccess;
}
// end cookie functions

PageController.prototype.setupMenus = function(){
	var me = this;
	// utility bar menu
	var utilityNavigationDiv = document.getElementById("utilityNavigation");
	var divPos = Util.getElementPosition(utilityNavigationDiv);
	$("#utilityNavigation > dd > ul > li.hasChildren").each( function(index, item){ 
		var subMenu = $(item).find("dl").get();
		if(subMenu != null){
			var itemPos = Util.getElementPosition(item);
			var x = itemPos.x - divPos.x;
			var y = itemPos.y + itemPos.height - divPos.y;
			var newID = me.getNextID();
			var html = "<div id=\"" + newID + "\" class=\"utilDropMenu\" style=\"left:" + x + "px;top:" + y + "px;\">" + item.innerHTML + "</div>";
			// add to pageDiv to make sure it appears above everything
			$("#pageDiv2").append(html);
			var newSubMenu = document.getElementById(newID);
			item._subMenu = newSubMenu;
			newSubMenu._parent = item;
			item._pageController = this;		
			$(item).hover( function(){ me.showSubMenu(item); }, function(){ me.hideSubMenu(item); } );
			$(newSubMenu).hover( function(){ me.showSubMenu(item); }, function(){ me.hideSubMenu(item); } );		
		}
	});
}
PageController.prototype.undoSetupMenus = function(){
    // this function just un-does what the above function does
    var me = this;
	// utility bar menu
	$("#utilityNavigation > dd > ul > li.hasChildren").each( function(index, item){
	    if(item._subMenu != null){
		    var subMenu = $(item).find("dl").get();
		    if(subMenu != null){
			    //$(item).hover( function(){ void(null); }, function(){ void(null); } );
			    $(item._subMenu).remove();
			    item._subMenu = null;
		    }
		}
	});
}
PageController.prototype.getNextID = function(){
	this._idCounter++;
	return "_i" + this._idCounter;
}
PageController.prototype.showSubMenu = function(item){
    if(item._subMenu == null){ return; }
	if(this._menuExpanded != null && this._menuExpanded != item){
		this.hideSubMenuNow();
	}
	this._menuExpanded = item;
	item._isCollapsing = false;
	$(item).addClass("expanded");
	$(item._subMenu).addClass("expanded");
}
PageController.prototype.hideSubMenu = function(item){
    if(item._subMenu == null){ return; }
	if(this._menuExpanded != item){ return; }
	item._isCollapsing = true;
	if(this._hideSubMenuTimeout != null){
		clearTimeout(this._hideSubMenuTimeout);
		this._hideSubMenuTimeout = null;
	}
	this._hideSubMenuTimeout = setTimeout("PC.hideSubMenuNow();", 50);
}
PageController.prototype.hideSubMenuNow = function(){
	if(this._menuExpanded != null && this._menuExpanded._isCollapsing){
		$(this._menuExpanded).removeClass("expanded");
		$(this._menuExpanded._subMenu).removeClass("expanded");
		this._menuExpanded._isCollapsing = false;
		this._menuExpanded = null;
	}
}

PageController.prototype.setupSearch = function(){
	if(this.searchUrlFormat == null || this.searchUrlFormat == ""){ return; }
	var searchButton = document.getElementById("searchButton");
	if(searchButton == null){ return; }
	// change the type from submit to button

	$(searchButton).replaceWith("<input id=\"searchButton\" type=\"button\" value=\"Go\" />");
	searchButton = document.getElementById("searchButton");
	if(searchButton == null){ return; }
	
	var me = this;
	searchButton.onclick = function(){ me.onClickSearch(); };
}
PageController.prototype.onClickSearch = function(){
	this.doSearch();
}
PageController.prototype.doSearch = function(){
	var textBox = document.getElementById("searchQuery");
	var text = textBox.value;
	if(text == ""){ return; }
	text = text.replace(" ", "%20");
	var url = this.searchUrlFormat.replace("{0}", text);
	document.location = url;
}
PageController.prototype.setupContent = function(){
	$("dl.socialMenu ul li a").each(function(index, item){
		var parent = item.parentNode;
		parent._anchor = item;
		parent.onclick = function(){ this._anchor.click(); };
	});
	
	// make the digg and delicious on the article page work differently
	$("div.articleDiv dl.socialMenu .diggLink span").replaceWith("<img src=\"/WebApplications/betRoot/includes/base/img/soc_digg.gif\" title=\"Digg\" />");
	$("div.articleDiv dl.socialMenu .deliciousLink span").replaceWith("<img src=\"/WebApplications/betRoot/includes/base/img/soc_delicious.gif\" title=\"Del.icio.us\" />");
	
}
PageController.prototype.popupWindow = function(url, width, height, id, scrollbars, locationbar, toolbar, statusbar, menubar, resizable, xPosition, yPosition){
	
	if(width == null || width < 1){ width = 300; }
	if(height == null || height < 1){ height = 300; }
	if(id == null){ id = "_popup"; }
	
	if(xPosition == null || xPosition < 0){ xPosition = 50; }
	if(yPosition == null || yPosition < 0){ yPosition = 50; }
	
	var parms = "width=" + width;
	parms += ",height=" + height;
	parms += ",scrollbars=" + (scrollbars ? "1" : "0");
	parms += ",location=" + (locationbar ? "1" : "0");
	parms += ",toolbar=" + (toolbar ? "1" : "0");
	parms += ",statusbar=" + (statusbar ? "1" : "0");
	parms += ",menubar=" + (menubar ? "1" : "0");
	parms += ",resizable=" + (resizable ? "1" : "0");
	parms += ",toolbar=" + (toolbar ? "1" : "0");
	
	var x,y;
	switch(xPosition){
		case "left":
			x = 0;
			break;
		case "right":
			x = 0;	// todo
			break;
		case "center":
			x = 0;	// todo
			break;
		case null:
			x = 0;	// todo
			break;
		default:
			x = xPosition;
			break;
	}
	switch(yPosition){
		case "left":
			y = 0;
			break;
		case "right":
			y = 0;	// todo
			break;
		case "center":
			y = 0;	// todo
			break;
		case null:
			y = 0;	// todo
			break;
		default:
			y = yPosition;
			break;
	}
	
	parms += ",left=" + xPosition;
	parms += ",top=" + yPosition;
	
	eval("page" + id + " = window.open(url, '" + id + "', '" + parms + "');");
}
PageController.prototype.playLeaderboardAd = function(adUrl, adClickUrl){
    var html = null;
    var adUrlLower = adUrl.toLowerCase(); 
    if(adUrlLower.indexOf(".swf") >= 0){
		// this is a flash ad
		html = PC.getFlashHtml(728, 90, adUrl, 8, null, FlashWMode.Transparent);    // must be transparent otherwise it will mess up menus
		html = "<div style=\"z-index:0;\">" + html + "</div>";
    }else{
		if(adUrlLower.indexOf(".jpg") >= 0 || adUrlLower.indexOf(".gif") >= 0 || adUrlLower.indexOf(".png") >= 0){
			// this is an image ad
			html = "<img src=\"" + adUrl + "\" />";
			if(adClickUrl != null && adClickUrl != ""){
				html = "<a href=\"" + adClickUrl + "\">" + html + "</a>";
			}
		}
    }
    
    $("#headerAdDiv dd div").empty();
    $("#headerAdDiv dd div").append(html);
}

//this method initializes any commenting on the page
PageController.prototype.initCommenting = function(config) {

    var cc = new CommentController(config);
    cc.initialize();

}
PageController.prototype.layoutControls = function(config) {

	var firstChild = jQuery(config.container).children()[0];        
    if(this.layoutManager.getLayout('threeColumn').canLayout(firstChild)) {
    
		this.layoutManager.doLayout({ container : config.container, layout : 'threeColumn' });
		
	}
	else if(this.layoutManager.getLayout('fourColumn').canLayout(firstChild)) {
		
		this.layoutManager.doLayout({ container : config.container, layout : 'fourColumn' });
		
	}

}

//
// end PageController object


// begin Enums  (simulate enum functionality for tighter code)
//

function AdTypeEnum(){
    this.HeaderAd = 1;
    //this.PageAd = 2;	// removed 2008-09-10
    this.FooterAd = 3;
    this.LeftNavSponsorAd = 4;
    this.MediumRectangleAd = 5;	// added 2008-09-10
    this.SkyscraperAd = 6;	// added 2008-09-10
    this.CoAd = 7;
}
var AdType = new AdTypeEnum();

function FlashWModeEnum(){
    this.Window = "window";
    this.Opaque = "opaque";
    this.Transparent = "transparent";
}
var FlashWMode = new FlashWModeEnum();

function FlashAllowScriptAccessEnum(){
    this.Always = "always";
    this.Never = "never";
    this.SameDomain = "sameDomain";
}
var FlashAllowScriptAccess = new FlashAllowScriptAccessEnum();

//
// end Enums


// begin other objects
//
// DateMap is used to map a date or date range to a string value.
function DateMap(){
	this.items = new Array();
	this.needsFix = false;
}
DateMap.prototype.addMapBegin = function(mappedValue, year, month, day, hour, minute, second){
	var dateBegin = (year == null) ? null : new Date(year, month, day, hour, minute, second, 0);
	var item = new DateMapItem(dateBegin, null, mappedValue);	// don't set the endDate yet
	this.items[this.items.length] = item;
	this.needsFix = true;
	return item;
}
DateMap.prototype.fixItems = function(){
	// sorts items by beginDate
	this.items.sort(this.sortFunc);
	for(var index=0; index<this.items.length; index++){
		var item = this.items[index];
		if(index > 0){
			var prevItem = this.items[index - 1];
			if(prevItem.endDate == null || prev.endDate > item.beginDate){
				prevItem.endDate = new Date();
				prevItem.endDate.setTime(item.beginDate.getTime() - 1);	// no overlap
			}
		}
	}
	this.needsFix = false;
}
DateMap.prototype.sortFunc = function(item1, item2){
	if(item1.beginDate == item2.beginDate){ return 0; }
	if(item1.beginDate == null){ return -1; }	// null is less than any date
	if(item2.beginDate == null){ return 1; }
	if(item1.beginDate < item2.beginDate){ return -1; }
	return 1;
}
DateMap.prototype.getValue = function(date){
	if(this.needsFix){ this.fixItems(); }
	for(var index=0; index<this.items.length; index++){
		var item = this.items[index];
		if((item.beginDate == null || item.beginDate <= date) && (item.endDate == null || date <= item.endDate)){ return item.mappedValue; }
	}
	return null;
}
function DateMapItem(beginDate, endDate, mappedValue){
	this.beginDate = beginDate;
	this.endDate = endDate;
	this.mappedValue = mappedValue;
}
DateMapItem.prototype.setEndDate = function(year, month, day, hour, minute, second){
	this.endDate = new Date(year, month, day, hour, minute, second);
	if(this.endDate < this.beginDate){ this.endDate = this.beginDate; }
}



function Point(x, y){
    this.x = x;
    this.y = y;
}

function Size(width, height){
    this.width = width;
    this.height = height;
}

function Rectangle(x, y, width, height){
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
}



function SimplePopupSurvey(surveyKey, url, probability, width, height){
    this._surveyKey = surveyKey;
    this._url = url;
    this._probability = probability;    // the likelihood of the survey popping up
    this._width = width;
    this._height = height;
    this._isSeen = false;
    this.maxChanceCount = -1;      // the number of times we should continue 
                                    // to "roll the dice" on whether they should view the survey.
                                    // -1 indicates no max
    this.maxDisplayCount = -1;      // the maximum number of times the survey can be displayed
                                    // -1 indicates no max
    // demo isHit function                             
    //for(var i=0; i<60; i++){
    //    document.write(i + "  " + this.isHit(i, this._probability) + "<br/>");
    //}                                  
}
SimplePopupSurvey.prototype.activate = function(){
    // determine if the survey should been seen
    // see if it has reached its max display count
    var chanceCountCookieKey = this._surveyKey + "_ChanceCount";
    var chanceCount = this.intFromCookie(chanceCountCookieKey);
    if(this.maxChanceCount > 0 && chanceCount >= this.maxChanceCount) return;   // don't chance it
    
    // chance it.  use the seconds of the current time and the probability to create randomness
    // since we are using the seconds, this only works exactly for probabilities >= 1/60
    var date = new Date();  // current date & time
    var seconds = date.getSeconds();
    var showSurvey = this.isHit(seconds, this._probability);
    chanceCount++;
    this.setCookie(chanceCountCookieKey, chanceCount, false);
    
    if(showSurvey){
        // check max display count
        var displayCountCookieKey = this._surveyKey + "_DisplayCount";
        var displayCount = this.intFromCookie(displayCountCookieKey);
        if(this.maxDisplayCount > 0 && displayCount >= this.maxDisplayCount) return;   // don't display 
        // display it
        window.open (this._url, "surveyWindow", "resizable=1,status=1,toolbar=1,width=" + this._width + ",height=" + this._height);
        // increment the display count
        displayCount++;
        this.setCookie(displayCountCookieKey, displayCount, false);
    }
}
SimplePopupSurvey.prototype.setCookie = function(key, value, isTemp, path, domain, secure){
    var cookieString = key + "=" + escape(value);
    if(!isTemp){
        var expires = new Date(2060, 1, 1);
        cookieString += "; expires=" + expires.toGMTString();
    }
    if(path){
        cookieString += "; path=" + escape(path);
    }
    if(domain){
        cookieString += "; domain=" + escape(domain);
    }
    if(secure){
        cookieString += "; secure";
    }
    document.cookie = cookieString;
}
SimplePopupSurvey.prototype.deleteCookie = function(key){
    var cookieDate = new Date();// current date & time
    cookieDate.setTime(cookieDate.getTime() - 1);
    document.cookie = key += "=; expires=" + cookieDate.toGMTString();
}
SimplePopupSurvey.prototype.getCookie = function(key){
    var results = document.cookie.match(key + '=(.*?)(;|$)');
    if(results){
        return(unescape(results[1]));
    }else{
        return null;
    }
}
SimplePopupSurvey.prototype.intFromCookie = function(key, defaultValue){
    if(defaultValue == null){ defaultValue = 0; }
    var value = this.getCookie(key);
    if(value == null){ return defaultValue; }
    value = parseInt(value, 10);
    return value;
}
SimplePopupSurvey.prototype.isHit = function(num, probability){
    if(probability >= 1) return true;
    if(probability <= 0) return false;
    var useInverse = (probability > 0.5);
    if(useInverse){
        probability = 1/probability;
    }
    var isHit = Math.round(num % (1/probability) * 1000)/1000 == 0;
    if(useInverse) return !isHit;
    return isHit;    
}

//implment the classes required for controlling a set of comment blocks
if(window.CommentController == null) {        
    
    var clone = function(obj) {
                
        if(obj == null)
            return obj;
        
        var copy = {};
        
        for(var attr in obj)
            copy[attr] = obj[attr];
            
        return copy;
        
    };
    
    var override = function(obj, ovr, deep) {
      
        if(ovr == null)
            return obj;
        
        var copy = clone(obj);
        
        for(var attr in ovr) {
            
            if(typeof(obj[attr] != 'undefined')) {
                
                if((typeof(obj[attr]) == 'object') && deep) {
                    
                    copy[attr] = override(obj[attr], ovr[attr], deep);
                    
                }
                else {
                    
                    copy[attr] = ovr[attr];
                    
                }
                
            }
                
        }
        
        return copy;
        
    };
    
    //Adds paging capability to comments
    window.CommentPager = function(config) {          
        
        var _private = {
            
            settings : {
                
                pageSize : 10,
                currentPage : 0,
                hideClass : 'hidden',
                showClass : 'visible',
                firstClass : 'first',
                lastClass : 'last',
                nextHtml : '<span>Next</span>',
                prevHtml : '<span>Previous</span>',
                navigation : 'both'
                
            },
            
            //shows the current page
            showPage : function() {
                
                //the current list depends on which page we are viewing
                var firstItem = _private.settings.currentPage * _private.settings.pageSize;
                var lastItem = firstItem + _private.settings.pageSize;
                
                if(lastItem > _private.commentList.length)
                    lastItem = _private.commentList.length;
                
                if(_private.currentItems != null)
                    //hide the old items
                    jQuery.each(_private.currentItems, _private.hideItem);
                    
                _private.currentItems = _private.commentList.slice( firstItem, lastItem );
                
                //show the currentItems
                jQuery.each(_private.currentItems, _private.showItem);                    
                
            },
            
            //shows the next page
            nextPage : function() {
                
                var next = _private.settings.currentPage + 1;                    
                if(next > _private.lastPage)
                    next = _private.lastPage;
                
                _private.settings.currentPage = next;                    
                _private.showNavigation();
                _private.showPage();
                
                return false;
                
            },
            
            //shows the previous page
            prevPage : function() {
                
                var prev = _private.settings.currentPage - 1;
                if(prev < _private.firstPage)
                    prev = _private.firstPage;                        
                
                _private.settings.currentPage = prev;
                _private.showNavigation();
                _private.showPage();
                
                return false;
                
            },
            
            //processes each item that is about to be shown
            showItem : function(index, item) {  
                
                //clear extraneous style
                jQuery(item).removeClass(_private.settings.hideClass);
                jQuery(item).removeClass(_private.settings.firstClass);
                jQuery(item).removeClass(_private.settings.lastClass);
                
                
                //apply appropriate stlying to show the item
                jQuery(item).addClass(_private.settings.showClass);
                
                if( index == 0 )
                    jQuery(item).addClass(_private.settings.firstClass);
                    
                if( index == (_private.settings.pageSize - 1) )
                    jQuery(item).addClass(_private.settings.lastClass);
                    
                
                
            },
            
            //process each item that is about to be shown
            hideItem : function(index, item) {
                
                //clear extraneous style and hide the item
                jQuery(item).removeClass(_private.settings.hideClass);
                jQuery(item).removeClass(_private.settings.firstClass);
                jQuery(item).removeClass(_private.settings.lastClass);
                jQuery(item).removeClass(_private.settings.showClass);
                
            },
            
            initNavigation : function() {
                
                if((_private.topNav == null) && ((_private.settings.navigation == 'both') || (_private.settings.navigation == 'top'))) {
                    //create top navigation                    
                    jQuery(_private.commentControl).find('dd:first a:first').after('<dl class="navigation top"><dt>Comment Navigation</dt><dd><div class="navLinks"><a class="prevLink" href="#"></a><a class="nextLink" href="#"></a></div><div class="clearFloats"></div></dd></dl>');
                    
                    _private.topNav = jQuery(_private.commentControl).find('.navigation.top');
                    _private.buildNavigation(_private.topNav);
                    
                }
                
                if((_private.bottomNav == null) && ((_private.settings.navigation == 'both') || (_private.settings.navigation == 'bottom'))) {
                    //create bottom navigation                    
                    jQuery(_private.commentControl).find('dd:first').append('<dl class="navigation bottom"><dt>Comment Navigation</dt><dd><div class="navLinks"><a class="prevLink" href="#"></a><a class="nextLink" href="#"></a></div><div class="clearFloats"></div></dd></dl>');
                    
                    _private.bottomNav = jQuery(_private.commentControl).find('.navigation.bottom');
                    _private.buildNavigation(_private.bottomNav);
                    
                }
                
                _private.showNavigation();
                
            },
            
            buildNavigation : function(nav) {
                
                jQuery(nav).find('a.prevLink').html(_private.settings.prevHtml);
                jQuery(nav).find('a.nextLink').html(_private.settings.nextHtml);
                jQuery(nav).find('a.prevLink').click(_private.prevPage);
                jQuery(nav).find('a.nextLink').click(_private.nextPage);
                
            },
            
            showNavigation : function() {
                
                if(_private.settings.currentPage == _private.firstPage){
                    jQuery(_private.commentControl).find('.navigation a.prevLink').addClass(_private.settings.hideClass);
                    
                    if(_private.lastPage != _private.firstPage)
                        jQuery(_private.commentControl).find('.navigation a.nextLink').removeClass(_private.settings.hideClass);
                    else
                        jQuery(_private.commentControl).find('.navigation a.nextLink').addClass(_private.settings.hideClass);
                        
                }
                else if(_private.settings.currentPage == _private.lastPage) {
                    jQuery(_private.commentControl).find('.navigation a.nextLink').addClass(_private.settings.hideClass);
                    jQuery(_private.commentControl).find('.navigation a.prevLink').removeClass(_private.settings.hideClass);
                }
                else {
                    jQuery(_private.commentControl).find('.navigation a.prevLink').removeClass(_private.settings.hideClass);
                    jQuery(_private.commentControl).find('.navigation a.nextLink').removeClass(_private.settings.hideClass);
                }
                
            },
            
            commentControl : null,
            
            commentList : null,
            
            currentItems : null,
            
            lastPage : 0,
            
            firstPage : 0,
            
            topNav : null,
            
            bottomNav : null
            
        };
        
        //override the defaults with anything the user passed into the constructor
        _private.settings = override(_private.settings, config);
        
        return {
            
            initialize : function(control, args) {
                
                //override defaults or constructor settings with function arguments
                _private.settings = override(_private.settings, args);
                
                //get the list of all comments
                _private.commentControl = control;
                _private.commentList = jQuery(control).find('dl.comment');
                
                if(_private.commentList.length > 0) {
                
					_private.lastPage = Math.floor(_private.commentList.length / _private.settings.pageSize) + ((_private.commentList.length % _private.settings.pageSize) > 0 ? 0 : -1);
	                
					//get the navigation
					_private.initNavigation();
	                
					//show the current page of comments
					_private.showPage();
                
                }
                
            }
            
        };
        
    };
    
    //controls all comments on a page
    window.CommentController = function(config) {
      
        //data members
        var _private = {
            
            settings : {
                
                //settings for the pager
                pager : {
                    
                    pageSize : 10,
                    currentPage : 0,
                    hideClass : 'hidden',
                    showClass : 'visible',
                    firstClass : 'first',
                    lastClass : 'last',
                    nextHtml : '<span>Next</span>',
                    prevHtml : '<span>Previous</span>',
                    navigation : 'both'
                    
                },
                
                enablePaging : true
                
            }
            
        };
        
        _private.settings = override(_private.settings, config, true);
        
        //implementation
        return {
            
            initialize : function() {
                
                jQuery('.commentList').each(function(index, item) {
                   
                    if(_private.settings.enablePaging) {
                        
                        var pager = new CommentPager(_private.settings.pager);
                        pager.initialize(item);
                        
                    }
                    
                });
                
            }
            
        };
        
    };
    
}

//LayoutManager class provide automatic layout of control elements
if(window.LayoutManager == null) {
    
	var clone = function(obj) {
	            
		if(obj == null)
			return obj;
	    
		var copy = {};
	    
		for(var attr in obj)
			copy[attr] = obj[attr];
	        
		return copy;
	    
	};

	var override = function(obj, ovr, deep) {
	    
		if(ovr == null)
			return obj;
	    
		var copy = clone(obj);
	    
		for(var attr in ovr) {
	        
			if(typeof(obj[attr] != 'undefined')) {
	            
				if((typeof(obj[attr]) == 'object') && deep) {
	                
					copy[attr] = override(obj[attr], ovr[attr], deep);
	                
				}
				else {
	                
					copy[attr] = ovr[attr];
	                
				}
	            
			}
	            
		}
	    
		return copy;
	    
	};

	if(window._debug == null)
		window._debug = false;

	var debug = function(msg) {
	    
		if(window._debug)
			alert(msg);
	    
	};

	//a basic layout that packs controls into a column
	window.ColumnLayout = function(config) {
	    
		var _private = {
	        
			//overridable settings
			settings : {
	            
				columns : [],
				spans : [],
				offset : {
					top : 0,
					left : 0
				}
	            
			},
	        
			//data members
			colFill : [],
			container : null,
			items : null,
			layoutHeight : 0,
			positions : [],
	        
			//private methods
	        
			//determines an items span
			getItemSpan : function(item) {
	            
				var cls = null;
				for(var i = 0; i < _private.settings.spans.length; i++) {                    
	                
					cls = _private.settings.spans[i].css;
	            
					if(jQuery(item).hasClass(cls)) {
						debug('span type: ' + cls);                
						return _private.settings.spans[i];
					}
	                
				}
	            
				return null;
	            
			},
	        
			//determines the position of the element
			calcItemPosition : function(args) {                
	            
				var pos = { top : 0, left : 0 };
	            
				//left edge found by taking the sum of all column widths to the left of the span
				pos.left = _private.sum(_private.settings.columns.slice(0, args.span.start), function(col) { return col.width; });                
				//top edge found by getting the lowest point in the fill
				pos.top = _private.max(_private.colFill.slice(args.span.start, args.span.start + args.span.span));                
	            
				var h = pos.top + jQuery(args.item).outerHeight({ margin : true });               
	            
				if(h > _private.layoutHeight) {
				
					_private.layoutHeight = h;
					_private.container.css('height', (_private.layoutHeight + _private.settings.offset.top) + 'px');
					
				}
	                
				//update the fill
				_private.updateFill(h, args.span.start, args.span.span);
	            
				return pos;
	            
			},
	        
			//moves an item to the given position
			positionItem : function(args) {                
	            
				debug('position item with pos = { top : ' + args.pos.top + ', left : ' + args.pos.left + ' }');
				debug('offset = { top : ' + _private.settings.offset.top + ', left : ' + _private.settings.offset.left + ' }');
				jQuery(args.item).css('position', 'absolute');
				jQuery(args.item).css('top', (args.pos.top + _private.settings.offset.top) + 'px');
				jQuery(args.item).css('left', (args.pos.left + _private.settings.offset.left) + 'px');
	            
			},
	        
			//returns the max of the array
			max : function(array) {                
	            
				debug('max array length: ' + array.length);
				var max = array[0];
				for(var i = 1; i < array.length; i++) {
					max = array[i] > max ? array[i] : max;
				}
	            
				debug('max height: ' + max);
				return max;
	            
			},
	        
			//returns the sum of all the elements
			sum : function(array, getValue) {
	            
				var cb = null;
				var s = 0;
	            
				if((getValue != null) && (typeof(getValue) == 'function'))
					cb = getValue;
				else
					cb = function(item) { return item; }; //identity function
	            
				for(var i = 0; i < array.length; i++) {
	                
					s += cb(array[i]);
	                
				}
	            
				return s;
	            
			},
	        
			//fills the given array with the given value.
			//if start is specified then only elements starting
			//with start are filled. If elements is specified then
			//only elements number of positions in the array are filled.
			updateFill : function(value, start, elements) {
	            
				var s = start != null ? start : 0;
				var e = elements != null ? start + elements : _private.colFill.length;
	            
				debug('filling with { value : ' + value + ', start : ' + s + ', elements : ' + e + ' }');
				for(var i = s; i < e; i++) {
	                
					_private.colFill[i] = value;
	                
				}
	            
			}
	        
		}
	    
		//constructor code
	    
		if(config.spans.length > 0)
			debug('passed spans');
	        
		_private.settings = override(_private.settings, config);
	    
		for(var c = 0; c < _private.settings.columns.length; c++) {
			_private.colFill[c] = 0;
		}
	    
		//implementation
		return {
	        
			render : function(args) {
	                
				_private.settings = override(_private.settings, args.options, true);
				_private.container = jQuery(args.container);
				_private.items = _private.container.children();
	            
	            _private.items.css('display', 'none');
	            //_private.container.parent().css('display', 'none');
				//layout all the items into a packed column
				_private.items.each(function(index, control) {
	                
					var span = _private.getItemSpan(control);
	                
					if(span != null) {
	                    
						_private.positionItem({
	                        
							item : control,
							pos : _private.calcItemPosition({
	                            
								item : control,
								span : span
	                            
							})
	                        
						});
	                    
					}
	                
				});
	            
	            //_private.container.parent().css('display', 'block');
	            _private.items.css('display', 'block');
				_private.container.css('height', (_private.layoutHeight + _private.settings.offset.top) + 'px');
	            
			},
			
			//determines if this layout can handles the specified argument
			canLayout : function(item) {
			
				if(_private.getItemSpan(item) != null)
					return true;
				else
					return false;
			
			}
	        
		};
	    
	};

	//The LayoutManager class is responsible for applying the correct Layout to the given container
	window.LayoutManager = function() {
	    
		var _private = {
	        
			settings : {
	            
			},
	        
			layouts : []                
	        
		};
	    
		return {
	        
			doLayout : function(args) {
	        
				var layout = null;
				if(typeof(args.layout) == 'object') {
					layout = args.layout;
				}
				else if(typeof(args.layout) == 'string') {
					layout = _private.layouts[args.layout];
				}
				else {
					return;
				}
				debug('rendering');
				layout.render({ container : args.container, options : args.options });
	        
			},
	        
			registerLayout : function(args) {
	            
				_private.layouts[args.name] = args.layout;
	            
			},
			
			getLayout : function(name) {
			
				return _private.layouts[name];
			
			}
	        
		};
	    
	};

}

//
// end other objects


// create a global instance of PageController for this page.
// we declare it here because other javascript files may depend upon it and we don't want to leave it to the page to handle.
var PC = new PageController();



