var thisNav;
var curIndex = 0;
var timeInterval = 2500;
var imgDiv = document.getElementById("PicThumbBanner");
var imgList = imgDiv.getElementsByTagName("img");

function splitPanel(img,stop)
{
    if(stop ==1 )
    {
        clearInterval(t);
        img.className = "cp_PicThumbSelect";
        thisNav.className = "cp_PicThumbSelectNo";
    }
    if(thisNav.src == img.src)
    {
        return;
    }
    var url = img.src.replace("PicThumb","PicNatural");
    document.getElementById('PicNaturalShow').src = url;
    document.getElementById('PicNaturalUrl').href = url;
    thisNav = img;
}

if(imgList.length > 0)
{
    imgList[0].className = "cp_PicThumbSelect";
    thisNav = imgList[0];
    var t = setInterval(changeImg,timeInterval);
    function changeImg()
    {
       if (curIndex == imgList.length-1) 
       {
            curIndex = 0;
       }
       else
       {
            curIndex += 1;
       }
       imgList[curIndex].className = "cp_PicThumbSelect";
       if(curIndex == 0)
       {
            imgList[imgList.length-1].className = "cp_PicThumbSelectNo";
       }
       else if(curIndex > 0 && curIndex < imgList.length)
       {
            imgList[curIndex-1].className = "cp_PicThumbSelectNo";
       }
       
       splitPanel(imgList[curIndex],0);
    }
}

var flag=false;
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
        flag=true;
        if(image.width/image.height>= iwidth/iheight){
            if(image.width>iwidth){
                ImgD.width=iwidth;
                ImgD.height=(image.height*iwidth)/image.width;
            }else{
                ImgD.width=image.width;
                ImgD.height=image.height;
            }
            ImgD.alt=image.width+"×"+image.height;
        }
        else{
            if(image.height>iheight){
                ImgD.height=iheight;
                ImgD.width=(image.width*iheight)/image.height;
            }else{
                ImgD.width=image.width;
                ImgD.height=image.height;
            }
            ImgD.alt=image.width+"×"+image.height;
        }
    }
}

