﻿    
    var mouseoverTimer = null;
    var TargetProductID;
    
    function _setLocation(x, y)
    {
        Sys.UI.DomElement.setLocation($get(this.ClientID), parseInt(x), parseInt(y));        
    }
    
    
    
    function Topic(strText, strID, strClientID, strFloatBehavior, strTopicHighlightBehavior, strSubTopicHightlightBehavior, strTopicSelectBehavior, strTopicSelectChildBehavior
    , strSubTopicSelectBehavior, strSubTopicSelectParentBehavior, strZoomBehavior, strZoomOutBehavior, strDefaultBehavior, strTopicIntroBehavior, strExtHighBehavior) 
    {
        //property that stores the radius 
        this.Text=strText;
        this.TopicID=strID;
        this.ClientID=strClientID;
        this.SubTopics = null;
        this.SubTopicObjects = null;
        this.RelatedProducts = null;
        this.RelatedProductsDescs = null;
        this.RelatedProductsBoxShots = null;
        this.CTAsProductIDs = null;
        this.CTAsType = null;
        this.CTAsText = null;
        this.CTAsTracking = null;
        this.CTAsURL = null;
        this.CTAsOpen = null;
        this.State = 'NORMAL'; 
        this.OriginalX = 0;
        this.OriginalY = 0;
        
        this.FloatBehavior = strFloatBehavior; 
        this.TopicHighlightBehavior = strTopicHighlightBehavior;                   
        this.SubTopicHighlightBehavior = strSubTopicHightlightBehavior;  
        
        this.TopicSelectBehavior = strTopicSelectBehavior;
        this.TopicSelectChildBehavior = strTopicSelectChildBehavior;
        this.SubTopicSelectBehavior = strSubTopicSelectBehavior;
        this.SubTopicSelectParentBehavior = strSubTopicSelectParentBehavior;
        this.ZoomBehavior = strZoomBehavior;
        this.ZoomOutBehavior = strZoomOutBehavior;
        this.DefaultBehavior = strDefaultBehavior;
        this.TopicIntroBehavior = strTopicIntroBehavior;
        this.ExternalHighlightBehavior = strExtHighBehavior;
        
        this.AnimationObjectsFound = false;
        
        
        this.State = "STARTUP";
        
        this.SavePosition = function () { this.OriginalX = this.GetBounds().x; this.OriginalY=this.GetBounds().y;};
        
        this.RestorePosition = function () 
        {           
            var bounds = this.GetBounds();
            
            if((Math.abs(bounds.x-this.OriginalX) >= 3 ||
               Math.abs(bounds.y-this.OriginalY) >= 3) && this.State != "SELECTED" && this.State != "HIGHLIGHT")
            {
               //this.StopFloat();
               //this.setLocation(this.OriginalX-400, this.OriginalY-200);
               //this.PlayFloat();
            }            
        }
                 
        this.addSubTopic = function (iTopicID)
        {
            if (this.SubTopics == null) 
            {
                this.SubTopics = new Array(1);
                this.SubTopicObjects = new Array(1);
                this.SubTopics[0] = iTopicID;
                this.SubTopicObjects[0] = GetTopicById(iTopicID);                    
            }
            else 
            {
                this.SubTopics[this.SubTopics.length] = iTopicID;
                this.SubTopicObjects[this.SubTopicObjects.length] = GetTopicById(iTopicID);
            }
        };
        
        this.addRelatedProduct = function (iProductID, ProductDesc, ProductBoxShot)
        {
            if(this.RelatedProducts == null)
            {
                this.RelatedProducts = new Array(1);
                this.RelatedProductsDescs = new Array(1);
                this.RelatedProductsBoxShots = new Array(1);
                this.RelatedProducts[0] = iProductID;
                this.RelatedProductsDescs[0] = ProductDesc;
                this.RelatedProductsBoxShots[0] = ProductBoxShot;
            }
            else
            {                
                this.RelatedProducts[this.RelatedProducts.length] = iProductID;
                this.RelatedProductsDescs[this.RelatedProductsDescs.length] = ProductDesc;
                this.RelatedProductsBoxShots[this.RelatedProductsBoxShots.length] = ProductBoxShot;
            }
        };
        
        this.InitAnimationObjects = function ()
        {
            if (this.AnimationObjectsFound == false) 
            {
                this.DefaultAnimation = $find(this.DefaultBehavior).get_OnClickBehavior().get_animation();
                //this.FloatAnimation = $find(this.FloatBehavior).get_OnClickBehavior().get_animation();
                this.ExternalAnimation = $find(this.ExternalHighlightBehavior).get_OnClickBehavior().get_animation();
                this.TopicHighlightAnimation = $find(this.TopicHighlightBehavior).get_OnClickBehavior().get_animation();
                this.SubTopicHighlightAnimation = $find(this.SubTopicHighlightBehavior).get_OnClickBehavior().get_animation();
                this.SubTopicSelectParentAnimation = $find(this.SubTopicSelectParentBehavior).get_OnClickBehavior().get_animation();
                this.ZoomAnimation = $find(this.ZoomBehavior).get_OnClickBehavior().get_animation();
                this.ZoomOutAnimation = $find(this.ZoomOutBehavior).get_OnClickBehavior().get_animation();
                this.TopicIntroAnimation = $find(this.TopicIntroBehavior).get_OnClickBehavior().get_animation();
                this.TopicSelectAnimation = $find(this.TopicSelectBehavior).get_OnClickBehavior().get_animation();
                this.TopicSelectChildAnimation = $find(this.TopicSelectChildBehavior).get_OnClickBehavior().get_animation()
                this.SubTopicSelectAnimation = $find(this.SubTopicSelectBehavior).get_OnClickBehavior().get_animation();
                this.AnimationObjectsFound = true;
            }
        }
        
        this.StopAllAnimations = function ()
        {
            
                this.DefaultAnimation.stop();
                //this.FloatAnimation = $find(this.FloatBehavior).get_OnClickBehavior().get_animation();
                this.ExternalAnimation.stop();
                this.TopicHighlightAnimation.stop();
                this.SubTopicHighlightAnimation.stop();
                this.SubTopicSelectParentAnimation.stop();
                this.ZoomAnimation.stop();
                this.ZoomOutAnimation.stop();
                this.TopicIntroAnimation.stop();
                this.TopicSelectAnimation.stop();
                this.TopicSelectChildAnimation.stop();
                this.SubTopicSelectAnimation.stop();
                this.AnimationObjectsFound = true;
            
        }
        
        this.AnimationsPlaying = function ()
        {
            
                if (this.DefaultAnimation.isPlaying ||
                    this.ExternalAnimation.isPlaying ||
                    this.TopicHighlightAnimation.isPlaying ||
                    this.SubTopicHighlightAnimation.isPlaying ||
                    this.SubTopicSelectParentAnimation.isPlaying ||
                    this.ZoomAnimation.isPlaying ||
                    this.ZoomOutAnimation.isPlaying ||
                    this.TopicIntroAnimation.isPlaying ||
                    this.TopicSelectAnimation.isPlaying ||
                    this.TopicSelectChildAnimation.isPlaying ||
                    this.SubTopicSelectAnimation.isPlaying) return true;                    
                 else return false;                             
        }
        
        this.addCTA = function (iProductID, CTAType, CTAText, CTATracking, CTAURL, CTAOpen)
        {
            if(this.CTAsProductIDs == null)
            {
                this.CTAsProductIDs = new Array(1);
                this.CTAsType = new Array(1);
                this.CTAsText = new Array(1);
                this.CTAsTracking = new Array(1);
                this.CTAsURL = new Array(1);
                this.CTAsOpen = new Array(1);
                this.CTAsProductIDs[0] = iProductID;
                this.CTAsType[0] = CTAType;
                this.CTAsText[0] = CTAText;
                this.CTAsTracking[0] = CTATracking;
                this.CTAsURL[0] = CTAURL;
                this.CTAsOpen[0] = CTAOpen;
            }
            else
            {
                var index = this.CTAsProductIDs.length;
                this.CTAsProductIDs[index] = iProductID;
                this.CTAsType[index] = CTAType;
                this.CTAsText[index] = CTAText;
                this.CTAsTracking[index] = CTATracking;
                this.CTAsURL[index] = CTAURL;
                this.CTAsOpen[index] = CTAOpen;
            }
        };
         
        this.GetBounds = function () 
        {
            return Sys.UI.DomElement.getBounds($get(this.ClientID));
        };
        
        this.PlayDefault = function ()
        {
            this.InitAnimationObjects();
            this.DefaultAnimation.play();                                            
        };
        
        /*this.PlayFloat = function ()
        {
            this.InitAnimationObjects();
            this.FloatAnimation.play();  
        
        };*/
        
        this.PlayExternalHighlight = function ()
        {
            this.InitAnimationObjects();
            this.ExternalAnimation.play();   
        };
        
        this.StopFloat = function ()
        {
            this.InitAnimationObjects();
            this.FloatAnimation.stop();   
        
        };
        
        this.PlayTopicHighlight = function ()
        {
            this.InitAnimationObjects();
            this.TopicHighlightAnimation.play();            
        }
        
        this.PlaySubTopicHighlight = function ()
        {
            this.InitAnimationObjects();
            this.SubTopicHighlightAnimation.play();
        }              
        
        this.PlayTopicSelect = function()
        {
            this.InitAnimationObjects();
            this.TopicSelectAnimation.play();           
        }
        
        this.PlayTopicSelectChild = function()
        {
            this.InitAnimationObjects();
            this.TopicSelectChildAnimation.play();
        }
        
        this.PlaySubTopicSelect = function()
        {
            this.InitAnimationObjects();
            this.SubTopicSelectAnimation.play();                
        }          
        
        this.PlaySubTopicSelectParent = function()
        {
            this.InitAnimationObjects();
            this.SubTopicSelectParentAnimation.play();            
        }
        
        this.PlayZoom = function()
        {
            this.InitAnimationObjects();
            this.ZoomAnimation.play();
        }
        
        this.PlayZoomOut = function()
        {
            this.InitAnimationObjects();
            this.ZoomOutAnimation.play();
        }
        
        this.PlayTopicIntro = function()
        {
            this.InitAnimationObjects();
            this.TopicIntroAnimation.play();
        }
        
        this.setLocation = _setLocation;
    }
    
    function calcCenter(x1, x2) 
    {
        return x1+((x2-x1)/2);
    }
    
    function GetState() 
    {
        return document.getElementById(hdnStateID).value;
    }
    
    function SetHiddenTopic(state) 
    {
        document.getElementById(hdnTopicID).value = state;
    }
    
    function GetHiddenTopic() 
    {
        try 
        {
            if (document.getElementById(hdnTopicID) != "undefined")
            {
                return document.getElementById(hdnTopicID).value;
            }
        } catch (ex) {
            //page loading      
        }
    }
    
    function SetState(state) 
    {
        document.getElementById(hdnStateID).value = state;
    }
    
    function ChangeText(txt) 
    {
        //$get(startupLinkID).style.display = 'none';
        //$get(startupLinkID).style.visibility = 'hidden'; 
        var startupLink = $get(startupLinkID);
        startupLink.innerHTML = txt;
        startupLink.style.width = "100px";
        
        var StartUpBounds = Sys.UI.DomElement.getBounds(startupLink);
        //Sys.UI.DomElement.setLocation(startupLink, parseInt(centerX - (StartUpBounds.width / 2)+12), parseInt(centerY - (StartUpBounds.height/2)+10));
        Sys.UI.DomElement.setLocation(startupLink, 250, 145);
        
        
        SetState('NORMAL');
        
    }
    
    function getQueryKey(key) 
    { 
      var query = window.location.search.substring(1); 
      var vars = query.split("&"); 
      for (var i=0;i<vars.length;i++) 
      { 
            var pair = vars[i].split("="); 
            if (pair[0] == key) 
            { 
                return pair[1]; 
            } 
      }  
    } 

    function PlayExploreIntro()
    {
        var animation = $find(startupLinkBehavior).get_OnClickBehavior().get_animation()
        animation.play();
        animation.add_ended(PlayChildTopicIntros);
        animation.add_ended(PlayTipIntro);
    }
    
    function StopAllAnimations()
    {
        for(var i=0; i < TopicList.length; i++)
        {
            TopicList[i].StopAllAnimations();
        }
    }
    
    function AnimationsPlaying()
    {
        for(var i=0; i < TopicList.length; i++)
        {
            if (TopicList[i].AnimationsPlaying()) return true;
        }
        
        return false;
    }
    
  
        
    function initializeCloud() 
    {
        SetState("NORMAL");
        SetHiddenTopic(-1);
        
        if (getQueryKey("topicid") != null) 
        {
            //$get(startupLinkID).style.display = 'none';                
            //$get(startupLinkID).style.visibility = 'hidden'; 
            organizeCloud();   
             
            //save all original topic positions
            for(var i=0; i < TopicList.length; i++) 
            {
                TopicList[i].SavePosition();
            }
            
            SetState("NORMAL");
            
            PlayCloudIntro();
            setTimeout("PlaySelect('"+ getQueryKey("topicid") + "')", 1900);
            
        }
        else 
        {
            organizeCloud();  
            
            //
           
           setTimeout("PlayCloudIntro();",100);
           //PlayExploreIntro();
           
          
           
           
        }
        
        setTimeout('FixProductHovers();', 1000);
        
    }
    
    function PlayCloudIntro()
    {
      

            PlayNextTopicIntro();
           
           
    }
    
    var parentTopicPlayIndex = 0;
    function PlayNextTopicIntro()
    {
        if (parentTopicPlayIndex < ParentTopics.length)
        {
            ParentTopics[parentTopicPlayIndex].PlayTopicIntro();
            ParentTopics[parentTopicPlayIndex].TopicIntroAnimation.add_ended(PlayNextTopicIntro);
            parentTopicPlayIndex++;
        } else {
            PlayExploreIntro();
        }
    }
    
    function PlayChildTopicIntros()
    {
       for (var i=0;i<TopicList.length;i++)
       {
            if (TopicList[i].SubTopics == null)
            {
                TopicList[i].PlayTopicIntro();
            }
       } 
       //FadeOut('StartImage', 100);
       //setTimeout("FadeIn('EndImage', 0);", 500); 
    }
    
    function PlayTipIntro()
    {
        var behavior = $find("TipBehavior"); 
        behavior.get_OnMouseOverBehavior().get_animation().play();
    }
    
    //var isTipExitPlayed = false;
    function PlayTipExit()
    {
        if (!GetTipExitState())
        {
            var behavior = $find("TipBehavior"); 
            if (behavior != null)
                behavior.get_OnMouseOutBehavior().get_animation().play();
            
        }
    }
    
    
    
    function GetTipExitState()
    {
        var state;
        
        var TopicCloudTip = document.getElementById('TopicCloudTip');
            state = (TopicCloudTip.style.display == "none") ? true : false;
        return state;
    }
    
    function HideTips()
    {
        var TopicCloudTip = document.getElementById('TopicCloudTip');
        TopicCloudTip.style.display = "none";
        
        var ProductTip = document.getElementById('ProductTip');
        ProductTip.style.display = "none";
        
        var NavTip = document.getElementById('NavTip');
        NavTip.style.display = "none";
        
        
    }
    
    function FixProductHovers()
    {
        if (ProductHoveredArray != null && GetState() != "SELECTED" && GetState() != "HOVER") 
        {
        
            var HasOpenProduct = false;
            var OpenProductId = null;
            for(var i=0; i < ProductHoveredArray.length; i++)
            {
                if (document.getElementById('offers_default_text_div_'+ProductHoveredArray[i]).style.display != 'none')
                {
                    HasOpenProduct=true;
                    OpenProductId=ProductHoveredArray[i];                   
                }                
            }            
            
            if (!HasOpenProduct) {
                PlayDefaultAnimations();
            }
            else {
                TopicCloudExternalHighlightTopics(LastProductIdsHovered, false);               
                //TopicCloudNormalizeUnrelatedTopics(LastProductIdsHovered);
            }
        }
        
        setTimeout('FixProductHovers();', 1000);
    }
    
    function cleanUpPositions() 
    {
       
       /*for(var i=0; i<TopicList.length; i++) 
       {
            TopicList[i].RestorePosition();
       }            
       setTimeout('cleanUpPositions();', 1000);*/
    }
    
    
    var ParentTopics, centerX, centerY = null;//define ParentTopics at global level
    var cloudContainer = null;
    function organizeCloud()
    {
        //get array of parent topics
        
        for(var i=0; i < TopicList.length; i++) 
        {
            if (TopicList[i].SubTopics != null) 
            {
                if (ParentTopics == null) 
                {
                    ParentTopics = new Array(1);                    
                    ParentTopics[0] = TopicList[i];
                }
                else 
                {
                    ParentTopics[ParentTopics.length] = TopicList[i];                    
                }   
            }                             
        }
        
        //sort Parent Topics array based on number of child topics
        var sorted = false;
        var temp = null;
        for(var i=0; i < ParentTopics.length && !sorted; i++)
        {                
            sorted = true;
            for(var j=0; j < (ParentTopics.length-1); j++)
            {
                if (ParentTopics[j].SubTopicObjects.length > ParentTopics[j+1].SubTopicObjects.length)
                {
                    temp = ParentTopics[j];
                    ParentTopics[j] = ParentTopics[j+1];
                    ParentTopics[j+1] = temp;
                    sorted = false;                        
                 }
            }
        }        
        
        //divide parent topics in half and put topics into two arrays one for each column of the cloud
        //this is done to try to balance the content of the cloud by pairing a topic with many sub topic with one
        //that has fewer.  The idea is to have have approximately the same number of rows in each column
        var Col1Parents = new Array(ParentTopics.length / 2 + (ParentTopics.length % 2));
        var Col2Parents = new Array(ParentTopics.length / 2);
        
        for(var i=0; i < Col1Parents.length; i++) 
        {
            Col1Parents[i] = ParentTopics[i];
        }
        
        for(var i=0; i < Col2Parents.length; i++) 
        {
            Col2Parents[i] = ParentTopics[i+Col1Parents.length];
        }            
        
        var Col1TotalRows = 0;
        var Col2TotalRows = 0;
        
        for(var i=0; i < Col1Parents.length; i++)
        {
            Col1TotalRows += Col1Parents[i].SubTopicObjects.length+1;
        }         
        
        for(var i=0; i < Col2Parents.length; i++)
        {
            Col2TotalRows += Col2Parents[i].SubTopicObjects.length+1;
        }                     
        
        var CloudTable = new Array(2);
        var TotalRows = 0;
        
        if (Col2TotalRows > Col1TotalRows) 
        {            
            TotalRows = Col2TotalRows;
        }
        else if (Col1TotalRows > Col2TotalRows) 
        {            
            TotalRows = Col1TotalRows;
        }
        
        CloudTable[0] = new Array(TotalRows);
        CloudTable[1] = new Array(TotalRows);
        
        //fill the cloud table with all topics and sub topics
        FillColumn(CloudTable[0], Col1Parents);
        FillColumn(CloudTable[1], Col2Parents);
        
        //place topics within the cloud div
        var cloudContainerBounds = Sys.UI.DomElement.getBounds($get('cloudContainer'));
        
        //determine max height of topic links 
        var maxHeight = 0;            
        for(var i=0; i < TopicList.length; i++) 
        {                  
            if (TopicList[i].GetBounds().height > maxHeight) maxHeight = TopicList[i].GetBounds().height;                       
        }  
        
        if (maxHeight == 0) maxHeight = 30; //IE 8 FIX
                    
        var CloudHeight = TotalRows*maxHeight;
        var CloudWidth = CalcCloudWidth(CloudTable);
        

        //place startup link in center            
        centerX = cloudContainerBounds.width / 2;
        centerY = cloudContainerBounds.height / 2;
        
        var link1Width = 0;
        var link2Width = 0;
        var pad=15;
        for(var row=0; row < TotalRows; row++)
        {
            if (CloudTable[0][row] != null)
            {
                link1Width = CloudTable[0][row].GetBounds().width;
            }
            else link1Width = 0;
           
            if (CloudTable[1][row] != null)
            {
                link2Width = CloudTable[1][row].GetBounds().width;
            }
            else link2Width = 0;                
            
            for(var col=0; col < CloudTable.length; col++) 
            {
                if (CloudTable[col][row] != null) 
                {          
                    //make pad a function of how far this topic will be from the center
                    //with topics closer to the center having a larger padding between centers
                    //this helps maintian the round look
                    //pad = parseInt(TotalRows/2-(centerY - (centerY  - (CloudHeight / 2) + (row * maxHeight))) / maxHeight)*20;
                    if (row == 4 || row == 5) pad = 60;
                    else pad = 0;
                    //if (pad < 0) pad = pad*-1;
                    
                    if (row == 1) pad = 15;
                    
                    if (col == 0)
                        CloudTable[col][row].setLocation(parseInt(centerX - (link1Width + link2Width + 2*pad) / 2), centerY  - (CloudHeight / 2) + (row * maxHeight));
                    else    
                        CloudTable[col][row].setLocation(parseInt(centerX - (link1Width + link2Width + 2*pad) / 2) + link1Width + 2*pad, centerY  - (CloudHeight / 2) + (row * maxHeight));
                }
            }            
        }    
        
    }
    
    function CalcCloudWidth(CloudTable) 
    {   
        return CalcColumnWidth(CloudTable[0]) + CalcColumnWidth(CloudTable[1]);            
    }       
    
    function CalcColumnWidth(CloudColumn) 
    {
        var maxWidth = 0;
        
        for(var i=0; i < CloudColumn.length; i++) {
            
            if(CloudColumn[i] != null) 
            {
                if (CloudColumn[i].GetBounds().width > maxWidth) maxWidth = CloudColumn[i].GetBounds().width;   
            }            
        }
        
        return maxWidth;
    }
    
    function FillColumn(CloudColumn, Parents)
    {
        var LastRow = 0;
        for(var i=0; i < Parents.length; i++) 
        {
            LastRow = PlaceTopicAndChildren(CloudColumn, Parents[i], LastRow);
        }
        
        if (LastRow < CloudColumn.length-1) //fill empty slots with nulls
        {
            for (var i=LastRow+1; i < CloudColumn.length; i++) CloudColumn[i] = null;
        }
    }
    
    function PlaceTopicAndChildren(CloudColumn, Parent, LastRow)
    {
        var ChildrenAbove = parseInt(Parent.SubTopicObjects.length / 2);
        var ChildrenBelow = Parent.SubTopicObjects.length - ChildrenAbove;
                    
        for(var count=0; count < ChildrenAbove; LastRow++)
        {
            CloudColumn[LastRow] = Parent.SubTopicObjects[count];
            count++;
        }
        
        //place parent
        CloudColumn[LastRow] = Parent;
        LastRow++;                      
        
        for(var count=0; count < ChildrenBelow; LastRow++)
        {
            CloudColumn[LastRow] = Parent.SubTopicObjects[ChildrenAbove+count];
            count++;
        }
        
        return LastRow;
    }
         
    
    
    function getControlID() 
    {
        return AnimationTarget; 
    }
    
    /*function PlayNormalState() 
    {
        try {
            SetState("CHANGING");
            //for each topic play the rotation behaviour
            for(var i = 0; i < TopicList.length; i++) 
            {                
                TopicList[i].PlayFloat();
                TopicList[i].State = "NORMAL"; 
            }
            SetState("NORMAL");
        }
        catch (ex) { }
    }*/
    
    /*function StopFloatAnimations() 
    {
        try {
           
            //for each topic play the rotation behaviour
            for(var i = 0; i < TopicList.length; i++) 
            {                
                TopicList[i].StopFloat();                   
            }               
        }
        catch (ex) { }
    }*/
    
    function PlayDefaultAnimations() 
    {
        try 
        {                
            SetState("CHANGING");                
            //for each topic play the rotation behaviour
            for(var i = 0; i < TopicList.length; i++) 
            {                
                TopicList[i].PlayDefault();                    
            }
            SetState("NORMAL");
        }
        catch (ex) { }
    }
    
    var FloatStopped=false;
    function StopNormalState() 
    {
        //for each topic play the rotation behaviour
        for(var i = 0; i < TopicList.length; i++) 
        {                
            TopicList[i].StopFloat();                
        }           
        FloatStopped = true;
    }
    
    
    function TopicCloudExternalHighlightTopics(TopicIds, PlayDefault)
    {       
        try {
            StopAllAnimations();           
        
            TopicIds = ',' + TopicIds + ',';
            
            //if (!FloatStopped) StopNormalState();      //uncomment to add float
            //if (PlayDefault) PlayDefaultAnimations();    
            TopicCloudNormalizeUnrelatedTopics(TopicIds);
            
            for(var i=0; i < TopicList.length; i++)
            {
                if (TopicIds.indexOf(TopicList[i].TopicID) >= 0)
                {
                    TopicList[i].PlayExternalHighlight();
                   //setTimeout('TopicList['+i+'].PlayExternalHighlight();', 1500); //this delay is needed to allow time for stopping the float and making sure all links are in the default state.
                }
            }
            
            SetState('PRODUCT_HOVER');
        }
        catch (ex) { /* this catches errors that get thrown before all page elements have loaded */};
        
        
    }
    
   
    function TopicCloudNormalizeUnrelatedTopics(TopicIds)
    {   
        try {
            TopicIds = ',' + TopicIds + ',';
                        
            for(var i=0; i < TopicList.length; i++)
            {
                if (TopicIds.indexOf(TopicList[i].TopicID) < 0)
                {
                    TopicList[i].PlayDefault();                   
                }
            }           
            
        }
        catch (ex) { /* this catches errors that get thrown before all page elements have loaded */};
    }
    
    
    function PlayMouseOut(topicId) 
    {
        try {
        
            CancelHighlightTimer();
            
            
        
            /*if (GetState() == "CHANGING")
            {                    
                return;
            }
        
            if (GetState() != "START_UP" && !(GetState() == "SELECTED" && GetHiddenTopic() == topicId)) 
            {
                SetState("CHANGING");
                StopNormalState();               
                
                //play animations  for unrelated topics to zoom topics back in
                unrelatedTopics = GetUnrelatedTopics(GetTopicById(topicId));            
                if (GetState() != "START_UP" && !(GetState() == "SELECTED" && GetHiddenTopic() == topicId)) 
                {
                    for(var r=0; r < unrelatedTopics.length; r++) 
                    {           
                        unrelatedTopics[r].PlayZoom();
                    }
                }
                
                SetState("CHANGING");                                         
                PlayDefaultAnimations();               
            }*/
        }
        catch(ex) { PlayDefaultAnimations(); }
           
    }
    
    var currentTopic;
    function PlaySelect(topicId) 
    {     
            CancelHighlightTimer();
            
            ExitAllProducts();
            
            
            var rotateBehavior = '';
            var selectBehavior='';
            var parent=null;
            var subTopics=null;
            
            currentTopic = GetTopicById(topicId);
            if (GetState() == "CHANGING")
            {                    
                return false;
            }
            
                           
            
            if (GetState() != "START_UP" && !(GetState() == "SELECTED" && GetHiddenTopic()==topicId)) 
            {
                //StopFloatAnimations(); Removed MB
                //PlayHighlight(topicId);                
               
//                SetState("CHANGING");      
//                var unrelatedTopics = null;
//                //play animations  for unrelated topics
//                unrelatedTopics = GetUnrelatedTopics(GetTopicById(topicId));      

//                //play zoom out
//                for (var r = 0; r < unrelatedTopics.length; r++) {
//                    //unrelatedTopics[r].StopFloat();                                
//                    unrelatedTopics[r].PlayZoomOut();
//                    unrelatedTopics[r].State = "BACKGROUND";
//                    //unrelatedTopics[r].PlayFloat();
//                }     
//               
//                for(var i = 0; i < TopicList.length; i++) 
//                {       
//                    if (TopicList[i].TopicID == topicId) 
//                    {         
//                        parent = GetParentTopic(TopicList[i]);
//                        
//                        if (parent == null) 
//                        {
//                            //TopicList[i].StopFloat();                            
//                            TopicList[i].PlayTopicSelect();                                
//                            TopicList[i].State = "SELECTED";
//                        
//                            //play highlight for sub topics also      
//                            subTopics = GetSubTopics(TopicList[i]);                  
//                            for(var j=0;subTopics != null && j < subTopics.length; j++) 
//                            {
//                                //subTopics[j].StopFloat(); 
//                                subTopics[j].PlayTopicSelectChild();                                    
//                                subTopics[j].State = "SELECTED";
//                            }
//                        }
//                        else 
//                        {
//                            //play behavior when child is clicked
//                            //parent.StopFloat();
//                            parent.PlaySubTopicSelectParent();                                
//                            parent.State = "SELECTED";
//                        
//                            //play highlight for sub topics also      
//                            subTopics = GetSubTopics(parent);                  
//                            for(var j=0;subTopics != null && j < subTopics.length; j++) 
//                            {
//                                //subTopics[j].StopFloat();
//                                if (subTopics[j].TopicID == topicId) subTopics[j].PlaySubTopicSelect();
//                                else subTopics[j].PlayTopicSelectChild();
//                                subTopics[j].State = "SELECTED";
//                            }
//                        }
//                    }
//                }
                 
                 //ExitAllRelatedProducts();
                 
                 
                    
               
                 
                 
                 setTimeout("ShowRelatedProducts();",300);
                
                 SetHiddenTopic(topicId);
                 
                 
                 SetState("SELECTED");
                 TopicSelectedCallback(topicId);
            }                
          
           
           if (!allowServerEvents) return false;
           else return true;
           
           
    }
    
    function ShowRelatedProducts()
    {
            SetState("CHANGING");                                            
                               
            //ExitAllRelatedProducts();                
            if(currentTopic.RelatedProducts != null)
            {
                for(var i=0; i<currentTopic.RelatedProducts.length; i++)
                {
                    RelatedProductShow(currentTopic.RelatedProducts[i], currentTopic.RelatedProductsDescs[i], currentTopic.RelatedProductsBoxShots[i]);
                }
                
                for(var i=0; i<currentTopic.CTAsProductIDs.length; i++)
                {
                    ChangeCTA(currentTopic.CTAsProductIDs[i], currentTopic.CTAsType[i], currentTopic.CTAsText[i], currentTopic.CTAsTracking[i], currentTopic.CTAsURL[i], currentTopic.CTAsOpen[i], 'offers_product_text_div_');
                }
            }    
            SetLinkStyle();
            SetState("SELECTED");
    }
    
    function PlayMouseOverWithPostBack(topicId, postbackScript)
    {
       SetLinkStyle(topicId);
        if (GetState() != "START_UP" && !(GetState() == "SELECTED" && GetHiddenTopic() == topicId)  &&
            !(GetState() == "HOVER" && GetHiddenTopic()==topicId)
            ) 
        {
            PlayTipExit();
            
            PlayHighlightTimer(topicId, postbackScript);        
           
        }
    }
    
    
    function SetLinkStyle(topicId)
    {
         if (topicId == undefined)
            topicId = GetHiddenTopic();
         
            
         var topic;
         if (TopicList != undefined)
         {
             for(var i = 0; i < TopicList.length; i++) 
                {       
                    topic = document.getElementById(TopicList[i].ClientID);
                    if (TopicList[i].TopicID == topicId) 
                    {
                       topic.style.color = "#3A4D81";
                       topic.style.fontWeight = "bold";
                       topic.style.textDecoration = "underline";
                       
                    } else {
                       
                       topic.style.color = "";
                       topic.style.fontWeight = "";
                       topic.style.textDecoration = "";
                    
                    }
                    
                }
            }
    }
    
    function CancelHighlightTimer()
    {
        if (mouseoverTimer != null) 
        {
            clearTimeout(mouseoverTimer);
            mouseoverTimer = null;
        }
    }
    
    function PlayHighlightTimer(topicId, postbackScript)
    {
        if (allowServerEvents) {
            //mouseoverTimer = setTimeout("PlayHighlight('"+topicId+"');" + postbackScript, 500);
            mouseoverTimer = setTimeout("PlayHighlight('" + topicId + "');" + postbackScript, 500);   
        }
        else 
        {
            //mouseoverTimer = setTimeout("PlayHighlight('"+topicId+"');", 500);
            mouseoverTimer = setTimeout("PlayHighlight('" + topicId + "');", 500);                    
        }
    }
    
    function TopicMouseOver(topicId)
    {
      
         for (var i = 0; i < TopicList.length; i++) {
            if (TopicList[i].TopicID == topicId)
            {
               var topicElement = $get(TopicList[i].ClientID);
               //alert(topicElement);
                TopicList[i].style.textDecoration = "underline";
                
            }
                    
         }
        //SelectedTopic.
    }
    
    var PlayingHighlight = false;
    function PlayHighlight(topicId) 
    {
        if (PlayingHighlight) return;
        
            PlayingHighlight = true;

            var rotateBehavior = '';
            var selectBehavior = '';
            var parent = null;
            var subTopics = null;

            var currentTopic = GetTopicById(topicId);
            if (GetState() == "CHANGING") {
                return false;
            }
           
            CancelHighlightTimer();
                   
            //play animations  for unrelated topics
            unrelatedTopics = GetUnrelatedTopics(GetTopicById(topicId));            
            
            //play animations for related topics
            if (GetState() != "START_UP" && !(GetState() == "SELECTED" && GetHiddenTopic() == topicId)  &&
            !(GetState() == "HOVER" && GetHiddenTopic()==topicId)
            ) 
            {                    
                //SetLinkStyle(topicId);          
                SetState("CHANGING");
                
                ExitAllRelatedProducts();
                if (currentTopic.RelatedProducts != null) {
                    for (var i = 0; i < currentTopic.RelatedProducts.length; i++) {
                        RelatedProductShow(currentTopic.RelatedProducts[i], currentTopic.RelatedProductsDescs[i], currentTopic.RelatedProductsBoxShots[i]);
                        //setTimeout("RelatedProductShow(" + currentTopic.RelatedProducts[i] + ", " + currentTopic.RelatedProductsDescs[i] + ", " + currentTopic.RelatedProductsBoxShots[i] + ");",200);
                    }
                    for (var i = 0; i < currentTopic.CTAsProductIDs.length; i++) {
                        ChangeCTA(currentTopic.CTAsProductIDs[i], currentTopic.CTAsType[i], currentTopic.CTAsText[i], currentTopic.CTAsTracking[i], currentTopic.CTAsURL[i], currentTopic.CTAsOpen[i], 'offers_product_text_div_');
                    }
                }
                else {
                    alert('related products null');
                }

//                var unrelatedTopics = null;
//                //play animations  for unrelated topics
//                unrelatedTopics = GetUnrelatedTopics(GetTopicById(topicId));

//                //play zoom out
//                for (var r = 0; r < unrelatedTopics.length; r++) {
//                    //unrelatedTopics[r].StopFloat();                                
//                    unrelatedTopics[r].PlayZoomOut();
//                    unrelatedTopics[r].State = "BACKGROUND";
//                    //unrelatedTopics[r].PlayFloat();
//                }

//                for (var i = 0; i < TopicList.length; i++) {
//                    if (TopicList[i].TopicID == topicId) {
//                        parent = GetParentTopic(TopicList[i]);

//                        if (parent == null) {
//                            //TopicList[i].StopFloat();                            
//                            TopicList[i].PlayTopicSelect();
//                            TopicList[i].State = "HIGHLIGHT";

//                            //play highlight for sub topics also      
//                            subTopics = GetSubTopics(TopicList[i]);
//                            for (var j = 0; subTopics != null && j < subTopics.length; j++) {
//                                //subTopics[j].StopFloat(); 
//                                subTopics[j].PlayTopicSelectChild();
//                                subTopics[j].State = "HIGHLIGHT";
//                            }
//                        }
//                        else {
//                            //play behavior when child is clicked
//                            //parent.StopFloat();
//                            parent.PlaySubTopicSelectParent();
//                            parent.State = "HIGHLIGHT";

//                            //play highlight for sub topics also      
//                            subTopics = GetSubTopics(parent);
//                            for (var j = 0; subTopics != null && j < subTopics.length; j++) {
//                                //subTopics[j].StopFloat();
//                                if (subTopics[j].TopicID == topicId) subTopics[j].PlaySubTopicSelect();
//                                else subTopics[j].PlayTopicSelectChild();
//                                subTopics[j].State = "HIGHLIGHT";
//                            }
//                        }
//                    }
//                }
                SetHiddenTopic(topicId); 
                
                
                SetState("HOVER");                
                if (TopicHoveredCallback != null) TopicHoveredCallback(topicId);
                
            }
           
        
        PlayingHighlight=false;
        
    }
    
    
    function GetTopicById(topicId) 
    {
        var Topic = null;
        for(var i=0; i < TopicList.length;i++) 
        {
            if (TopicList[i].TopicID.toLowerCase() == topicId.toLowerCase()) {
             Topic = TopicList[i];
             break;
             }
        }
        
        return Topic;
    }
    
    function GetUnrelatedTopics(topic)
    {
        var parent = GetParentTopic(topic);
        var SubTopics = null;
                    
        if (parent == null) 
        {
            parent = topic;
            SubTopics = GetSubTopics(topic);
        }
        else {
            SubTopics = GetSubTopics(parent);
        }
        
        //get array of all unrelated topics
        var UnrelatedArray = null;
        var isRelated = false;
        for(var i=0; i < TopicList.length;i++) 
        {
            if (TopicList[i].TopicID != parent.TopicID) 
            {
                isRelated=false;
                for(var j=0; j < SubTopics.length; j++) 
                {
                    if (SubTopics[j].TopicID == TopicList[i].TopicID) isRelated=true;
                }
                
                if (!isRelated) 
                {
                    if (UnrelatedArray == null) 
                    {
                        UnrelatedArray = new Array(1);
                        UnrelatedArray[0] = TopicList[i];
                    }
                    else 
                    {
                        UnrelatedArray[UnrelatedArray.length] = TopicList[i];
                    }
                }
            }
        }
        
        return UnrelatedArray;
    }
    
    function GetSubTopics(topic) 
    {
        if (topic.SubTopics != null) 
        {
            var SubTopicObjects = new Array(topic.SubTopics.length);
            
            //for every sub topic id find the sub topic object and add it to the array
            for(var i=0; topic.SubTopics != null && i < topic.SubTopics.length ; i++) 
            {
                for(var j=0; j < TopicList.length; j++) 
                {
                    if (TopicList[j].TopicID == topic.SubTopics[i]) 
                    {
                        SubTopicObjects[i] = TopicList[j];
                    }
                }
            }
            
            return SubTopicObjects;
        }
        else {
            return null;
        }
    }
    
    function GetParentTopic(topic) 
    {
        for(var i=0; i < TopicList.length; i++) 
        {
            for(var j=0; TopicList[i].SubTopics != null && j < TopicList[i].SubTopics.length; j++) 
            {
                if (TopicList[i].SubTopics[j] == topic.TopicID) return TopicList[i];
            }
        }
        
        return null;
    }
    
    function LinkPlaced(linksPlaced, TopicbObj, PlaceCount) {
    
        for(var i=0; i < PlaceCount; i++) 
        {
            if (linksPlaced[i] == TopicbObj.TopicID) return true;
        }
        
        return false;
    }
    
    function GetWidestLinkBounds(topicLinks, linkIDsPlaced, linksPlaced) 
    {
        var maxWidth = 0;
        var maxWidthID = -1;
        for(var i=0; i< linkIDsPlaced.length; i++) 
        {
            if (topicLinks[i].GetBounds().width > maxWidth && !LinkPlaced(linkIDsPlaced, topicLinks[i], linksPlaced))
            {
                maxWidth = topicLinks[i].GetBounds().width;
                maxWidthID = i;
            }
        }
        
        return maxWidthID;
    }            
    
    function GetLinkNotPlaced(topicLinks, linkIDsPlaced, linksPlaced) 
    {
        var maxWidth = 0;
        var maxWidthID = -1;
        for(var i=0; i< linkIDsPlaced.length; i++) 
        {
            if (!LinkPlaced(linkIDsPlaced, topicLinks[i], linksPlaced))
            {
                maxWidth = topicLinks[i].GetBounds().width;
                maxWidthID = i;
            }
        }
        
        return maxWidthID;
    }
    
