$(document).ready(function(){
	$("#galleryBox div.slideContent").hide().css('position', 'absolute');
	lastBlock = $("#galleryBox div.slideContent:first").show();
	lastBlock.css({'left': '0px'});
	oneWidth = 900;
	
	var i;
	$("#gallerySlider embed").attr('wmode','transparent');
	
	$("#sliderMenu li:first").addClass('active');

	$("#sliderMenu li a").click(function () {
		if ($(this).parent().hasClass('active')) {
			return false;
		}
		
		if ($(this).parent().nextAll('.active').length == 0) { // need to scroll left 
			lastBlock = scrollBlocksRight(lastBlock, '#galleryBox div.slideContent', 900,
				$('#' + $(this).attr('rel'))
			);
		}
		else {
			lastBlock = scrollBlocksLeft(lastBlock, '#galleryBox div.slideContent', 900,
				$('#' + $(this).attr('rel'))
			);
		}
		
		return false;
	});
	
	$("#buttonLeft").click(function () { 
		lastBlock = scrollBlocksLeft(lastBlock, '#galleryBox div.slideContent', 900, null);
		return false;
	});
	
	$("#buttonRight").click(function () { 
		lastBlock = scrollBlocksRight(lastBlock, '#galleryBox div.slideContent', 900, null);
		return false;
	});
	
});	

scrollBlocksRight = function(lastBlk, selector, maxWidth, animateBlock)
{
	if (animateBlock == null) {
		if (lastBlk.next().length == 0) {
			animateBlock = $(selector + ':first');
		}
		else {
			animateBlock = lastBlk.next();
		}
	}
	
	animateBlock.css({
		'left': maxWidth + 'px'
	}).show();
	
	lastBlk.animate({left: '-' + maxWidth + 'px'}, { queue:false, duration:1500, "complete": function(){
		$(this).hide().css({'left': '0px', 'right': '0px'});
	} });
	
	animateBlock.animate({left: '0px'}, { queue:false, duration:1500, "complete": function(){
		$('#sliderMenu li').removeClass('active');
		$('#sliderMenu li a[rel="' + $(this).attr('id') + '"]').parent().addClass('active');
	}});
	
	return animateBlock;
};

scrollBlocksLeft = function(lastBlk, selector, maxWidth, animateBlock)
{
	if (animateBlock == null) {
		if (lastBlk.prev().length == 0) {
			animateBlock = $(selector + ':last');
		}
		else {
			animateBlock = lastBlk.prev();
		}
	}
	
	animateBlock.css({
		'left': '-' + maxWidth + 'px'
	}).show();
	
	lastBlk.animate({left: maxWidth + 'px'}, { queue:false, duration:1500, "complete": function(){
		$(this).hide().css({'left': '0px', 'right': '0px'});
	} });
	
	animateBlock.animate({left: '0px'}, { queue:false, duration:1500, "complete": function(){
		$('#sliderMenu li').removeClass('active');
		$('#sliderMenu li a[rel="' + $(this).attr('id') + '"]').parent().addClass('active');
	}});
	
	return animateBlock;
};

