// this is what gets run when the page loads
$(document).ready(function(){
	
	/*Begin Local Nav control*/
	/* ==Steps==
	1. Check for LocalNavDiv
	2. Find Lowest Selected Node
	3. Get Proper Element.
	4. Clone Element.
	5. Set Inner Div Markup to the retrieved MarkUp.
	*/
	jQuery("#primaryNavigationDiv dl.navMenu li.active").addClass("selected");
	if(document.getElementById("localNavDiv")!=null){
		var selectedNavItem = jQuery("#primaryNavigationDiv dl.navMenu li.selected:first");
		
		
		jQuery("#localNavDiv2 ul").append(selectedNavItem.clone());
	/*This has to happen before the IE 6 adjustments, because it is a copy of the primary nav.*/
	}
	
	/*End Local Nav control*/
	
	//jQuery("#primaryNavigationDiv dl.level0 li.selected:first-child a").css("background", "transparent url(/WebApplications/betRoot/includes/theme/cog2009/img/nav/navbar_activeleft.gif) no-repeat");

	
	if(navigator.userAgent.indexOf("MSIE 6")!=-1)
	{  /*Special IE 6 issues*/
		jQuery("#pageBodyDiv1").css("background","transparent url(/webapplications/betroot/includes/theme/va2008/img/innerbackground-ie.jpg) no-repeat");
		jQuery("body").css("background","transparent url(/webapplications/betroot/includes/theme/va2008/img/background-ie.jpg) no-repeat scroll center top");
		jQuery("#headerUtilityDiv").css("width", "950px");
		jQuery("#primaryNavigationDiv li a").css("width", "55px");
		jQuery("#primaryContentDiv").css("margin","0px 10px 0px 10px");
		jQuery("#primaryNavigationDiv dl.level0 dd li:nth-child(3) a").css("width", "106px");
		jQuery("div.oneThirdColLeft").css("margin", "0px 0px 0px 0px");
		jQuery("div.oneThirdColMiddle").css("margin", "0px 0px 0px 0px");
		jQuery("div.oneThirdColRight").css("margin", "0px 0px 0px 0px");
		jQuery("div.twoThirdsColLeft").css("margin", "0px 0px 0px 0px");
		jQuery("div.twoThirdsColRight").css("margin", "0px 0px 0px 0px");
		jQuery("div.fullCol").css("margin", "0px 0px 0px 0px");
		jQuery("div.twoThirdsColLeft dl.barkerBlockExtended").css("margin", "0px 10px 10px 0px");
		jQuery("div.oneThirdColLeft dl.halfSABPair").css("margin", "0px 10px 10px 0px");
		jQuery("div.oneThirdColMiddle dl.halfSABPair").css("margin", "0px 10px 10px 0px");
		jQuery("div.oneThirdColLeft dl.whatsHotList").css("margin", "0px 10px 10px 0px");
		jQuery("div.oneThirdColMiddle dl.whatsHotList").css("margin", "0px 10px 10px 0px");
		jQuery("div.oneThirdColMiddle dl.whatsHotList dl.items dl").css("position", "relative");
		jQuery("div.oneThirdColMiddle dl.whatsHotList dl.items dl").css("bottom", "16px");
		jQuery("div.oneThirdColMiddle dl.whatsHotList dl.items dl.first").css("bottom", "0px");
		jQuery("dl.more").css("left", "10px");
		jQuery("dl.galleryBarkerList dl.more").css("left", "0px");
		jQuery("dl.galleryBarkerList dl.more").css("margin", "0px 2px 0px 0px");
		jQuery("div.mediumRectangleAdDiv").css("margin", "0px 0px 9px 0px");
		jQuery("dl.whatsHotList dl.more a.relatedLink").css("position", "absolute");
		jQuery("dl.whatsHotList a.relatedLink").css("z-index", "4");
		jQuery("dl.whatsHotList dl.more a.relatedLink").css("top", "0px");
		jQuery("dl.more").css("margin-bottom", "10px");
		jQuery("div.twoThirdsColLeft dl.items").css("margin", "0px 10px 10px 0px");	
		jQuery("div.videoPlayerBoxDiv2 dl.videoDetails dl.videoTitle dd").css("right", "0px");
		jQuery("div.videoPlayerBoxDiv2 dl.videoDetails dl.videoTitle dd").css("left", "5px");
		jQuery("#category_nav").css("position", "relative");
		jQuery("#category_nav").css("top", "22px");
		jQuery("#category_nav").css("right", "5px");

	}
	else {
	
		//jQuery('head').prepend('<link rel="stylesheet" href="http://www.bet.com/WebApplications/betroot/Widgets/mammabar/css/mamma.css" type="text/css" media="all" />');	
	
	}
	/*Special Category page edits*/
	if(document.getElementById("category_nav")!=null){
		jQuery("#primaryContentDiv").css("padding","0px 0px 0px 0px");
	}
	/*End Special Category page edits*/
	/*Article Page Edits*/
	jQuery(".articlePageDiv").removeClass("fullCol");
	jQuery(".articlePageDiv").addClass("threeFourthsColLeft");
	jQuery("#skyscraperAdDiv").addClass("oneFourthColRight");
	jQuery("#skyscraperAdDiv").addClass("skyscraperAdDiv");
	jQuery("#skyscraperAdDiv1").addClass("skyscraperAdDiv1");
	jQuery("#skyscraperAdDiv2").addClass("skyscraperAdDiv2");
	/*End Article Page Edits*/
	/*Flipbook Edits*/
	jQuery(".thumbViewDiv").next(".relatedGalleriesDiv").css("display", "none");
	/*End Flipbook Edits*/
	//fixes the pageContentDiv floating issue...
	//jQuery('#pageBodyDiv2').append('<div style="clear: both;"></div>');

	if(PC.isEditMode){ 	
		jQuery('div#primaryContentDiv2').css('position', 'static');
		return; 
	}	// we want it to be fast
	

    // handle barker list types without overlays
    PC.makeBlockAnchors(".barkerList dl.items dl:not(.disabled)", "mouseover");	// pass in jquery selector and hover css class
    PC.makeBlockAnchors(".barkerList dl.more", "mouseover");
    PC.makeBlockAnchors(".videoBarkerBlockList dl:not(.disabled)", "mouseover");
    
        
    
    // handle barker list types with overlays
    //PC.makeBlockAnchorsWithOverlays(".barkerBlockPromo dl:not(.disabled)", "mouseover");	// pass in jquery selector and hover css class
    //PC.makeBlockAnchorsWithOverlays(".barkerBlockLP dl:not(.disabled)", "mouseover");	// pass in jquery selector and hover css class

    
	// inject the logo with flash that shows the air date.  the PC.currentDateKey will be passed to the flash
	// only do it if there is a currentDateKey
	
	var airdate = "";
	
	/*In the future if you have more than one element being placed into the headerIdentityDiv dynamically make sure they are not dependent upon one another.*/
	airdate += "<div class=\"oneThirdColRight\" style=\"margin-bottom:0px; width: 300px; height: 57px; position: relative; z-index: 1; background: transparent url(/Webapplications/betroot/Includes/theme/va2008/img/airdate.jpg) no-repeat;\">";
	airdate += "</div>";
	

	jQuery("div.oneThirdColRight:first").before(airdate);
	
	/*Add Time of Show onto the 4 col layout pages*/
	var timeHtml = '';
	timeHtml += '<div class="oneFourthColRight" style="background: transparent url(/Webapplications/betRoot/Includes/theme/va2008/img/tunein.jpg) no-repeat; display:block; width:160px margin-bottom:0px; height:83px; z-index: 1;">';
	timeHtml += '</div>';
	jQuery("div.oneFourthColRight:first").before(timeHtml);

	//headerIdentityDiv2.innerHTML = html;
	

	jQuery("#primaryNavigationDiv dl.level0 li").mouseover(function () {
		jQuery(this).addClass("hover");
    	});
    	jQuery("#primaryNavigationDiv dl.level0 li").mouseout(function () {
	  	jQuery(this).removeClass("hover");
    	}); 
    	jQuery("#primaryNavigationDiv dl.level0 li dl.level1 li").mouseover(function () {
		jQuery(this).addClass("hover");
	});
	jQuery("#primaryNavigationDiv dl.level0 li dl.level1 li").mouseout(function () {
		jQuery(this).removeClass("hover");
    	}); 
    

	// on the comments hr element, we need to add a div to get the faded line
	$("div.commentsDiv hr").replaceWith("<div class=\"hrDiv\"></div>");
	
	
	/*var xsbList = document.getElementById("extraSmallBarkerListDiv2");*/
	var header = "";
	header+='<div class="msnTitle">';
	header+='<a target="_blank" href="http://www.msn.com">More on MSN ></a>';
	header+='</div>';
	
	$(".extraSmallBarkerList").before(header);
	
	var urlGrabber ="";
	urlGrabber+='<div class="grabber">';
    urlGrabber+='<span>URL:</span>';
    urlGrabber+='<input class="actionUrlBox" name="urlText" type="text" readonly="readonly" id="widgetText" onclick="javascript:this.form.widgetText.focus();this.form.widgetText.select();" />';
    urlGrabber+='</div>'; 
       
    $(".videoDetails").after(urlGrabber);
      
	var locationUrl = window.location.toString();
	var qs = locationUrl.indexOf('?', 0);
	qs = qs >= 0 ? qs : locationUrl.length;
	jQuery('.actionUrlBox').val(locationUrl.substring(0, qs));
	
    // INJECT MAMMA BAR
    jQuery("img[name='s_i_betprod']").css('display', 'none');


    if (jQuery('#mtv_foot').length != 0) {


	clearInterval(footIntID);
	jQuery(document.body).css('padding-top', '0px');
	jQuery('#primaryContentClearingDiv').prev().css('margin-bottom', '0px');
	jQuery('#mtv_foot').css('margin', '0px');

    }

    // END MAMMA BAR
	
	// BARKER FIXES
	
	//this marks oneHalfColMiddle halfSAB barker items as either even or odd.
	//this allows us finer control of the margins/padding
	jQuery('div.oneHalfColMiddle dl.barkerHalfSAB dl.items dd dl').each(function(index, item) {
	
		var cls = 'even';
		
		if((index % 2) != 0) {
		
			cls = 'odd';
			
		}
		
		jQuery(item).addClass(cls);
	
	});
	
	// END BARKER FIXES
	
	// temporary fix for the galleryplayer
	jQuery('div.galleryPlayer').parent().removeClass('fullCol');
	jQuery('div.galleryPlayer').parent().addClass('threeFourthsColLeft');
	jQuery('div.videoPlayerBoxDiv').addClass('threeFourthsColLeft');
	jQuery('div.videoBarkerBlockListDiv').parent().removeClass('twoThirdsColLeft');
	jQuery('div.videoBarkerBlockListDiv').parent().addClass('oneHalfColMiddle');
	
	//let's leave these at the bottom incase there is something above that modifies the markup.
	PC.initCommenting();	
	PC.layoutControls({ container : 'div#primaryContentDiv2' });	
	
	//Change links inside of class popup to open in new windows.
	jQuery(".popup a").attr("target", "_blank");

});


// set the currentDateKey based on a DateMap
// setup a DateMap to map the current date to a mappedValue.  this will be passed into the flash items.
var dateMap = new DateMap();
dateMap.addMapBegin("0");	// no start date means it is already started
dateMap.addMapBegin("1", 2008, 4, 11, 0, 0, 0);
dateMap.addMapBegin("2", 2008, 4, 12, 0, 0, 0);
// below is how to add an item with an endDate
var item = dateMap.addMapBegin("1000", 2008, 4, 13, 0, 0, 0);
item.setEndDate(2008, 4, 14, 0, 0, 0);   // add the endDate

// set the currentDateKey of the PageController.  this will be passed in to the flash.
PC.currentDateKey = dateMap.getValue(PC.originServeDate);