/*------------------------------------------------------------
CTA functions
------------------------------------------------------------*/    
    function ShowCTA(ProductId)
    {
         var ParentDiv = document.getElementById("offers_product_text_div_" + ProductId);
         var ChildAnchors = ParentDiv.getElementsByTagName("a");
         var BackgroundImageText;
         
         for (var i=0;i<ChildAnchors.length;i++)
         {
            BackgroundImageText = ChildAnchors[i].style.backgroundImage.toString();
            BackgroundImageText = BackgroundImageText.replace("_gray.gif",".gif");
            ChildAnchors[i].style.backgroundImage = BackgroundImageText;
         }
         
    }
    
    function HideCTA(ProductId)
    {
         var ParentDiv = document.getElementById("offers_product_text_div_" + ProductId);
         var ChildAnchors = ParentDiv.getElementsByTagName("a");
         var BackgroundImageText;
         
         for (var i=0;i<ChildAnchors.length;i++)
         {
            BackgroundImageText = ChildAnchors[i].style.backgroundImage.toString();
            BackgroundImageText = BackgroundImageText.replace(".gif","_gray.gif");
            ChildAnchors[i].style.backgroundImage = BackgroundImageText;
         }
         
    }

    function ChangeCTA(ProductId, CTAType, CTAText, CTATracking, CTAURL, CTAOpen, divText)
    {
       
        if(CTAOpen == 'iframe')
        {
            document.getElementById(divText+ProductId).innerHTML +=
                '<a onclick="showIframe(\'' + CTAURL + '\',\'' + CTATracking + '\');" class="CTAButton" style="background-image: url(images/cta_' + CTAType + '.gif);">' + CTAText + '</a>';
        }
        else
        {
            document.getElementById(divText+ProductId).innerHTML +=
                '<a href="' + CTAURL + '" target="_blank" onclick="pageEventsTracking.setClickEvents(\'' + CTATracking + '\');" class="CTAButton" style="background-image: url(images/cta_' + CTAType + '.gif);">' + CTAText + '</a>';
        }
    }  
    
