﻿var recommendationChildren = -1;
var pageFooterChildren = -1;
var pageHeaderMenuChildren = -1;
var pageHeaderSearchChildren = -1;
var debug = false;
var XmlHelper = new XmlHelper();
var theFeed;
var theBottomFeed;
var baseURL = "http://beta.video.msn.com/play/";
var feedURL = 'http://msnemx.msn.com/RssGenerator/RssAggregator.aspx?id=videoguide';
var alertTimerId = 0;
var inThis;
var thisID;
var queryVars = location.search ? location.search.substr(1).toLowerCase().split("&") : new Array();
for (var i = 0; i < queryVars.length; ++i)
{
    var aVar = queryVars[i].split("=");
    if(aVar[0] == "debug" && aVar[1] == "true")
    {
        //Insert test url
        feedURL = 'http://msnemx.msn.com/RssGenerator/RssAggregator.aspx?id=videoguide';
        debug = true;
    }    
}

function passFlashXML(passedXMLString)
{  
var myPat = /%5[c|C]/g;
var passedText = passedXMLString.replace(/%26/g,"&"); 
passedText = passedText.replace(myPat,"\\");   
theFeed = XmlHelper.getXmlDoc("string",passedText);

    if(theFeed.documentElement == null || theFeed.documentElement.getAttribute("failed") == null){
        location.href = "http://entertainment.msn.com";
        if(debug)
        {
            alert("Something is wrong with the feed");
        }     
    }
    if(theFeed.documentElement && Number(theFeed.documentElement.getAttribute("failed")) >= 2)
    {
        location.href = "http://entertainment.msn.com";
        if(debug)
        {
            alert("Number of groups failed: " + Number(theFeed.documentElement.getAttribute("failed")));
        }                     
    }     
}
 
function listenForRecommendations()
{
    var recHolder = document.getElementById("watchholder");
    var recBox = document.getElementById("recommendBox");             
    if(recHolder && recommendationChildren == recHolder.childNodes.length && recHolder.childNodes.length > 0 && recBox)
    {
        var nodeCount = (recHolder.childNodes.length <= 4) ? recHolder.childNodes.length : 4;
        for(x=0; x < nodeCount; x++)
        {
            var theHREF = recHolder.childNodes[x].childNodes[0].href;
            var theTitle = recHolder.childNodes[x].childNodes[0].childNodes[0].nodeValue;
            var formatedRec = formatRecommendations(theTitle,theHREF);
            recBox.appendChild(formatedRec);      
        }
        return;
    }
    recommendationChildren = recHolder.childNodes.length;
    setTimeout("listenForRecommendations()",100);
}

function sendUserFeedback()
{
    theAddress = "msnvfb@microsoft.com";
    theSubject = "MSN Video Guide User Feedback"
    theBody = "";
    theMailToLink = "mailto:" + theAddress + "?subject=" + theSubject + "&body=" + theBody;
    window.open(theMailToLink,"_self");    
}


function formatRecommendations(theText,theHREF)
{
    if(theText.length > 50){
        theText = theText.substr(0,47)+"...";
    }
    if(typeof theText == "undefined" || typeof theHREF == "undefined")
    {
        return false;
    }
    var holderDiv = document.createElement("div");
    holderDiv.className = "recommendItemContainer"; 
    holderDiv.onclick = function()
    {
        location.href = theHREF;
    };

    holderDiv.onmouseover = function()
    {
        this.style.backgroundColor = "#1c2126";
    }
    holderDiv.onmouseout = function()
    {
        this.style.backgroundColor = "transparent";
    }
           
    var leftDiv = document.createElement("div");
    leftDiv.className = "recommendItemContainerLeft";
    var leftDivImg = document.createElement("img");
    leftDivImg.src = "http://entimg.msn.com/i/VideoGuide/images/dropDownArrow.gif";
    leftDiv.appendChild(leftDivImg);
                        
    var rightDiv = document.createElement("div");
    rightDiv.className = "recommendItemContainerRight";                
    rightDiv.appendChild(document.createTextNode(theText));
            
    holderDiv.appendChild(leftDiv);
    holderDiv.appendChild(rightDiv);
    return holderDiv;    
}

