function SetButtonStatuses(currentPosition, maxNumber, nb){
    if (currentPosition + maxNumber >= nb) {
        $('#downscroll_gal img').attr({
            "src": "images/down_disabled_gal.png"
        });
        $('#downscroll_gal img').unbind("click");
	
    }
    else {
        $('#downscroll_gal img').attr({
            "src": "images/down_gal.png"
        });
        $('#downscroll_gal img').click(Scroll);
    }
    
    if (currentPosition <= 0) {
        $('#upscroll_gal img').attr({
            "src": "images/up_disabled_gal.png"
        });
        
        $('#upscroll_gal img').unbind("click");
    }
    else {
        $('#upscroll_gal img').attr({
            "src": "images/up_gal.png"
        });
        $('#upscroll_gal img').click(Scroll);
    }
}

function Scroll(){

    if ($(this).attr("alt") == "up") 
        direction = 1;
    else 
        direction = -1;
    
    var item_height = $('#gallery_ul li').outerHeight();
    var top_indent = parseInt($('#gallery_ul').css('top')) + (direction * item_height);
    var currentPosition = -parseInt(top_indent / item_height);

    $('#gallery_ul').animate({
        'top': top_indent
    }, 500, function(){
        $('#gallery_ul').css({
            'top': top_indent
        });
        
    });
    
    SetButtonStatuses(currentPosition, maxNumber, nb);
    
    
}



$(document).ready(function(){
    nb = $('#gallery_ul li').size();
	$(".main_gal_header span:last").attr({innerHTML:nb});
	if (nb == 0)
	{
	   $(".main_gal_header span:first").attr({innerHTML:0}); 
	}
    maxNumber = 3;
	$('#gallery_ul li').click(function(){
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL;
		var no = $('#gallery_ul li').index(this) + 1;
		$(".main_gal img").attr({ src: imgTitle , alt: imgAlt});
		$(".main_gal a").attr({href:imgTitle});
		$(".main_gal_header span:first").attr({innerHTML:no});
     });
     
    
    $('#upscroll_gal img').attr({
        "src": "images/up_disabled_gal.png"
    });
    if (nb > maxNumber) {
        $('#downscroll_gal img').click(Scroll);
    }
    else {
        $('#downscroll_gal img').hide();
        $('#upscroll_gal img').hide();
    }
	
	
});
