﻿
$(document).ready(function(){
    
    //当前显示的图片下标
    var showIndex=0;
    //隐藏的图片下标
    var hideIndex=0;
    //播放时间
    var playTime=2300;
    //暂停时间
    var suspendedTime=1000;
    //所有轮播的图片对象
    var imgArr=$(".fadeImg:first img");
    $(".fadeImg:first img").not(":first").hide();            
    $.extend({
        next:function(){
            hideIndex=showIndex;
            ++showIndex;                    
            if(showIndex>=imgArr.length)
            {
                showIndex=0;
                hideIndex=imgArr.length-1;
            }
            
            imgArr.eq(hideIndex).fadeTo(playTime,0);
            //setTimeout("function(){this.imgArr.eq(hideIndex).hide()}",playTime)
            imgArr.eq(showIndex).fadeTo(playTime,1)
        },
        pre:function(){
            hideIndex=showIndex;
            --showIndex;
            if(showIndex<0)
            {
                showIndex=imgArr.length-1;
                hideIndex=0;
            }
            imgArr.eq(hideIndex).fadeTo(playTime,0);
            //setTimeout("function(){this.imgArr.eq(hideIndex).hide()}",playTime)
            imgArr.eq(showIndex).fadeTo(playTime,1)
        },
        suspendedPlay:function(){
            self.setTimeout("$.next()",suspendedTime);
        }
    });
    
    $("a#pre:first").click(function(){
        $.pre();
    });
    
    $("a#next:first").click(function(){
        $.next();
    });
    
    $.suspendedPlay();
    
    var autoPlay=self.setInterval("$.suspendedPlay()",playTime+suspendedTime);
    
    imgArr.mouseover(function(){
        self.clearInterval(autoPlay);
    });
    
    imgArr.mouseout(function(){
        //$.next();
        autoPlay=self.setInterval("$.next()",playTime+suspendedTime);
    });
    
});