/*------------------------------------------------------------
Product functions
------------------------------------------------------------*/

    function ProductHoverTimeout(ProductId)
    {
        setTimeout('ProductHover("' + ProductId + '");', 400);
    }
    
    function ProductExitTimeout(ProductId)
    {
        ExitProductId = ProductId;
        exitTimeout = setTimeout('ProductExit("' + ProductId + '");', 10);
    }
    
    var ProductHoverId = '';
    var ProductHoveredArray = null;
    var RelatedProductShownArray = null;
    var exitTimeout = null;
    var ExitProductId = ''; 
    
    function AddProductHovered(ProductId)
    {
        if (ProductHoveredArray == null)
        {
            ProductHoveredArray = new Array(1);
            ProductHoveredArray[0] = ProductId;
        }        
        else
        {
            var found = false;
            for(var i=0; i < ProductHoveredArray.length; i++) {
                if (ProductHoveredArray[i] == ProductId) {
                     found = true;
                     break;
                }            
            }
            
            if (!found) ProductHoveredArray[ProductHoveredArray.length] = ProductId;         
        }
    }
    
    function AddRelatedProductShown(ProductId)
    {
        if (RelatedProductShownArray == null)
        {
            RelatedProductShownArray = new Array(1);
            RelatedProductShownArray[0] = ProductId;
        }        
        else
        {
            var found = false;
            for(var i=0; i < RelatedProductShownArray.length; i++) {
                if (RelatedProductShownArray[i] == ProductId) {
                     found = true;
                     break;
                }            
            }
            
            if (!found) RelatedProductShownArray[RelatedProductShownArray.length] = ProductId;         
        }
    }
    
    function ExitAllProducts() 
    {
        for(var i=0; ProductHoveredArray != null &&  i < ProductHoveredArray.length; i++) 
        {
            ProductExit(ProductHoveredArray[i], false);
        }
        ProductHoveredArray = null;
    }
    
    function ExitAllRelatedProducts()
    {
        for(var i=0; RelatedProductShownArray != null &&  i < RelatedProductShownArray.length; i++) 
        {
            ProductExit(RelatedProductShownArray[i], true);
        }
        RelatedProductShownArray = null;
    }
    
    function ExitAllRelatedProductsExceptCurrent(ProductId)
    {
        for(var i=0; RelatedProductShownArray != null &&  i < RelatedProductShownArray.length; i++) 
        {
            if (RelatedProductShownArray[i] != ProductId) ProductExit(RelatedProductShownArray[i], true);
        }
        RelatedProductShownArray = null;
    }
    
    var ProductHoverTimeout = null;
    var LastProductIdsHovered = '';
        
        
    var HoverTopicIds = null;
    var LastProductHovered = null;
    var ProductHoverTimeout = null;
    function ProductHover(ProductId, TopicIds)
    {   
        //if (GetState() == "SELECTED") return;        
        
        SetState('PRODUCT_HOVER');      
        LastProductIdsHovered = TopicIds;
        DoProductHover(ProductId, TopicIds);
        PlayTipExit();
    }
    
    function DoProductHover(ProductId, TopicIds)
    {                 
        
        if (ExitProductId == ProductId && exitTimeout != null) 
        {
            clearTimeout(exitTimeout)
            ExitProductId = '';
            exitTimeout = null;
         }
        /*
        for(var i=0; RelatedProductShownArray != null && i<RelatedProductShownArray.length; i++)
        {
            if(RelatedProductShownArray[i] == ProductId) return;
        }
        */
        
        //if (ProductHoverId != '' && ProductHoverId == ProductId) return;
        //ExitAllRelatedProducts();
        
        
        TopicCloudExternalHighlightTopics(TopicIds, true);
          
        
        //document.getElementById('offers_default_text_div_'+ProductId).style.display = 'block';   
        //document.getElementById('offers_product_text_div_'+ProductId).style.display = 'none'; 
        
        ExpandProduct(ProductId);
        
        ShowCTA(ProductId);
         
        AddProductHovered(ProductId);
         
        ProductHoverId = ProductId;        
       
        //HideTopicDetails(GetHiddenTopic()); 
    }
    
    function ExpandProduct(ProductId)
    {
        
        var behavior = $find("ProductBehavior"); 
        TargetProductID = "main_product_div_" +ProductId;
        
        if (behavior != null)
        {
            behavior.get_OnMouseOverBehavior().get_animation().play();
        }
        
        //document.getElementById('offers_default_text_div_'+ProductId).style.display = 'none';  
        //document.getElementById('offers_product_text_div_'+ProductId).style.display = 'block';  
        //document.getElementById('main_product_div_'+ProductId).style.height = "130px";
        //document.getElementById('main_product_div_'+ProductId).style.display = "block";
    }
    
     function CollapseProduct(ProductDivId)
    {
        
        var Product = document.getElementById(ProductDivId);
        if (Product != undefined)
        {
              var behavior = $find("ProductBehavior");
              TargetProductID = ProductDivId;
              if (behavior != null)
                behavior.get_OnMouseOutBehavior().get_animation().play();
            
            //Product.style.height = "70px";
        }
    }
    
    
    function RelatedProductShow(ProductId, ProductDesc, ProductBoxShot)
    {        
        if (ExitProductId == ProductId && exitTimeout != null) 
        {
            clearTimeout(exitTimeout);
            ExitProductId = '';
            exitTimeout = null;
        }
        
        //document.getElementById('offers_boxshot_img_' + ProductId).src = ProductBoxShot;
        //document.getElementById('offers_logo_div_' + ProductId).style.display = "none";
        //document.getElementById('offers_boxshot_div_' + ProductId).style.display = "block";
         
          
        document.getElementById('offers_product_text_div_'+ProductId).innerHTML = ProductDesc;  
         
        
        ExpandProduct(ProductId);
        AddRelatedProductShown(ProductId);        

    }
    
    var ExitLocked = false;
 
    function ProductExit(ProductId, isRelatedProduct)
    {    
        //if (GetState() == "SELECTED") return;
        
//        if(!isRelatedProduct)
//        {
//            for(var i=0; RelatedProductShownArray != null && i<RelatedProductShownArray.length; i++)
//            {
//                //if(RelatedProductShownArray[i] == ProductId) return;
//                if(RelatedProductShownArray[i] != ProductId)
//                {
//                    document.getElementById('LeftArrow_'+ProductId).style.display = 'none'; 
//                   
//                }
//            }
//        }
//       
//        
        
        
         //document.getElementById('offers_default_text_div_'+ProductId).style.display = 'none';    
         //document.getElementById('offers_product_text_div_'+ProductId).style.display = 'none';
         
         //document.getElementById('offers_boxshot_div_' + ProductId).style.display = "none";
         //document.getElementById('offers_logo_div_' + ProductId).style.display = "block";
         
                       
         CollapseProduct('main_product_div_'+ProductId);
         
         HideCTA(ProductId);
         
               
         if (ProductHoverId == ProductId) ProductHoverId='';
         ExitProductId = '';
         exitTimeout = null;
    }
    