function getTopSearches(containerID,groupID)
{
    if(typeof containerID == "undefined" || typeof groupID == "undefined")
    {
        return false;
    }
    if(typeof theFeed != "undefined")
    {
        if(debug)
        {
            getDebugDiv(containerID,groupID,"debugDivTopSearches");
        }          
        var returnedNodes = XmlHelper.selectNodes(theFeed.documentElement,"//group[@id='" + groupID + "']/item",null);    
        nodeCount = (returnedNodes.length > 18) ? 18 : returnedNodes.length;
        var columnArray = new Array(createColumn(0),createColumn(1),createColumn(2),createColumn(3),createColumn(4),createColumn(5));       
        var currentColumn = 0;
        for(x=0; x < nodeCount; x++)
        {            
            if(!returnedNodes[x].getElementsByTagName("title") || !returnedNodes[x].getElementsByTagName("link"))
            {                
                continue;      
            }
            var theTitle = returnedNodes[x].getElementsByTagName("title")[0].childNodes[0].nodeValue;
            var theLink;
            if(returnedNodes[x].getElementsByTagName("link")[0].childNodes.length<1){
                theLink = returnedNodes[x].getElementsByTagName("link")[0].getAttribute("url")+"&form=Video_Guide";
            }
            else{
                theLink = returnedNodes[x].getElementsByTagName("link")[0].childNodes[0].nodeValue+"&form=Video_Guide_Xrank";
            }           
            var linkDiv = document.createElement("div");
            linkDiv.className = "topSearchesLink";
            var theAnchor = document.createElement("a");
            theAnchor.href = theLink;
            theAnchor.appendChild(document.createTextNode(theTitle));
            linkDiv.appendChild(theAnchor);
             
            columnArray[currentColumn].appendChild(linkDiv);
            if(currentColumn == 5)
            {
                currentColumn = 0;
            }
            else
            {
                currentColumn++;
            }                      
        }
        for(y=0; y < columnArray.length; y++)
        {
            document.getElementById(containerID).appendChild(columnArray[y]);
        }
        return;    
    }
    setTimeout("getTopSearches('" + containerID + "','" + groupID + "')",100);    
}

function createColumn(x)
{
    var currentColumn = document.createElement("div");
    currentColumn.className = "topSearchColumn";
    currentColumn.id = "topSearchColumn" + x;
    return currentColumn;
}

function getImageAndList(imageContainerID,listContainerID,linkClass,groupID,howMany,tracking)
{   
   
    if(typeof imageContainerID == "undefined" || typeof listContainerID == "undefined" || typeof linkClass == "undefined" || typeof groupID == "undefined") 
    {
        return false;
    }
    howMany = (typeof howMany != "undefined") ? howMany : false;
    if(typeof theFeed != "undefined")
    {
        if(debug)
        {           
            getDebugDiv(listContainerID,groupID,"debugDivImageList");
        }  
        
        var returnedNodes = XmlHelper.selectNodes(theFeed.documentElement,"//group[@id='" + groupID + "']/item",null);
        if(returnedNodes != null && returnedNodes.length > 0)
        {            
            var nodeCount = (howMany && returnedNodes.length > howMany) ? howMany : returnedNodes.length;
            var ImageIncrement = 0;
            var imageID;
            for(x=0; x < nodeCount; x++)
            {
                if(!returnedNodes[x].getElementsByTagName("description") || !returnedNodes[x].getElementsByTagName("title") || !returnedNodes[x].getElementsByTagName("thumb") || !returnedNodes[x].getElementsByTagName("link"))
                {
                    ImageIncrement++;
                    continue;      
                }
                if(x == ImageIncrement)
                {
                    var imageAnchor = document.createElement("a");
                    imageAnchor.href = returnedNodes[x].getElementsByTagName("link")[0].getAttribute("url");
                    var theImage = document.createElement("img");
                    imageID = imageContainerID + "Img";
                    theImage.id = imageID;
                    theImage.src = returnedNodes[x].getElementsByTagName("thumb")[0].getAttribute("url");
                    imageAnchor.appendChild(theImage);
                    document.getElementById(imageContainerID).appendChild(imageAnchor);
                }                
                                
                var theTitle = limitStringLength(returnedNodes[x].getElementsByTagName("title")[0].childNodes[0].nodeValue,90);
                var theHREF;
                var guidList = returnedNodes[x].getElementsByTagName("id")[0].getAttribute("guid");
                var usePopUp = false;
                
                              
                 for(var i=0;i<returnedNodes.length;i++){
                       if(i != x && returnedNodes[i].getElementsByTagName("id")[0].getAttribute("guid").indexOf("youtube") == -1 && groupID != "mostpopulartv"){ 
                        guidList = guidList +","+ returnedNodes[i].getElementsByTagName("id")[0].getAttribute("guid");
                        }
                    }
                
                
                theHREF = baseURL + "?ocid=" + tracking + "&uuids=" + guidList;
                
                var theDescription = limitStringLength(returnedNodes[x].getElementsByTagName("description")[0].childNodes[0].nodeValue,140);
                                
                var navDiv = document.createElement("div");
                navDiv.className = "catLinkHolder";
                navDiv.id = "catLinkHolder" + listContainerID + x;
                
                var playButtonDiv = document.createElement("div");
                playButtonDiv.className = "catLinkPlayButtonDiv";
                playButtonDiv.id = "catLinkPlayButtonDiv" + listContainerID + x;
                playButtonDiv.style.display = "none";
                
                var playButton = document.createElement("img");
                playButton.id = "catLinkPlayButton" + listContainerID + x;                
                playButton.src = "http://entimg.msn.com/i/VideoGuide/images/dropDownArrow.gif";
                
                var navDivBottom = document.createElement("div");
                navDivBottom.className = "catLinkBottom";
                navDivBottom.id = "catLinkBottom" + listContainerID + x;
                navDivBottom.style.display = "none";
                                               
                
                var theLink = document.createElement("div");
                theLink.className = "catLink";
                theLink.data = new Array(listContainerID + x,theHREF,imageID,returnedNodes[x].getElementsByTagName("thumb")[0].getAttribute("url"),guidList);
                theLink.onclick = function()
                {
                    location.href = this.data[1];
                    
                };
                                             
                function delayOn(){
                   
                   document.getElementById("catLinkBottom" + inThis.data[0]).style.display = "block"; 
                   document.getElementById(inThis.data[2]).src = inThis.data[3];
                   document.getElementById(inThis.data[2]).parentNode.href = inThis.data[1];
                }
                
                theLink.onmouseover = function()
                {
                    inThis = this;
                    inThis.style.backgroundColor = "#1c2126";
                    document.getElementById("catLinkPlayButtonDiv" + inThis.data[0]).style.display = "block";
                    alertTimerId = setTimeout(delayOn,650);
                };
                theLink.onmouseout = function()
                {
                    clearTimeout(alertTimerId);
                    document.getElementById("catLinkPlayButtonDiv" + this.data[0]).style.display = "none";
                    document.getElementById("catLinkBottom" + this.data[0]).style.display = "none";
                    this.style.backgroundColor = "transparent";
                };
                
                playButtonDiv.appendChild(playButton);                
                navDivBottom.appendChild(document.createTextNode(theDescription));
                theLink.appendChild(document.createTextNode(theTitle));
                navDiv.appendChild(playButtonDiv);
                navDiv.appendChild(theLink);
                navDiv.appendChild(navDivBottom); 
                       
                
                document.getElementById(listContainerID).appendChild(navDiv);                                   
            }            
        }
        return;   
    }
    setTimeout("getImageAndList('" + imageContainerID + "','" + listContainerID + "','" + linkClass + "','" + groupID + "','" + howMany + "')",100);    
}

