var __is_loading__      = false;
var __page_index__      = 1;
var __page_count__      = 0;
var __record_count__    = 0;
var __page_size__       = 10;
var __select_team__     = 0;
var __select_show__     = 0;
var __call_page__       = "/ExpressVu/NHLHighlightsAJAX.aspx";
var NHLCarouselAjax;
var carouselResult;


function ChangeState()
{
    objselectTeam =document.getElementById("selectTeam");
    __select_team__ =objselectTeam.options[objselectTeam.selectedIndex].value;
    objselectShow =document.getElementById("selectShow");
    __select_show__ =objselectShow.options[objselectShow.selectedIndex].value;
    __callAJAXPage(__select_team__ , __select_show__ , 1);
}

function __callPrevious(){
    if (__is_loading__)
        return;
    else
        __callAJAXPage(__select_team__ , __select_show__ , --__page_index__);
}
function __callNext(){
    if (__is_loading__)
        return;
    else
        __callAJAXPage(__select_team__ , __select_show__ , ++__page_index__);
}

function __callAJAXPage(intselectteam,intselectshow,intPageIndex)
{
    if (__is_loading__)
        return;
          
    var ajax = new AJAX(GetAbsoluteUrl(__call_page__));
    ajax.AddUrlParameter('TeamType',  intselectteam);
    ajax.AddUrlParameter('ShowType',  intselectshow);
    ajax.AddUrlParameter('PageIndex',  intPageIndex);
    ajax.AddUrlParameter('PageSize',   __page_size__);
    ajax.SetCallbackFun(__fillPageData);
    ajax.Send(null);
}



function __fillPageData(ajax)
{
                                                    
    var __wx_list_item__ ='<div class="items">'+
								'<div class="thumbnail">'+
									'<div class="thumbnailspacer"></div>'+
									'<div class="thumbnaillink"><a href="$1" class="thumbnail"><div class="thumbnaillink"></div></a></div>'+
									'<div class="thumbnailplay"><div class="shadow"></div><div class="buttonimage"></div></div>'+
									'<div class="thumbnailimg"><img src="$9" width="120" height="80" /></div>'+
								'</div>'+
								'<div class="itemGraphicScore">'+
									'<div class="team"><img src="$2" width="25" height="25" /><br />$3 $4</div>'+
									'<div class="vs"></div>'+
									'<div class="team"><img src="$5" width="25" height="25" /><br />$6 $7</div>'+
								'</div>'+
								'<div class="itemScore">$8</div>'+
							'</div>';                        
                            
    var strhtml = '';
    var box  = document.getElementById("whileitems");
    var doc  = ajax.GetXmlDoc();
    if (!__is_loading__) 
    {
        __is_loading__     = true;
        __page_index__     = parseInt(doc.selectSingleNode("//xmlRoot/pageIndex").text,10);
        __page_count__     = parseInt(doc.selectSingleNode("//xmlRoot/pageCount").text,10);
        __record_count__   = parseInt(doc.selectSingleNode("//xmlRoot/recordCount").text,10);
       
       
        __fillNavigation(__select_team__ , __select_show__ , __page_index__, __page_count__);
        
        if (__record_count__ > 0) 
        {
            var nodes = doc.selectNodes("//xmlRoot/records/record");
            for(var i = 0; i < nodes.length; i++)
            {
                var GameID      = nodes[i].selectSingleNode("GameID").text;
                var vislink     = nodes[i].selectSingleNode("Number").text;
                var VisLog      = nodes[i].selectSingleNode("VisTeamLog").text;
                var VisTeam     = nodes[i].selectSingleNode("VisTeam").text;           
                var VisScore    = nodes[i].selectSingleNode("VisScore").text;                
                var HomeLog     = nodes[i].selectSingleNode("HomeTeamLog").text;               
                var HomeTeam    = nodes[i].selectSingleNode("HomeTeam").text;                         
                var HomeScore   = nodes[i].selectSingleNode("HomeScore").text;              
                var EST         = nodes[i].selectSingleNode("EST").text;
                var ESTByPic    = nodes[i].selectSingleNode("ESTByPic").text;
                
                strhtml += String.format(
                            __wx_list_item__
                            , vislink
                            , VisLog
                            , VisTeam
                            , VisScore
                            , HomeLog 
                            , HomeTeam
                            ,HomeScore
                            ,EST
                            ,ESTByPic
                            );

            }
        }
        box.innerHTML   = strhtml;
        if (__record_count__ == 0)
        {
           document.getElementById("sprecord").innerHTML      ="0 ";
           document.getElementById("sprecordcount").innerHTML ="0 ";
           __is_loading__  = false;
        }
        else
        {
          var intStart=0;
          var strStart='';
          var intEnd=0;
          var strEnd=''
          
          intStart=((__page_index__ - 1) * __page_size__)+1;
          strStart=intStart;
          
          intEnd=(__page_index__) * __page_size__;
          if (intEnd<__record_count__)
          {
             strEnd=intEnd;
          }
          else
          {
            strEnd=__record_count__;
          }   
          
          document.getElementById("sprecord").innerHTML      =strStart +"-"+ strEnd +" ";
          document.getElementById("sprecordcount").innerHTML =__record_count__+" ";
          __is_loading__  = false;
        }
    }
    
    decorateEvThumbs();
}

