﻿
//设置当前第几块被选中
var _currIndex = 0;
var _maxLength = 2;
var _indexLength = 300;
var _currThis = null;   //当前活动对象，用来清除timer

function myScrollLeft()
{
    if(null != _currThis)
        _currThis.Stop();
        
    var myScroll = new myScroller("ctypeDiv","ctypeUl",{Step:10,Speed:30});
    _currThis = myScroll;
    
    if(_currIndex > 0)
    {
        myScroll.ScrollPanel({ScrollSide:'right',PauseWidth:_indexLength});
        _currIndex --;
    }
    else
    {
        myScroll.ScrollPanel({ScrollSide:'left',PauseWidth:_indexLength * _maxLength});
        _currIndex = _maxLength - 1;
    }
    
    setMyCurrImg(_currIndex);
}

function myScrollRight()
{
    if(null != _currThis)
        _currThis.Stop();
        
    var myScroll = new myScroller("ctypeDiv","ctypeUl",{Step:10,Speed:30});
    _currThis = myScroll;
    
    if(_currIndex < _maxLength - 1)
    {
        myScroll.ScrollPanel({ScrollSide:'left',PauseWidth:_indexLength});
        _currIndex ++;
    }
    else
    {
        myScroll.ScrollPanel({ScrollSide:'right',PauseWidth:_indexLength * (_maxLength - 1)});  //左滚动时少一格
        _currIndex = 0;
    }
    
    setMyCurrImg(_currIndex);
}

function myScrollImgClick(ind)
{
    ind = ind - 0;
    if(isNaN(ind))
        return;
        
    if(ind == _currIndex || ind < 0 || ind >= _maxLength)
        return;
        
    if(null != _currThis)
        _currThis.Stop();
        
    var myScroll = new myScroller("ctypeDiv","ctypeUl",{Step:10,Speed:30});
    _currThis = myScroll;
    
    if(ind < _currIndex)
        myScroll.ScrollPanel({ScrollSide:'right',PauseWidth:_indexLength * (_currIndex - ind)});
    else
        myScroll.ScrollPanel({ScrollSide:'left',PauseWidth:_indexLength * (ind - _currIndex)});
    
    _currIndex = ind;
    setMyCurrImg(_currIndex);
}

function setMyCurrImg(ind)
{
    var imgPanel = document.getElementById("_comTypeList_Panel");
    var imgs = imgPanel.getElementsByTagName("img");
    for(var i = 0; i < imgs.length; i++)
    {
        imgs[i].src = "images/idd2.gif";
    }
    imgs[ind].src = "images/idd1.gif";
}

//window.onload=function(){
//    setInterval(function(){
//        myScrollRight();
//    },5000);
//};