function getList(containerID,linkClass,groupID,howMany,listCutoff,tracking)
{
    if(typeof containerID == "undefined" || typeof linkClass == "undefined" || typeof groupID == "undefined")
    {
        return false;
    }
    howMany = (typeof howMany != "undefined") ? howMany : false;
    listCutoff = (typeof listCutoff != "undefined") ? listCutoff : false;
    if(typeof theFeed != "undefined")
    {
        if(debug)
        {
            getDebugDiv(containerID,groupID,"debugDivTopList");
        }        
        var returnedNodes = XmlHelper.selectNodes(theFeed.documentElement,"//group[@id='" + groupID + "']/item",null);
        if(returnedNodes != null && returnedNodes.length > 0)
        {
            var nodeCount = (howMany && returnedNodes.length > howMany) ? howMany : returnedNodes.length;
            for(x=0; x < nodeCount; x++)
            {
                if(!returnedNodes[x].getElementsByTagName("title") || !returnedNodes[x].getElementsByTagName("link") || !returnedNodes[x].getElementsByTagName("description"))
                {
                    continue;      
                }
                var theTitle = returnedNodes[x].getElementsByTagName("title")[0].childNodes[0].nodeValue;
                if(groupID == "mostpopulartv"){
                    theTitle = "'"+returnedNodes[x].getElementsByTagName("series")[0].getAttribute("title")+"': "+returnedNodes[x].getElementsByTagName("episode")[0].getAttribute("title");
                }
                if(theTitle.length > 45){
                        theTitle = theTitle.substr(0,45)+" ...";
                }
                
                var theHREF;
                var guidList = returnedNodes[x].getElementsByTagName("id")[0].getAttribute("guid");
                                
                for(var i=0;i<returnedNodes.length;i++){
                       if(i != x && returnedNodes[i].getElementsByTagName("id")[0].getAttribute("guid").indexOf("youtube") == -1 && groupID != "mostpopulartv"){ 
                        guidList = guidList +","+ returnedNodes[i].getElementsByTagName("id")[0].getAttribute("guid");
                        }
                    }
            
                theHREF = baseURL + "?ocid=vgtop" + "&uuids=" + guidList;
                
                var theDescription;
                if(returnedNodes[x].getElementsByTagName("description")[0].childNodes.length == 0){
                    theDescription = "";}
                else{
                    theDescription = limitStringLength(returnedNodes[x].getElementsByTagName("description")[0].childNodes[0].nodeValue,140);
               }
                
                
                var theImage = returnedNodes[x].getElementsByTagName("thumb")[0].getAttribute("url");
                
                var navDiv = document.createElement("div");
                navDiv.className = "topLinkHolder";
                navDiv.id = "topLinkHolder" + containerID + x;
                
                var playButtonDiv = document.createElement("div");
                playButtonDiv.className = "topLinkPlayButtonDiv";
                playButtonDiv.id = "topLinkPlayButtonDiv" + containerID + x;
                playButtonDiv.style.display = "none";
                
                var playButton = document.createElement("img");
                playButton.id = "topLinkPlayButton" + containerID + x;                
                playButton.src = "http://entimg.msn.com/i/VideoGuide/images/dropDownArrow.gif";
                
                var navDivBottom = document.createElement("div");
                navDivBottom.className = "topLinkBottom";
                navDivBottom.id = "topLinkBottom" + containerID + x;
                navDivBottom.style.display = "none";
                
                var navDivBottomLeft = document.createElement("div");
                navDivBottomLeft.className = "topLinkBottomLeft";
                if(groupID == "topboxofficemovies"){
                navDivBottomLeft.className = "topLinkBottomLeftMovie";
                }
                
               
                navDivBottomLeft.id = "topLinkBottomLeft" + containerID + x;
                
                var navDivBottomLeftImg = document.createElement("img");
                navDivBottomLeftImg.src = theImage;
                                
                var navDivBottomRight = document.createElement("div");
                navDivBottomRight.className = "topLinkBottomRight";
                navDivBottomRight.id = "topLinkBottomRight" + containerID + x;
                                
                var theLink = document.createElement("div");
                theLink.className = "topLink";
                theLink.data = new Array(containerID + x,theHREF,guidList);
                theLink.onclick = function()
                {
                      
                     location.href = this.data[1];
                    
                };
                
                function delayListOn(){
                   document.getElementById("topLinkBottom" + inThis.data[0]).style.display = "block";
                }
                
                theLink.onmouseover = function()
                {
                    inThis = this;
                    inThis.style.backgroundColor = "#1c2126";
                    document.getElementById("topLinkPlayButtonDiv" + inThis.data[0]).style.display = "block";
                    alertTimerId = setTimeout(delayListOn,650);
                };
                theLink.onmouseout = function()
                {
                    clearTimeout(alertTimerId);
                    document.getElementById("topLinkPlayButtonDiv" + this.data[0]).style.display = "none";
                    document.getElementById("topLinkBottom" + this.data[0]).style.display = "none";
                    this.style.backgroundColor = "transparent";
                };
                
                playButtonDiv.appendChild(playButton);                
                navDivBottomLeft.appendChild(navDivBottomLeftImg);
                navDivBottomRight.appendChild(document.createTextNode(theDescription));
                navDivBottom.appendChild(navDivBottomLeft);
                navDivBottom.appendChild(navDivBottomRight);
                theLink.appendChild(document.createTextNode(theTitle));
                navDiv.appendChild(playButtonDiv);
                navDiv.appendChild(theLink);
                navDiv.appendChild(navDivBottom);                 
                                               
                if(listCutoff && x > (listCutoff - 1))
                {
                    navDiv.style.display = "none";
                }               
                                             
                document.getElementById(containerID).data = listCutoff;
                document.getElementById(containerID).appendChild(navDiv);
            }                 
        }
        return;
    }
    setTimeout("getList('" + containerID + "','" + linkClass + "','" + groupID + "','" + howMany + "','" + listCutoff + "')",100);              
}

