var ScrollerHolderWidth = 682;
var ScrollerSlideWidth = 682;
// Slider: to move one slide at a time
// Holder: to move by all slides that fit in one holder
var ScrollerMoveBy = 'Holder';

var ScrollerID = 'Slider';
var ScrollerSpeed = 17500;
var IntervalDelay = 5000;
var IntervalStorage = null;

var LargeImageHolder = 'ImageLarge';

$(document).ready(function() {
	
	IntervalStorage = window.setInterval(function() { MoveScroller( 'Right' ) }, IntervalDelay);
	
	$('#SlideWrapup').bind({
		mouseenter: function() {
			window.clearInterval(IntervalStorage);
		},
		
		mouseleave: function() {
			IntervalStorage = window.setInterval(function() { MoveScroller( 'Right' ) }, IntervalDelay);
		}
	});
	
	$('div.Slider div.SliderArrow.LeftArrow').bind('click', function() {
		MoveScroller( 'Left' );		
	});

	$('div.Slider div.SliderArrow.RightArrow').bind('click', function() {
		MoveScroller( 'Right' );		
	});
		
});

function MoveScroller( Direction ) {
	var MoveX;
	if( ScrollerMoveBy == 'Holder' ) {
		MoveX = ScrollerHolderWidth;
	} else {
		MoveX = ScrollerSlideWidth;
	}
	
	var position = $('#' + ScrollerID ).position();
	if( Direction == 'Left' ) {
		if( position.left < 0 ) {
			$( '#' + ScrollerID ).animate({
				left: '+=' + MoveX + ''
			}, ' + ScrollerSpeed + ', function() {
			    // Animation complete.
				position = $('#' + ScrollerID ).position();
				//VisibilityLeftButton( position.left );
				//VisibilityRightButton( position.left );
			});				
		} else {
			$( '#' + ScrollerID ).animate({
				left: "-" + ($('#' + ScrollerID).width() - $('.Slide').width())
			}, ' + ScrollerSpeed + ', function() {
			    // Animation complete.
				position = $('#' + ScrollerID ).position();
				//VisibilityLeftButton( position.left );
				//VisibilityRightButton( position.left );
			});	
		}
	} else {
		var ScrollerWidth = $('#' + ScrollerID ).width();
		if( ( position.left - ScrollerSlideWidth - ScrollerHolderWidth ) > ( 0 - ScrollerWidth - 1 ) ) {
			$( '#' + ScrollerID ).animate({
				left: '-=' + MoveX + ''
			}, ' + ScrollerSpeed + ', function() {
			    // Animation complete.
				position = $('#' + ScrollerID ).position();
				//VisibilityLeftButton( position.left );
				//VisibilityRightButton( position.left );
			});				
		} else {
			$( '#' + ScrollerID ).animate({
				left: '0'
			}, ' + ScrollerSpeed + ', function() {
			    // Animation complete.
				position = $('#' + ScrollerID ).position();
				//VisibilityLeftButton( position.left );
				//VisibilityRightButton( position.left );
			});	
		}
	}		
}

function VisibilityLeftButton( positionLeft ) {
	if( positionLeft >= 0 ) {
		$('div.Slider div.SliderArrow.LeftArrow').hide();
	} else {
		$('div.Slider div.SliderArrow.LeftArrow').show();
	}
}

function VisibilityRightButton( positionLeft ) {
	var aSlides = jQuery.makeArray($(".Slide"));
	var iSlides = Math.ceil(aSlides.length / 1);
	var iWidth = iSlides * ScrollerHolderWidth;
	var iMaxLeftNegative = 0 - ( iWidth - ScrollerHolderWidth );

	if( positionLeft <= iMaxLeftNegative ) {
		$('div.Slider div.SliderArrow.RightArrow').hide();
	} else {
		$('div.Slider div.SliderArrow.RightArrow').show();
	}
}
