$(document).ready(function() {
    $('div#slideShow').cycle({ timeout:3000 });

    $('div.noticeBox').slideDown('slow');
    $('a.noticeBoxCloseLink').click(function() {
        $('div.noticeBox').slideUp('slow');
        return false;
    }); 
    
    $('#aboutService').click(function() {
        $('#aboutServiceTxt').slideToggle('slow');
        return false;
    });
    
    var paddedShirtIndex = 0;
    var shirts = $('#lastShirts li');
    
    //Shirts hovering
    shirts.each(function(k, v) {
        $(v).hover(function() { 
            $(this)
                .stop(true, true)
                .animate({
                    paddingTop: "0",
                    paddingBottom: "55px"
                }, 'fast');
        }, function() {
            $(this)
                .stop(true, true)
                .animate({
                    paddingTop: "20px",
                    paddingBottom: "35px"
                }, 'fast');
        });
    });
    
    //Right scroller
    var rScroller = $('#rScroller')
        .click(function(){
            if (!$(this).hasClass('disabled')) {
                scroll('right');
            }
        })
        .hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover') });
    
    //Left scroller
    var lScroller = $('#lScroller')
        .click(function(){
            if (!$(this).hasClass('disabled')) {
                scroll('left');
            }
        })
        .hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover') })
        .addClass('disabled');
    
    //Do a scroll
    var scroll = function(dir) {
		if (dir == 'left') {
		
		    $(shirts[paddedShirtIndex - 1]).animate({ marginLeft: "0" });
		    paddedShirtIndex--;
		} else {
		    $(shirts[paddedShirtIndex]).animate({ marginLeft: "-185px" });
		    paddedShirtIndex++;
		}
		
        scrollerChange('shirts', lScroller, rScroller, shirts.length, paddedShirtIndex, 3);
	}   
	
	//Scrolling restrictions check
    var scrollerChange = function (name, left, right, maxlen, comparer, remainder) {
        if (comparer == 0){
    		left.addClass('disabled');
    	} else {
    		left.removeClass('disabled');
    	}

    	if (comparer == maxlen - remainder){
    		right.addClass('disabled');
    	} else {
    		right.removeClass('disabled');
    	}
    } 
    
});

