﻿//图片切换效果
(function ($){
    $.fn.PicScroll=function(opt,callback){
		var _this=this;
        var defaults = {
            fx:"0",
            width:200,
            timeout:4000,
            timescroll:800,
            imgId:"",
			titleId:"",
            pagerId:""
        };
		var titleList=null;
        var opts = $.extend(defaults, opt);
        var imgDiv=$(opts.imgId);
        var pageDiv=$(opts.pagerId);
        var currentClass=pageDiv.find("a").eq(0).attr("class");
        var len  = imgDiv.find("img").length;
	    var index = 0;
	    var pageA=pageDiv.find("a");
	    pageA.mouseover(function(){
		    index = pageA.index(this);
		    _this.showImg(index);
	    });
	    //滑入 停止动画，滑出开始动画.
	    _this.MyTime=null;
	    _this.hover(function(){
            if(_this.MyTime){
                clearInterval(_this.MyTime);
            }
	    },function(){
            _this.MyTime = setInterval(function(){
                _this.showImg(index);
                index++;
                if(index==len){index=0;}
            } , opts.timeout);
        }).mouseout();
		if(opts.titleId){
			titleList=$(opts.titleId).find("a");
		}
	    _this.showImg=function(i){
	        if(opts.fx=="0")
	        {
	            imgDiv.stop(true,false).animate({top:-opts.width*i},opts.timescroll);
	        }else{
	            imgDiv.stop(true,false).animate({left:-opts.width*i},opts.timescroll);
	        }
			if(titleList){
				titleList.eq(0).attr("href",titleList.eq(i+1).attr("href"));
				titleList.eq(0).html(titleList.eq(i+1).html());
			}
		    pageA.eq(i).addClass(currentClass).siblings().removeClass(currentClass);
	    }
    }
})(jQuery);
