// 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(2) a").css("width", "123px");
	}
    /*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");


/* Start Ad and Email Form Inject */
    var awardSponsor = {
	    removeLastNavItem: function(){
      var primaryNavigation = document.getElementById('primaryNavigationDiv');
      if (typeof primaryNavigation != 'undefined' && typeof primaryNavigation != undefined) {
        var getUL = primaryNavigation.getElementsByTagName('ul')[0];
        if(typeof getUL != 'undefined' && typeof getUL != undefined){
        var getLI = getUL.getElementsByTagName('li')
        for (i = 0; i < getLI.length; i++) {
          var getSpan = getLI[i].getElementsByTagName('span')[0];
          if (typeof getSpan != 'undefined' && typeof getSpan != undefined) {
            if (getSpan.innerHTML == 'My Black is Beautiful') {
              getLI[i].parentNode.style.display = 'none';
              getLI[i - 1].className = 'last';
            }
          }
         }
        }
      }
    },
        insertAd: function(classname, target){
            this.classname = classname;
            this.target = target;
            var oneThirdAdDiv = jQuery('div.oneThirdColRight').get(0);
            var oneFourthAdDiv = jQuery('div.oneFourthColRight').get(0);
            if (typeof oneFourthAdDiv != 'undefined' && typeof oneFourthAdDiv != undefined) {
                var targetElem = document.getElementById(this.target);
                var newSpan = document.createElement('span');
                newSpan.className = this.classname + ' four-col';
                var destination = targetElem.getElementsByTagName('div')[0];
                destination.appendChild(newSpan);
                oneFourthAdDiv.className = oneFourthAdDiv.className + ' ad-Skyscrapper';
                var barkerList = jQuery('div.oneHalfColMiddle.barkerBlockExtendedDiv');
                if (typeof barkerList[0] != 'undefined' && typeof barkerList[0] != undefined) {
                    barkerList[0].parentNode.style.position = 'relative';
                    barkerList[0].style.position = 'relative';
                    barkerList[0].style.left = '186px';
                }
            }
            if (typeof oneThirdAdDiv != 'undefined' && typeof oneThirdAdDiv != undefined) {
                var targetElem = document.getElementById(this.target);
                var newSpan = document.createElement('span');
                newSpan.className = this.classname;
                var destination = targetElem.getElementsByTagName('div')[0];
                destination.appendChild(newSpan);
                oneThirdAdDiv.style.top = '100px';
                var galleryDiv = jQuery('div.oneThirdColRight.galleryBarkerListDiv').get(0);
                if (typeof galleryDiv != 'undefined' && typeof galleryDiv != undefined) {
                    galleryDiv.style.top = '371px';
                }
            }
            if (typeof oneFourthAdDiv != 'undefined' && typeof oneFourthAdDiv != undefined) {
                oneFourthAdDiv.style.top = '100px';
            }
        },
        insertForm: function(classname, sourceURL, target, method){
            this.classname = classname;
            this.src = sourceURL;
            this.target = target;
            this.method = method;
            var oneThirdAdDiv = jQuery('div.oneThirdColRight').get(0);
            var oneFourthAdDiv = jQuery('div.oneFourthColRight').get(0);
            if (typeof oneThirdAdDiv != 'undefined' && typeof oneThirdAdDiv != undefined) {
                if (typeof this.target != 'undefined' && typeof this.target != undefined) {
                    var html = '<form class="newsletterSignupDiv email-subscription"><input type="text" class="emailTextbox" /><button type="button" class="submitButton" value="Sign Up" /></form>';
                    var galleryDiv = jQuery('div.oneThirdColRight.galleryBarkerListDiv').get(0);
                    if (typeof galleryDiv != 'undefined' && typeof galleryDiv != undefined) {
                        var targetElem = document.getElementById(this.target);
                        var targetTopValue = parseFloat(galleryDiv.style.top);
                        galleryDiv.style.top = targetTopValue + 100 + 'px';
                        var outerDiv = galleryDiv;
                        $(outerDiv).append(html);
                        var button = $(outerDiv).find('.submitButton').get(0);
                        var emailTextbox = $(outerDiv).find('.emailTextbox').get(0);
                        var controller = {
                            nullValueText: 'ENTER E-MAIL',
                            isActive: false,
                            getIsNull: function(){
                                var actualValue = this.textbox.value;
                                if (Util && Util.trim) {
                                    actualValue = Util.trim(actualValue);
                                }
                                return actualValue == '' || actualValue == this.nullValueText;
                            },
                            getValue: function(){
                                if (this.getIsNull()) {
                                    return null;
                                }
                                else {
                                    return this.textbox.value;
                                }
                            },
                            update: function(){
                                if (this.isActive) {
                                    if (this.getIsNull()) {
                                        this.textbox.value = '';
                                    }
                                    $(this.textbox).removeClass('emptyTextbox');
                                }
                                else {
                                    if (this.getIsNull()) {
                                        this.textbox.value = this.nullValueText;
                                        $(this.textbox).addClass('emptyTextbox');
                                    }
                                }
                            },
                            onclick: function(){
                                this.isActive = true;
                                this.update();
                            },
                            onblur: function(){
                                this.isActive = false;
                                this.update();
                            },
                            attach: function(textbox){
                                textbox._controller = this;
                                this.textbox = textbox;
                                if (this.textbox.value == '') {
                                    this.textbox.value = this.nullValueText;
                                }
                                var me = this;
                                textbox.onclick = function(){
                                    me.onclick();
                                };
                                textbox.onblur = function(){
                                    me.onblur();
                                };
                                this.update();
                            }
                        };
                        controller.attach(emailTextbox);
                        emailTextbox.blur();
                        if (button != null && emailTextbox != null) {
                            button.onclick = function(){
                                var emailAddress = emailTextbox.value;
                                var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                                if (!emailAddress.match(emailRegEx)) {
                                    alert('Please enter valid email address.');
                                    emailTextbox.select();
                                    return false;
                                }
                                var subscriptionID = 2068066151;
                                var url = '/webapplications/betroot/services/generic/web/subscriptions.aspx?SubsciberEmail=' + emailAddress + '&SubscriptionID=' + subscriptionID;
                                $.getJSON(url, null, function(data){
                                    //$(outerDiv).find('.newsletterSignupDiv').css('display', 'none');
                                    $(outerDiv).find('.newsletterSignupDiv').html('<span class="thank-you">Thank You!</span>!');
                                });
                            }
                        }
                    }
                }
            }
        }
    };
    //var MSNsponsor = new awardSponsor.insertAd('msn-sponsor', 'primaryContentDiv1');
    //var betAwardsSubscription = new awardSponsor.insertForm('email-subscription', 'http://www.google.com/', 'primaryContentDiv1', 'POST');
	var removeLastNavItem = new awardSponsor.removeLastNavItem();	
/* End Ad and Email Form Inject */


});
// 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);