function getRolloverDiv(theID,theTitle,theHREF,theDescription,theImage)
{
    if(typeof theID == "undefined" || typeof theTitle == "undefined" || typeof theHREF == "undefined" || typeof theDescription == "undefined" || typeof theImage == "undefined")
    {
        return false;
    }
    var holderDiv = document.createElement("div");
    var linkHolder = document.createElement("div");
    var hoverHolder = document.createElement("div");
    
}

function showOrHideListCutoff(containerIDArray,displayCSSValue,hideThis,showThis)
{
    if(typeof containerIDArray == "undefined" || typeof displayCSSValue == "undefined")
    {
        return false;
    }
    if(typeof hideThis != "undefined")
    {
        document.getElementById(hideThis).style.display = "none";        
    }
    if(typeof showThis != "undefined")
    {
        document.getElementById(showThis).style.display = blockOrTable();
    }
    for(i=0; i < containerIDArray.length; i++)
    {
        var theContainer = document.getElementById(containerIDArray[i]);
        for(x=theContainer.data; x < theContainer.childNodes.length; x++)
        {
            theContainer.childNodes[x].style.display = displayCSSValue;
        }
    }    
}

function getDebugDiv(parentButtonID,groupID,theClass)
{   
    var theParent = document.getElementById(parentButtonID);
       
    var debugDiv = document.createElement("div");
    debugDiv.className = theClass;
    debugDiv.appendChild(document.createTextNode(groupID));
    
    theParent.insertBefore(debugDiv,theParent.childNodes[0]);
}

function getNavList(containerID,parentButtonID,groupID,howMany)