function __fillNavigation(intselectteam,intselectshow,intPageIndex, intPageCount)
{
    var navtop      = document.getElementById("wxListNavtop");
    var previoustop = document.getElementById("wxPrevioustop");
    var nexttop     = document.getElementById("wxNexttop");
    var navbot      = document.getElementById("wxListNavbot");
    var previousbot = document.getElementById("wxPreviousbot");
    var nextbot     = document.getElementById("wxNextbot");
    
    var strhtml  =  "<a style='cursor:pointer' "+
                 "onclick=\"__callAJAXPage("+ intselectteam +" , "+ intselectshow +" , "+"1)\" "+
                 "class=\"" + (intPageIndex == 1 ? "on" : "count") + "\">1</a>";
    
    if(intPageIndex <= intPageCount / 2)
    {
        if( intPageCount >= 5 && intPageIndex > 3)
            strhtml += "<a href=\"javascript:void(0);\" class=\"count\">...</a>";
        
        for( var i = intPageIndex - 1; i <= intPageIndex + 2; i++)
        {
            if( i <= 1 )
                continue;
            if( i >= intPageCount )
                continue;
            strhtml += "<a style='cursor:pointer' "+
                       "onclick=\"__callAJAXPage("+ intselectteam +" , "+ intselectshow +" , " + i + ")\" "+
                       "class=\"" + (i == intPageIndex ? "on" : "count") + "\">" + i + "</a>";
        }
        if( intPageCount >= 5 && intPageIndex < intPageCount - 3)
            strhtml += "<a href=\"javascript:void(0);\" class=\"count\">...</a>";
    }
    else
    {
        if( intPageCount >= 5 && intPageIndex > 4)
            strhtml += "<a href=\"javascript:void(0);\" class=\"count\">...</a>";
            
        for( var i = intPageIndex - 2; i <= intPageIndex + 1; i++)
        {
            if( i <= 1 )
                continue;
            if( i >= intPageCount )
                continue;    
            strhtml += "<a style='cursor:pointer' "+
                       "onclick=\"__callAJAXPage("+ intselectteam +" , "+ intselectshow +" , " + i + ")\" "+
                       "class=\"" + (i == intPageIndex ? "on" : "count") + "\">" + i + "</a>";
        }
        if( intPageCount >= 5 && intPageIndex <= intPageCount - 3)
            strhtml += "<a href=\"javascript:void(0);\" class=\"count\">...</a>";
    }
    if (intPageCount > 1)
        strhtml += "<a style='cursor:pointer' "+
                "onclick=\"__callAJAXPage("+ intselectteam +" , "+ intselectshow +" , " + intPageCount + ")\" "+
                "class=\"" + (intPageIndex == intPageCount ? "on" : "count") + "\">" + intPageCount + "</a>";
    navtop.innerHTML = strhtml;
    navbot.innerHTML = strhtml;
    
    if (intPageIndex <= 1) 
        {
           previoustop.style.display = 'none';
           previousbot.style.display = 'none';
        }
    else
        {
          previoustop.style.display = '';
          previousbot.style.display = '';
        }
        
    if (intPageIndex - intPageCount >= 0) 
        {
          nexttop.style.display = 'none';
          nextbot.style.display = 'none';
        }
    else
       {
         nexttop.style.display = '';
         nextbot.style.display = '';
        }

}

function ShowNHLHighlightsCarousel() 
{
//    gender = document.getElementById("spanAction").innerHTML;
    document.getElementById('carouselHolderOne').innerHTML = "";
    NHLCarouselAjax = new AJAX(GetAbsoluteUrl("NHLHighlightsCarouselAjax.aspx"));
    //tvCarouselAjax = new AJAX(GetAbsoluteUrl("NHLHighlightsCarouselAjax.aspx"));  
    //tvCarouselAjax.AddUrlParameter("gender",gender);
    //tvCarouselAjax.SetCallbackFun(callbackTvCarousel);
    //tvCarouselAjax.Send(null);
    NHLCarouselAjax.SetCallbackFun(callbackNHLHighlightsCarousel);
    NHLCarouselAjax.Send(null);
    
}

function callbackNHLHighlightsCarousel() 
{
    carouselResult = NHLCarouselAjax.m_objXML.responseText;
    carouselResult = eval(carouselResult);
    CarouselPane(carouselResult,1,"carouselHolderOne",true);
}

function doItemClick(obj) {
    window.open(obj,"_self");
}


