/* start Flux Comments height fix */
var fluxCommentsFix = {
    injectNewCSS: function(HREF){
        this.href = HREF;
        var target = document.getElementsByTagName('head')[0];
        var newLink = document.createElement('link');
        newLink.href = this.href;
        newLink.type = 'text/css';
        newLink.media = 'all';
        newLink.rel = 'stylesheet';
        target.appendChild(newLink);
    },
    injectNewJS: function(SRC){
        this.src = SRC;
        var target = document.getElementsByTagName('head')[0];
        var newScript = document.createElement('script');
            newScript.type = 'text/javascript';
            newScript.src = this.src;
        target.appendChild(newScript);
	},
	fixHeight: function(){
	if(MJ_Flux_Comments_Count != undefined){
		var fluxExists = jQuery('div.commentsHolder').get(0);
		if(fluxExists != undefined){
		var targetElement = jQuery('div.commentsHolder div.commentItem:last').get(0);
		if(MJ_Flux_Comments_Count <= '7'){
		if(targetElement != undefined){
		var position = jQuery(targetElement).position();
		var heightToAdd = position.top;
		var elementToFix = document.getElementById('primaryContentDiv1');
		var getFooter = document.getElementById('mtv_foot');
		var getFooterPosition = jQuery(getFooter).position();
		var currentHeight = jQuery('#primaryContentDiv1').height();
		heightToAdd = jQuery('.commentsHolder').height();
		var newHeight = currentHeight + heightToAdd +30;
		elementToFix.style.height = newHeight+'px';
		}else{
		setTimeout("var fixCommentsHeight = new fluxCommentsFix.fixHeight('div.commentsHolder div.commentItem:last')",2000);
		MJ_Flux_Comments_Count += 1;
		}}}else{
		setTimeout("var fixCommentsHeight = new fluxCommentsFix.fixHeight('div.commentsHolder div.commentItem:last')",2000);
		MJ_Flux_Comments_Count += 1;
		}
	}
}}
MJ_Flux_Comments_Count = 0;
var fixCommentsHeight = new fluxCommentsFix.fixHeight();


// this is what gets run when the page loads
jQuery(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");
    /*Special Category page edits*/
    if (document.getElementById("category_nav") != null) {
        jQuery("#primaryContentDiv").css("padding", "0px 0px 0px 0px");
    }
    /*End Special Category page edits*/
	if(navigator.userAgent.indexOf("MSIE 6")!=-1)
	{  /*Special IE 6 issues*/
	jQuery("#primaryNavigationDiv dl.level0 dd li:nth-child(4) a").css("width", "113px");
	}
    /*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");
    jQuery("dl.commentList dl.comment p.text:even").css("background", "#ffffff");
    /*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");
    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=\"display:block; margin-bottom:0px; width: 300px; height: 98px; position: relative; z-index: 1;\">";
    var file = "http://www.bet.com/static/flash/rtr09/rtr09_cdown/countdown4.swf";
    airdate += PC.getFlashHtml(300, 98, file, 8, "", FlashWMode.Transparent, "", true, true);
    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/rtr2009/img/datetime.jpg) no-repeat; display:block; width:160px margin-bottom:0px; height:98px; z-index: 1;">';
    timeHtml += '</div>';
    //jQuery("div.oneFourthColRight:first").before(timeHtml);
    jQuery('#headerIdentityDiv2').append('<a class="header-link" href="http://www.bet.com/Specials/betawards09/"></a>');
    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
    jQuery("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>';
    jQuery(".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>';
    jQuery(".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));
    //script src="/WebApplications/betroot/Widgets/mammabar/mamma.js" type="text/javascript" language="javascript"></script
    // INJECT MAMMA BAR
    jQuery("img[name='s_i_betprod']").css('display', 'none');
    // 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);