{   
  
    if(typeof containerID == "undefined" || typeof parentButtonID == "undefined" || typeof groupID == "undefined")
    {
        return false;
    }   
    
    howMany = (typeof howMany != "undefined") ? howMany : false;    
    if(typeof theFeed != "undefined")
    {    
        if(debug)
        {
            getDebugDiv(parentButtonID,groupID,"debugDivNav");
        }
        var returnedNodes = XmlHelper.selectNodes(theFeed.documentElement,"//group[@id='" + groupID + "']/item",null);        
        
        
        if(returnedNodes != null && returnedNodes.length > 0)
        {
            var nodeCount = (howMany && returnedNodes.length > howMany) ? howMany : returnedNodes.length;
            for(x=0; x < nodeCount; x++)
            {
                if(!returnedNodes[x].getElementsByTagName("title") || !returnedNodes[x].getElementsByTagName("link") || !returnedNodes[x].getElementsByTagName("description") || !returnedNodes[x].getElementsByTagName("thumb"))
                {
                    continue;      
                }                
                var usePopUp = false;
                if(returnedNodes[x].getElementsByTagName("link")[0].getAttribute("url").indexOf("youtube") == -1){
                    usePopUp = true;
                }
               
                var theHREF;
                var guidList = returnedNodes[x].getElementsByTagName("id")[0].getAttribute("guid");
                var theAnchor = document.createElement("a");
                theAnchor.className = "altlink";
                          
                for(var i=0;i<returnedNodes.length;i++){
                       if(i != x && returnedNodes[i].getElementsByTagName("id")[0].getAttribute("guid").indexOf("youtube") == -1){ 
                            guidList = guidList +","+ returnedNodes[i].getElementsByTagName("id")[0].getAttribute("guid");
                        }
                }
                
                theHREF = baseURL + "?ocid=vgnav" + "&uuids=" + guidList;
                theAnchor.data = new Array(returnedNodes[x].getElementsByTagName("link")[0].getAttribute("url"),guidList,groupID,"Video_Guide_Nav",theHREF);
                
                theAnchor.onclick = function(){

                    if(this.data[0].indexOf("youtube") == -1){
                        location.href = this.data[4];
                    }
                    else{
                        playViral(this.data[0]);
                    }
                }              
              
                
                
	            var containerDiv = document.createElement("div");
 	            containerDiv.id = "ddItemContainer" + containerID + x;
                containerDiv.className = "outerItemContainer";                
                containerDiv.data = new Array(containerID,x);

              function delayNavOn(){
                    inThis.style.height = "95px";
              };
              
              containerDiv.onmouseover = function()
              {
                    inThis = this;
                    inThis.style.backgroundColor = "#262c31";
                    alertTimerId = setTimeout(delayNavOn,650);
               };
                
              containerDiv.onmouseout = function()
              {
                   clearTimeout(alertTimerId);
                   this.style.height = "20px";
                   this.style.backgroundColor = "transparent";
              };                    
  
	          var titleDiv = document.createElement("div");
              titleDiv.id = "ddItem" + containerID + x;
              titleDiv.className = "dropDownItemContainer";                
              titleDiv.data = new Array(containerID,x);
                
      
	  	 	
                                             
                var titleLeftDiv = document.createElement("div");
                titleLeftDiv.className = "dropDownItemContainerLeft";
                var titleLeftImg = document.createElement("img");
                titleLeftImg.src = "http://entimg.msn.com/i/VideoGuide/images/dropDownArrow.gif";
                titleLeftDiv.appendChild(titleLeftImg);
                
                var titleRightDiv = document.createElement("div");
                titleRightDiv.className = "dropDownItemContainerRight";                
                var titleText = limitStringLength(returnedNodes[x].getElementsByTagName("title")[0].childNodes[0].nodeValue,45);
                titleRightDiv.appendChild(document.createTextNode(titleText));
                                
                titleDiv.appendChild(titleLeftDiv);
                titleDiv.appendChild(titleRightDiv);
	            containerDiv.appendChild(titleDiv);	
               
                
                var dropDownDiv = document.createElement("div");
                dropDownDiv.id = "ddItemOver" + containerID + x;
                dropDownDiv.className = "dropDownItemOverContainer";
                                   
                
                var dropDownLeft = document.createElement("div");
                dropDownLeft.id = "ddItemOverL" + containerID + x;
                dropDownLeft.className = "dropDownItemOverContainerLeft";
                
                var dropDownThumb = document.createElement("img");
                dropDownThumb.src = returnedNodes[x].getElementsByTagName("thumb")[0].getAttribute("url");                
                dropDownLeft.appendChild(dropDownThumb);
                
                var dropDownRight = document.createElement("div");
                dropDownRight.id = "ddItemOverR" + containerID + x;
                dropDownRight.className = "dropDownItemOverContainerRight";                
                var descriptionText = limitStringLength(returnedNodes[x].getElementsByTagName("description")[0].childNodes[0].nodeValue,130);
                                
                dropDownRight.appendChild(document.createTextNode(descriptionText));                
                dropDownDiv.appendChild(dropDownLeft);
                dropDownDiv.appendChild(dropDownRight); 
 
	            containerDiv.appendChild(dropDownDiv);  
 	            theAnchor.appendChild(containerDiv);              
                document.getElementById(containerID).appendChild(theAnchor);
            }       
        }        
        return;
    }
    setTimeout("getNavList('" + containerID + "','" + parentButtonID + "','" + groupID + "','" + howMany + "')",100);      
}

function limitStringLength(theString,stringLength)
{
    if(typeof theString == "undefined" || typeof stringLength == "undefined")
    {
        return false;
    }    
    if(theString.length > stringLength)
    {
        return theString.substr(0,(stringLength - 4));        
    }
    else
    {
        return theString;
    }    
}

function rssHeaderSwap(overOrOut)
{
    if(typeof overOrOut == "undefined" || !document.getElementById("rssSubscribeButtonOver") || !document.getElementById("rssSubscribeButtonOut"))
    {
        return false;
    }   
    if(overOrOut)
    {
        document.getElementById("rssSubscribeButtonOver").style.display = blockOrTable();
        document.getElementById("rssSubscribeButtonOut").style.display = "none";       
    }
    else
    {
        document.getElementById("rssSubscribeButtonOut").style.display = blockOrTable();
        document.getElementById("rssSubscribeButtonOver").style.display = "none";
    }    
}

