$(function() {
    time=500;


    function move_left(obj)
    {
        $(obj).find(".cont").stop();
        var clientsize=$(obj).find(".view").width();
        step=clientsize-20;
        ttime=time;
        if (obj.wheel){step=300;time=200;}
        var possize=$(obj).find(".cont").width();
        diff=(clientsize-possize);
        obj.lastleft=obj.lastleft+step;
        if (obj.lastleft>0){obj.lastleft=0;}
        $(obj).find(".cont").animate({'left':obj.lastleft+'px'},ttime);
        obj.wheel=false;
    }

    function move_right(obj)
    {
        $(obj).find(".cont").stop();
        var clientsize=$(obj).find(".view").width();
        step=clientsize-20;
        ttime=time;
        if (obj.wheel){step=300;time=200;}
        var possize=$(obj).find(".cont").width();
        diff=(clientsize-possize);
        if (clientsize<possize)
        {
            obj.lastleft=obj.lastleft-step;
            if (obj.lastleft<diff) obj.lastleft=diff;
            $(obj).find(".cont").animate({'left':obj.lastleft+'px'},ttime);
        }
        obj.wheel=false;
    }


    $(".galleryBox").each(function()
    {
        this.wheel=false;
        this.lastleft=0;
        //$(this).find('a[rel=lightbox]').slimbox(); // Select all links that contains lightbox in the attribute rel
        //$(this).find('detail-event.a'); // Select all links that contains lightbox in the attribute rel



        $(this).find(".left").click(function()
        {
            move_left($(this).parent()[0]);
        });
        $(this).find(".right").click(function()
        {
            move_right($(this).parent()[0]);
        });

        $(this).find('.left,.right').mouseover(function()
        {
            this.style.backgroundPosition='0px 0px';
        });

        $(this).find('.left,.right').mouseout(function()
        {
            this.style.backgroundPosition='0px 21px';
        });

        $(this).mousewheel(function(event, delta) {
            this.wheel=true;
            if (delta>0)
            {
                move_left(this);
            }else
            {move_right(this);}
            return false;
        });


    });
   

    
    wheel=false;




   


    
});

