$(document).ready(function(){
    
        
    $.local = {
        init: function()
        {
            $.local.initProductsBaner();
        },
        initProductsBaner: function()
        {

            $('.udo a').each(function(){
                $(this).wrap('<div style="float: left;"/>');
            });

            var speed = 20;
			var mouseenter = [5,5]; // interval speed/pxls
			var mouseleave = [20,1];
			var pxls = 1;
            var interval = setInterval(function() {
                animateToLeft();
            }, speed);
            
            function animateToRight(){
                var wid = $('.ban1 > div > div:visible:last').width();
                var marg = $('.ban1 > div > div:visible:last').css('margin-left');
                var cut = marg.length;
                cut = cut-2;
                marg = marg.slice(0,cut);
                if((Math.abs(marg)-1300) >= Math.abs(wid)){
                    var item =  $('.ban1 > div > div:visible:last').detach();
                    item.css('margin-left', '0px').appendTo('.ban1 > div');
                    $('.ban1 > div > div:visible:last').animate({
                        marginLeft: '+='+pxls+'px'
                    }, 0);
                }else{
                    $('.ban1 > div > div:first').animate({
                        marginLeft: '+='+pxls+'px'
                    }, 0);
                }
            }
            function animateToLeft(){
                var wid = $('.ban1 > div > div:first').width();
                var marg = $('.ban1 > div > div:first').css('margin-left');
                var cut = marg.length;
                cut = cut-2;
                marg = marg.slice(0,cut);
                if(Math.abs(marg) >= Math.abs(wid)){
                    var item =  $('.ban1 > div > div:first').detach();
                    item.css('margin-left', '0px').appendTo('.ban1 > div');
                    $('.ban1 > div > div:first').animate({
                        marginLeft: '-='+pxls+'px'
                    }, 0);
                }else{
                    $('.ban1 > div > div:first').animate({
                        marginLeft: '-='+pxls+'px'
                    }, 0);
                }
            }
                
            $('.ban1 > div').live('mouseenter',function(){
                clearInterval(interval);
            }).live('mouseleave', function(){
				speed = mouseleave[0];
                interval = setInterval(function() {
                    animateToLeft();
                }, speed);
            });

            $('#scroll-right').live('mouseenter', function(){
                speed = mouseenter[0];
				pxls = mouseenter[1];
				clearInterval(interval);
                interval = setInterval(function() {
                    animateToRight();
                }, speed);
            }).live('mouseleave', function(){
                speed = mouseleave[0];
				pxls = mouseleave[1];
				clearInterval(interval);
                interval = setInterval(function() {
                    animateToLeft();
                }, speed);
            });

            $('#scroll-left').live('mouseenter', function(){
                speed = mouseenter[0];
				pxls = mouseenter[1];
				clearInterval(interval);
                interval = setInterval(function() {
                    animateToLeft();
                }, speed);
            }).live('mouseleave', function(){
                speed = mouseleave[0];
				pxls = mouseleave[1];
				clearInterval(interval);
				interval = setInterval(function() {
                    animateToLeft();
                }, speed);
            });    
        }
        
    }
    
    // init local
    $.local.init();
});
