﻿
$(function(){
    var page = 1;
    var len = $('.prolist_content > ul > li').length;
    var i =4;
    page_count = 4;
    $('.prolist_content').css('width',len*160);
    var display_width = 160;
    var $prolist = $('.prolist_content');
    var timoutid1 = 0;
    var timoutid2 = 0;
    var timoutid3 = 0;
	$(".prolist_content > ul > li").hover(
	  function () {
	    $(".goRight").unbind('click');
	    clearTimeout(timoutid2);
	  },
	  function () {
	    bindClick();
		timoutid3 = window.setTimeout(function(){
			$('.goRight').click()
		},2000);
	  }
	); 
    
    function bindClick(){
    $(".goRight").bind("click",function(){
        if (!$prolist.is(':animated')) {
    		$('.prolist_content').animate({
                    left: "-=" + display_width + 'px'
                }, 300,function(){
				clearTimeout(timoutid1);
	    		clearTimeout(timoutid3);
				clearTimeout(timoutid2);
				var first_li = $(".prolist_content > ul > li:first-child");
				var last_li = $(".prolist_content > ul > li:last-child");
	    		$(last_li).after(first_li);
	    		$('.prolist_content').css({left:'0px'});
				timoutid2 = window.setTimeout(function(){
					$('.goRight').click()
				},2000);
    		});
    	}
    });
    }
    
	$('.goLeft').mouseout(function(){
	    bindClick();
		timoutid2 = window.setTimeout(function(){
			$('.goRight').click()
		},2000);
	}); 
	
    $('.goLeft').click(function(){
	    $(".goRight").unbind('click');
        if (!$prolist.is(':animated')) {
        var first_li = $(".prolist_content > ul > li:first-child");
		var last_li = $(".prolist_content > ul > li:last-child");
   		$(first_li).before(last_li);
   		$('.prolist_content').css({left:'-160px'});
    		$('.prolist_content').animate({
                    left: "+=" + display_width + 'px'
                }, 300,function(){
    		});
        }
    });
    bindClick();
	timoutid1 = window.setTimeout(function(){
		$('.goRight').click()
	},2000);
})
