(function($){
    $(document).ready(function(){

        // get
        var slider = $('#thumbs ul');
        
        if (slider.length)
        {
            var images = $('#thumbs img');
            var imageWidth  = $(images[0]).width();
            imageWidth      = imageWidth < 89 ? 89 : imageWidth;
            var slideWidth  = $('#thumbs').width();
            var sliderWidth = imageWidth * images.length;
            var slides = Math.ceil(sliderWidth / slideWidth);


            // set
            var currentSlide = 1;
            slider.width(sliderWidth)


            // do
            $('#prev, #next').click(function(e)
            {
                e.preventDefault();

                if ($(this).attr('id') == 'prev' && currentSlide > 1)
                {
                    currentSlide--;
                    slider.animate(
                    {
                        marginLeft : '+=' + slideWidth
                    });
                }
                else if ($(this).attr('id') == 'next' && currentSlide < slides)
                {
                    currentSlide++;
                    slider.animate(
                    {
                        marginLeft : '-=' + slideWidth
                    });
                }
            });

            slider.find('a').click(function(e)
            {
                e.preventDefault();

                $.get($(this).attr('href').concat('&block=item'), function(response)
                {
                    $('#object').html(response);
                });
            });
        }
        
        
        // hand
        var pos =
        [
            [  0,  0],
            [ 31,112],
            [ 31,283],
            [ 31,454],
            [103,112],
            [103,283],
            [103,454],
            [175,112],
            [175,283],
            [175,454]
        ];
        
        
        // numpad
        $('.numpad a').hover
        (
            function(enter)
            {
                //var pos    = $(this).position()
                //var height = $(this).height();
                //var width  = $(this).width();
                
                var item = $(this).parent().attr('class').replace(/[^0-9]+/g, '');
                
                $('#hand').css(
                {
                    top  : pos[item][0],//pos.top - (height * 1.5),
                    left : pos[item][1] //pos.left + (width / 1.5)
                }).removeClass('hidden');
            },
            function(leave)
            {
                $('#hand').addClass('hidden');
            }
        ).mousedown(function()
        {
            $('#hand').find('img').toggleClass('hidden');
        }).mouseup(function()
        {
            $('#hand').find('img').toggleClass('hidden');
        });
        
    })
})(jQuery)