function getRSSList(containerID)
{
    if(typeof containerID == "undefined")
    {
        return false;
    }        
    var theContainer = document.getElementById(containerID);
    if(typeof theFeed != "undefined")
    {        
        var rssListItem1 = formatRSSListItem("Most Watched","mostpopular");        
        theContainer.appendChild(rssListItem1);
        var rssListItem2 = formatRSSListItem("Most Commented","mostcommented");        
        theContainer.appendChild(rssListItem2);
        var rssListItem3 = formatRSSListItem("Must-See Viral","topviral");        
        theContainer.appendChild(rssListItem3);
        var rssListItem4 = formatRSSListItem("Celebrity Buzz","mostwatchedcelebrity");        
        theContainer.appendChild(rssListItem4);
        var rssListItem5 = formatRSSListItem("Popular User Video","viralmix");        
        theContainer.appendChild(rssListItem5);
        var rssListItem6 = formatRSSListItem("Top TV","mostpopulartv");        
        theContainer.appendChild(rssListItem6);
        var rssListItem7 = formatRSSListItem("Top Movies","topboxofficemovies");        
        theContainer.appendChild(rssListItem7);
        var rssListItem8 = formatRSSListItem("Top Music","topmusicvideos");        
        theContainer.appendChild(rssListItem8);
        return;
    }
    setTimeout("getRSSList('" + containerID + "')",100); 
}

function formatRSSListItem(rssTitle,groupID)
{
    var rssLink = XmlHelper.selectNodes(theFeed.documentElement,"//group[@id='"+ groupID +"']/rsslink/@url",null);
    if(rssLink != null && rssLink[0])
    {
        var containerDiv = document.createElement("div");
        containerDiv.id = rssTitle + "RSSLink";
        containerDiv.className = "rssListItem";
        containerDiv.style.display = blockOrTable();
        containerDiv.appendChild(document.createTextNode(rssTitle));
        containerDiv.onmouseover = function()
        {
            this.style.backgroundColor = "#393e43";
        }
        containerDiv.onmouseout = function()
        {
            this.style.backgroundColor = "transparent";
        }   
        containerDiv.data = rssLink[0].nodeValue;
        containerDiv.onclick = function()
        {
            window.location.href = this.data;
        }
        return containerDiv;
    }
    else
    {
        return false;
    }
}

function blockOrTable()
{
    var blockOrTable = (navigator.appName.toLowerCase().indexOf("microsoft internet explorer") > -1) ? "block" : "table";
    return blockOrTable;
}

function openFirstListItem(whichID)
{   
    if(document.getElementById("ddItem" + whichID + 0) && document.getElementById("ddItemOver" + whichID + 0))
    {
        //document.getElementById("ddItem" + whichID + 0).style.backgroundColor = "#262c31";
        //document.getElementById("ddItemOver" + whichID + 0).style.display = blockOrTable();
    }
}

function hideFirstListItem(whichID)
{   
    if(document.getElementById("ddItem" + whichID + 0) && document.getElementById("ddItemOver" + whichID + 0))
    {
        //document.getElementById("ddItem" + whichID + 0).style.backgroundColor = "transparent";
        //document.getElementById("ddItemOver" + whichID + 0).style.display = blockOrTable();
    }
}

function viewDropDown(whichID,whichButton,whatColor)
{  
    if(typeof whichButton != "undefined" && typeof whatColor != "undefined")
    {        
        document.getElementById(whichButton).style.backgroundColor = whatColor;
    }
    document.getElementById(whichID).style.display = blockOrTable();
    
}    



function hideDropDown(whichID,whichButton,whatColor)
{       
   if(typeof whichButton != "undefined" && typeof whatColor != "undefined")
    {
        document.getElementById(whichButton).style.backgroundColor = whatColor;
    }
    document.getElementById(whichID).style.display="none"  
    
}

function formatPageFooter()
{   	
    if(document.body && document.body.childNodes && document.body.getElementsByTagName("div")[0] && document.body.getElementsByTagName("div")[0].childNodes && document.getElementById("microsoftLogo"))
	{   	
	    var pageContentDiv = document.body.getElementsByTagName("div")[0];        
        if(pageFooterChildren == pageContentDiv.childNodes.length)
        {                
            for(n=0; n < pageContentDiv.childNodes.length; n++)
            {            
		        if(pageContentDiv.childNodes[n].className == "pageFooter_control")
		        {		            
		            document.getElementById("microsoftLogo").src = "http://entimg.msn.com/i/VideoGuide/images/MicrosoftRules.gif";
		            document.getElementById("microsoftLogo").style.display = "block";
		            var theFooter = pageContentDiv.childNodes[n];   		                
		            var footerInsideDiv = document.createElement("div");		            
		            footerInsideDiv.id = "footerInsideDiv";		        
		            footerInsideDiv.style.width = "874px";
		            footerInsideDiv.style.height = "100px";
		            footerInsideDiv.style.overflow = "hidden";
		            footerInsideDiv.style.marginLeft = "auto";
		            footerInsideDiv.style.marginRight = "auto";
    		        
		            var theFooterTemp = theFooter.cloneNode(true);
		            footerInsideDiv.innerHTML = theFooterTemp.innerHTML;
		            theFooter.innerHTML = "";
		            theFooter.appendChild(footerInsideDiv);	        
    		        
		            return;
		        }
            }
        }
        pageFooterChildren = pageContentDiv.childNodes.length;                        				
	}      
	var formatPageFooterTO = setTimeout("formatPageFooter()",100);				
}