/*------------------------------------------------------------
Topic detail functions
------------------------------------------------------------*/    
     var VisibleTopicId = '';  
  
     var DetailsShownOnce = false;
      function ShowTopicDetails(topicId)
      {     
         PlayTipExit();
         if (VisibleTopicId == topicId) return;
         
         if (VisibleTopicId == '') 
         {        
            //setTimeout("FadeIn('topicdiv_" + topicId + "', 0);", 1000);
            document.getElementById("topicdiv_" + topicId).style.display = "block";
            if (!DetailsShownOnce) 
            {
                //FadeOut('StartImage', 100);
                //setTimeout("FadeIn('EndImage', 0);", 500);       
            }
            VisibleTopicId = topicId;
         }
         else
         {        
            
            document.getElementById("topicdiv_" + VisibleTopicId).style.display = "none";
            document.getElementById("topicdiv_" + topicId).style.display = "block";
            
            
            VisibleTopicId = topicId;
         }
         
         DetailsShownOnce = true;
        
      } 
      
      function HideTopicDetails(topicId)
      {
        if(VisibleTopicId == '') return;
      
        document.getElementById("topicdiv_" + VisibleTopicId).style.display = "none";
        //FadeOut("topicdiv_" + VisibleTopicId, 100);
        VisibleTopicId = '';
      }
      
      function GetTargetProduct()
      {
        return TargetProductID;
      }
      
      function GetTopicCloudTip()
      {
        return "TopicCloudTip";
      }
      
      function GetProductTip()
      {
        return "ProductTip";
      }
      
      function GetNavTip()
      {
        return "NavTip";
      }
      
      
      
     function WindowAddEventHandler(obj,eventName, eventHandler)
      {
      var IsIE = (navigator.userAgent.toString().toLowerCase().indexOf("msie") >=0) ? true : false;
        if (IsIE) {
            obj.attachEvent(eventName,eventHandler);
        } else {
            obj.addEventListener(eventName.replace("on",""),eventHandler,false);
          } 
      
       }
       
    //Added to handle article lightbox scenario  
    WindowAddEventHandler(window,"onload",AddWindowTopCheck);
    function AddWindowTopCheck()
    {
        //select all links except for CTA buttons
        var anchors = document.getElementsByTagName("a");
        
        for (var i=0;i<anchors.length;i++)
        {
            if (anchors[i] != undefined)
            {
                if (anchors[i].className != undefined)
                {
                    if (anchors[i].className.toString().indexOf('CTAButton') == -1)
                    {
                        EventUtility.AddEventHandler(anchors[i], "onclick", CheckForWindowTop);
                    }
                } else {
                    //EventUtility.AddEventHandler(anchors[i], "onclick", CheckForWindowTop);
                }
            }
        }
        
    }  
     
     //checks if page is actually in an iframe and redirects URL to window.top 
    function CheckForWindowTop(evt)
    {
        var returnValue = true;
        if (window.top.location.toString().indexOf('/resources/') > -1)
        {
            var sourceObj = EventUtility.GetEventSourceObject(evt);
            
            if (sourceObj != undefined)
            {
                if (sourceObj.href != undefined)
                {
                    window.top.location = sourceObj.href.toString();
                }
            }
            returnValue = false;
        }
        
        return returnValue;
    }
      
      
      