/*
  图片滚动  for 古龙集团
  author by zmyfujian  
  qq  87651357
  update 2010 9-1
*/

$(document).ready(function() {
	
	$("#i-shop-list").scrollImg1(181,4000,null,null,800);	
	
	
});


(function($) {   
     var curIndex=0;
	 var obj=new Object();
	 /*
	 objid: 对象ID
	 w: 对象嵌套子项
	 sp_t:切换间隔时间
	 lcid:左控制id
	 rcid:右控制id
	 sc_t:滚动需要的时间
	 */
	
     $.fn.scrollImg1 = function(w,sp_t,lcid,rcid,sc_t) {  	
	    obj=this;
        obj.objid=this.attr("id");	
		obj.w=w;
		obj.sp_t=sp_t;
		obj.lcid=lcid;
		obj.rcid=rcid;
		obj.sc_t=sc_t;
	    obj.l = this.find("li").length * obj.w;
		obj.intervalId =setInterval(scrollImg, obj.sp_t);		
		scrollImg();
      
        obj.hover(function() {			   
                window.clearInterval(obj.intervalId);
        },
        function() {	
		        
                obj.intervalId = setInterval(scrollImg, obj.sp_t);
				scrollImg();
        }
        );	   
    };	
	function debug(){alert("aa");}
	function scrollImg() {		
        curIndex++;
        var lv = -1 * curIndex * obj.w;
        var abs_lv;
        if (lv > 0) {
                lv = 0;
        } else {
                abs_lv = Math.abs(lv);
                if (abs_lv % obj.w != 0) {
                        lv = ( - 1) * obj.w * (abs_lv / obj.w )
                }
                abs_lv = Math.abs(lv);
                if (abs_lv > (obj.l - obj.w)) {
                        lv = 0;
                        curIndex = 0;
                }
				
               $("#"+obj.objid).animate({
                        left: lv,
                        top: [0, "swing"]
                },
                obj.sc_t);
        }

     };
	
	
})(jQuery);    