function addLiveSearchMSNDomain()
{
    document.getElementById("videoSearchInput").value += " site:msn.com";
    return true;
}

function formatPageHeader()
{
    if(document.getElementById("pageHeaderMenu") && document.getElementById("pageHeaderMenu").childNodes && document.getElementById("pageHeaderSearch") && document.getElementById("pageHeaderSearch").childNodes && document.getElementById("verticalLogo"))
    {    
       if(pageHeaderMenuChildren == document.getElementById("pageHeaderMenu").childNodes.length && pageHeaderSearchChildren == document.getElementById("pageHeaderSearch").childNodes.length)
       {       
           var pageHeaderMenu = document.getElementById("pageHeaderMenu");
           pageHeaderMenu.removeChild(pageHeaderMenu.childNodes[1]);
           var pageHeaderSearch = document.getElementById("pageHeaderSearch");
           var pageHeader = pageHeaderMenu.parentNode.parentNode;
           var headerContainer = pageHeaderMenu.parentNode;
           var verticalLogo = document.getElementById("verticalLogo");
           var searchDiv = pageHeaderSearch.childNodes[1];
           searchDiv.innerHTML = "";           
           var bucketLinks = pageHeaderMenu.childNodes[0];
           
           var channelLinks = bucketLinks.childNodes;
           for(var r=0; r < channelLinks.length; r++)
           {
                var link = channelLinks[r].getElementsByTagName("a")[0]
                var textId = link.innerHTML;
               
                if(link.id != "ctl00_moreButton_contentModule")
                {
                    if(textId.indexOf("entertainment") > -1)
                    {
                        link.href = "http://entertainment.msn.com/";
                    }
                    if(textId.indexOf("movies") > -1)
                    {
                        link.href = "http://movies.msn.com/";
                    }
                    if(textId.indexOf("music") > -1)
                    {
                        link.href = "http://music.msn.com/";
                    }
                    if(textId.indexOf("tv") > -1)
                    {
                        link.href = "http://tv.msn.com/";
                    }
                }                  
           }
                                          
           pageHeader.style.backgroundColor = "#111112";
           pageHeader.style.backgroundImage = "url(http://entimg.msn.com/i/VideoGuide/images/headBack.jpg)";
           pageHeader.style.backgroundRepeat = "repeat-x";
           pageHeader.style.backgroundPosition = "bottom center";
           
           headerContainer.style.width = "972px";
           headerContainer.style.height = "143px";
           headerContainer.style.marginLeft = "auto";
           headerContainer.style.marginRight = "auto";
                  
           pageHeaderMenu.style.border = "none";
           pageHeaderMenu.style.height = "25px";
           pageHeaderMenu.style.width = "963px";
           pageHeaderMenu.style.paddingLeft = "9px";
           pageHeaderMenu.style.paddingTop = "10px";             
           
           pageHeaderSearch.className = "";
           pageHeaderSearch.style.border = "none";
           pageHeaderSearch.style.height = "108px";
           pageHeaderSearch.style.width = "972px";
           pageHeaderSearch.style.margin = "0px";
           pageHeaderSearch.style.padding = "0px";       
           
           verticalLogo.className = "";
           verticalLogo.childNodes[0].childNodes[0].src = "http://entimg.msn.com/i/VideoGuide/images/msnVideoLogo.gif";
           verticalLogo.removeChild(verticalLogo.childNodes[1]);
           verticalLogo.style.width = "456px";
           verticalLogo.style.height = "67px";
           verticalLogo.style.margin = "0px";
           verticalLogo.style.paddingLeft = "30px";
           verticalLogo.style.paddingTop = "41px";
           verticalLogo.style.paddingRight = "0px";
           verticalLogo.style.paddingBottom = "0px";       
           verticalLogo.style.overflow = "hidden";
           document.getElementById("msnLogo").style.display = "block";
           document.getElementById("msnLogo").useMap = "#msnVideoLogo_Map"
           //document.getElementById("msnLogo").parentNode.href = "http://videoguide.msn.com";
                  
           searchDiv.className = "";
           searchDiv.id = "searchDiv";         
           searchDiv.style.width = "386px";
           searchDiv.style.height = "83px";
           searchDiv.style.margin = "0px";
           searchDiv.style.paddingLeft = "100px";
           searchDiv.style.paddingTop = "25px";
           searchDiv.style.overflow = "hidden";
                                    
           var searchDivTop = document.createElement("div");
           searchDivTop.id = "searchDivTop";          
           
           var searchNavMSNHome = document.createElement("div");
           searchNavMSNHome.id = "searchNavMSNHome";
           searchNavMSNHome.className = "searchNavLink";
           searchNavMSNHomeA = document.createElement("a");
           searchNavMSNHomeA.href = "http://www.msn.com";           
           searchNavMSNHomeA.appendChild(document.createTextNode("MSN\u00a0Home"));
           searchNavMSNHome.appendChild(searchNavMSNHomeA);
           
           var searchNavDivide = document.createElement("div");
           searchNavDivide.className = "searchNavDivide";           
           searchNavDivide.appendChild(document.createTextNode("|"));
           
           var searchNavMail = document.createElement("div");
           searchNavMail.id = "searchNavMail";
           searchNavMail.className = "searchNavLink";
           searchNavMailA = document.createElement("a");
           searchNavMailA.href = "http://hotmail.msn.com";          
           searchNavMailA.appendChild(document.createTextNode("Mail"));
           searchNavMail.appendChild(searchNavMailA);
           
           var searchNavDivide2 = document.createElement("div");
           searchNavDivide2.className = "searchNavDivide";          
           searchNavDivide2.appendChild(document.createTextNode("|"));
           
           var searchNavMyMSN = document.createElement("div");
           searchNavMyMSN.id = "searchNavMyMSN";
           searchNavMyMSN.className = "searchNavLink";
           searchNavMyMSNA = document.createElement("a");
           searchNavMyMSNA.href = "http://my.msn.com";          
           searchNavMyMSNA.appendChild(document.createTextNode("My\u00a0MSN"));
           searchNavMyMSN.appendChild(searchNavMyMSNA);
           
           searchDivTop.appendChild(searchNavMSNHome);
           searchDivTop.appendChild(searchNavDivide);
           searchDivTop.appendChild(searchNavMail);
           searchDivTop.appendChild(searchNavDivide2);
           searchDivTop.appendChild(searchNavMyMSN);           
                                 
           var searchDivBottom = document.createElement("div");
           searchDivBottom.id = "searchDivBottom";          
                     
           var videoSearchForm = document.createElement("form");
           videoSearchForm.id = "videoSearchForm";           
           videoSearchForm.action = "http://search.live.com/video/results.aspx";
           var videoSearchDiv = document.createElement("div");
           videoSearchDiv.id = "videoSearchDiv";
           var videoSearchInputBack = document.createElement("div");
           videoSearchInputBack.id = "videoSearchInputBack";
           var videoSearchInput = document.createElement("input");
           videoSearchInput.id = "videoSearchInput";
           videoSearchInput.name = "q";
           var videoSearchSubmit = document.createElement("input");
           videoSearchSubmit.id = "videoSearchSubmit";
           videoSearchSubmit.type = "submit";
           videoSearchSubmit.value = "";
           videoSearchSubmit.onclick = function()
           {
                return addLiveSearchMSNDomain();
           }
           
           videoSearchInputBack.appendChild(videoSearchInput);
           videoSearchDiv.appendChild(videoSearchInputBack);
           videoSearchDiv.appendChild(videoSearchSubmit);           
           videoSearchForm.appendChild(videoSearchDiv);
           searchDivBottom.appendChild(videoSearchForm);           
           
           searchDiv.appendChild(searchDivTop);
           searchDiv.appendChild(searchDivBottom);      
           
           return;
        }
        pageHeaderMenuChildren = document.getElementById("pageHeaderMenu").childNodes.length; 
        pageHeaderSearchChildren = document.getElementById("pageHeaderSearch").childNodes.length;       
    }
    var formatPageHeaderTO = setTimeout("formatPageHeader()",100);
}

