// JavaScript Document
speed = 2000; //speed factor, the more - the slower
$(document).ready(function(){
    initScroll("#g");
    $("#g .g_scroller").width(($("#g .g_scroller ul li").length * 320) + 20);
     initScroll("#cg");
    $("#cg .g_scroller").width(($("#cg .g_scroller ul li").length * 320) + 20);
   
	function initScroll(type){
        $(type + "_left").hover(function(){
            $(this).css('background','url(/i/arrow_left_hover.png) no-repeat');
			var wrapper_width = $(type).width();
            var div = $(type + " div.g_scroller");
            var width = div.width();
            if (width <= wrapper_width) 
                return;
            var left = parseInt(div.css("left"));
            if (left >= 0) {
                left = 0;
                div.css("left", left + "px");
                return;
            }
            div.animate({
                left: 0
            }, -left * speed / 1000);
        }, function(){
            $(this).css('background','none');
			$(type + " div").stop();
        });
        
        $(type + "_right").hover(function(){
            $(this).css('background','url(/i/arrow_right_hover.png) no-repeat');
			var wrapper_width = $(type).width();
            var div = $(type + " div.g_scroller");
            var width = div.width();
          if (width <= wrapper_width) 
           return;
            var left = parseInt(div.css("left"));
          if (left == wrapper_width - width) 
			return;
            div.animate({
                left: wrapper_width-width
            }, (width - wrapper_width + left) * speed / 1000);
        }, function(){
            $(this).css('background','none');
			$(type + " div").stop();
        });
    }

});
