﻿
/*_____________________________________________*/
/*RELATED COMPONENT*/
/*---------------------------------------------*/
       
       var isPopulatedImages=false;
       var relatedTimer;  
        
       var  FlicksCollection = new FlicksCollectionClass();
            FlicksCollection.TargetPanel = "RelatedPanel";
            //FlicksCollection.ContentView = "sou=3&typ=150154&sor=0&tim=1&adu=0&num=9&trg=1&itr=9&rnd=1";
        
        var RhBgImage;
        var AnalyticsOnLoad = false;
        function SwitchView(owner, viewType)
        {
      
        
            FlicksCollection.Reset();               
            

            //var baseUrl = "localhost/aniboom/Pages/Application/Feeds/Rss.aspx?" + FlicksCollection.ContentView;
            var baseUrl = "http://www.aniboom.com/Pages/Application/Feeds/Rss.aspx?sou=3&typ=150154&sor=0&tim=1&adu=0&num=9&trg=1&itr=9&rnd=1";
            new Ajax.Request(baseUrl,
            {   parameters: '',
                method: 'post', 
                onSuccess: function(transport)
                {
                    clearTimeout(relatedTimer);
                    FlicksCollection.Reset();
                    eval(transport.responseText);
                    FlicksCollection.RenderResult(); 
                    FlicksCollection.PopulateImages();
                },
                
                onFailure: function(){
                    alert("problem with ajax");
                    //window.status = "problem with ajax";
                }
                
            });
                
        }

       
       function FlicksCollectionClass()
       {
            var me = this ;
            this.Items = new Array();
            this.Count=this.Items.length;
            this.TargetPanel = "";
            this.Content = "";
            this.ContentView = "";
            
            
            this.Reset = function(){
                this.Items = new Array();    
            }
            
            this.AddElement = function(elem){
            
                this.Items[this.Items.length] = elem;
                this.Count++;
            }
        
            this.GetElementByName = function(elemName){
                for(i=0;i<this.Items.length;i++){
                    if(this.Items[i].Id==elemName)
                    return this.Items[i];
                }
            }

            
            this.RenderResult = function()
            {
               this.Content = "";
               
               this.TargetPanel = $(this.TargetPanel);
               
               
                        //prompt(tempItemsCollection,tempItemsCollection);
                        this.Content+=FinalistBottomFrameTopHTML();
                        //alert(this.Items.length);
                        var FinalistLoser;
                        if(this.Items[4].Url.substr(29,6)!="237964")
                        {
                           for(i=0;i<this.Items.length;i++)
                            {   
                               
                                if(this.Items[i].Url.substr(29,6) == "237964" )
                                {   
                                    FinalistLoser = i; 
                                    break;                     
                                }
                            }
                            var itemtoReplace=this.Items[4];
                            this.Items[4]=this.Items[FinalistLoser];
                            this.Items[FinalistLoser]=itemtoReplace; 
                        }
                        
                        for(i=0;i<this.Items.length;i++)
                        { 
                            switch(i)
                            {
                                case 4:
                                {
                                    bottomVideoCategory="<div style=\"text-align:left;padding-left:8px;\"><div style=\"text-align:center;height:14px;width:80px;border:2px solid #000000;border-bottom-width:0px;font-size:12px;background-color:#FCB577; \">Finalist</div></div>";
                                    this.Content += RenderFlickItem(this.Items[i],i); 
                                    break;
                                }
                                default:
                                {
                                    bottomVideoCategory="<div style=\"text-align:left;padding-left:8px;\"><div style=\"text-align:center;height:14px;width:80px;border:2px solid #000000;border-bottom-width:0px;font-size:12px;background-color:#ffffff; \">Semi-Finalist</div></div>"
                                    this.Content += RenderFlickItem(this.Items[i],i);
                                    break;
                                }
                            }
                            
                        }
                        //$(currentRelatedtab).style.height = 0 + "px";
                        
                   
                    
               
               this.TargetPanel.innerHTML = this.Content; 
            }
            
            this.PopulateImages=function()
            {
                for(m=0;m<this.Items.length;m++)
                {
                    $("img"+m).src=this.Items[m].ThumbUrl;
                }
            
            }
       }
    
    var defualtImg = new Image();
            defualtImg.src="http://icons.aniboom.com/animations/default.jpg";
    var bottomVideoCategory;
    function RenderFlickItem(flick,pos)
    {
        var bombsImg = switchToImg(flick.Rating);
        
        
        if(flick.Title.length>13)
        {
            flick.Title = flickTitleLength(flick.Title);
        }
        
        
                return ""
                    + "<div id=\"container" + pos + "\" style=\"border:1px soid #C5DEFF;display:inline;text-align:center;margin-bottom:10px; margin-left:15px;float:left;width:100px;height:96px;\">"
                    +  bottomVideoCategory 
                    + "<div onmouseover=\"relatedTabMouseOver('title"+pos+"')\" onmouseout=\"relatedTabMouseOut('title"+pos+"')\"><a href=\""+flick.Url+"\"><img onError=\"SetDefaultImage(this)\" id=\"img" + pos + "\" style=\"width:80px;height:62px;border:2px solid #000000;\" src=\"" + defualtImg.src + "\""
                    + "class=\"RelatedImage\" /></div> "
                    + "<div onmouseover=\"relatedTabMouseOver('title"+pos+"')\" onmouseout=\"relatedTabMouseOut('title"+pos+"')\" style=\"margin-top:2px;\"><a class=\"relatedLink\" style=\"color:#373737;\" href=\""+flick.Url+"\"><span id=\"title" + pos + "\">" + flick.Title + "</span></a></div>"
                    + "</div>";
            
        
       
    }
    
    /* functions for rendering content into html - end*/
    
    

    function SetDefaultImage( obj ) {
        obj.onError!=SetDefaultImage;
       
       obj.src = "http://icons.aniboom.com/animations/default.jpg"

    }
    
    function switchToImg(fullRank)
    {
        fullRank=(fullRank % 0.5) > 0.25 ?
            (fullRank - (fullRank % 0.5) + 0.5) : fullRank - (fullRank % 0.5);
            
            var str =new String(fullRank);
            
            return ("bomb" + str.replace(".5","half") + ".gif");
    }
    
    function flickTitleLength(Title)
    {
        return Title.substr(0,10)+"...";
    }
    function FinalistBottomFrameTopHTML()
    {
         return ""
        + "<div style=\"height:12px;\"></div>" ; 
    } 
  //SwitchView( 'FinalistBottomFrame','FinalistBottomFrame');  
 