function addEvent(element, type, handler) {
	if (element.addEventListener) {
		element.addEventListener(type, handler, false);
	} else {
		
		if (!handler.$$guid) handler.$$guid = addEvent.guid++;
		
		if (!element.events) element.events = {};
		
		var handlers = element.events[type];
		if (!handlers) {
			handlers = element.events[type] = {};
			
			if (element["on" + type]) {
				handlers[0] = element["on" + type];
			}
		}
		
		handlers[handler.$$guid] = handler;
		
		element["on" + type] = handleEvent;
	}
};

addEvent.guid = 1;

function removeEvent(element, type, handler) {
	if (element.removeEventListener) {
		element.removeEventListener(type, handler, false);
	} else {
		
		if (element.events && element.events[type]) {
			delete element.events[type][handler.$$guid];
		}
	}
};

function handleEvent(event) {
  var returnValue = true;
  
  event = event || fixEvent(window.event);
  
  var handlers = this.events[event.type];
  
  for (var i in handlers) {
    this.$$handleEvent = handlers[i];
    if (this.$$handleEvent(event) === false) {
      returnValue = false;
    }
  }
  return returnValue;
};

function fixEvent(event) {
  
  event.preventDefault = fixEvent.preventDefault;
  event.stopPropagation = fixEvent.stopPropagation;
  return event;
};
fixEvent.preventDefault = function() {
  this.returnValue = false;
};
fixEvent.stopPropagation = function() {
  this.cancelBubble = true;
};