var theMaxImages							= 0;
var currentPos								= 0;
var currentAnimating						= false;
var currentImage							= 0;
// var imagesArray								= new Array();
var serverPath								= new String("");
var projectId								= 0;
var savedHash								= "";
var autoPlayChapter							= true;
var safariBrowser							= false;
var timerIntro								= null;
var nextHIddenImage							= 0;

function initializeVP(maxImages) {
	theMaxImages							= maxImages;
	nextHIddenImage							= 8;
}

function initializeDefaults(server, project, hash) {
	serverPath								= server;
	projectId								= project;
	savedHash								= hash;
}

function stopShow() {
	var mov									= getFlashMovie("theProjectPlayer");
	mov.stopTheMovie();
	currentImage						= 0;
	$(".push_image").fadeTo("fast", 0.5);
}

function startShow() {
	timerIntro								= setTimeout("showIntro()", 4000);
}

function highlightImage(index) {
	if ( null != timerIntro ) {
		clearTimeout(timerIntro);
		timerIntro							= null;
	}

	$(".push_image").fadeTo("fast", 0.5);
	if ( index == nextHIddenImage ) {
		nextHIddenImage++;
		moveRight();
	}
	$("#theImage"+index).fadeTo("fast", 1.0);
}

function showIntro() {
	currentImage							= 0;
	highlightImage(0);

	var mov									= getFlashMovie("theProjectPlayer");
	mov.loadImageGallery(serverPath, projectId, savedHash);
}

function showImage() {
	highlightImage(++currentImage);
}

function imageEnd() {
	if ( autoPlayChapter ) {
		showImage();
	}
}

function chapterEnd() {
	currentImage							= 0;
	nextHIddenImage							= 8;
	resetBar();
	showIntro();
}

function resetBar() {
	for ( idx = 0;idx <= theMaxImages;idx++ ) {
		if ( idx <= 7 )
			$("#theImage"+idx).show();
		else
			$("#theImage"+idx).hide();
	}
	
	currentPos								= 0;
	currentAnimating						= false;
}

function moveLeft() {
	if ( currentAnimating || currentPos <= 0 ) {
		return false;
	}

	currentAnimating						= true;

	var maxPos								= currentPos+7;
	$("#theImage"+maxPos).hide(100, function() {

		var idx								= 0;

		for ( idx = (currentPos+6);idx >= currentPos;idx-- ) {
			$("#theImage"+idx).animate({right: 77}, "normal");
		}

		$("#theImage"+idx).show();

		if ( currentPos > 0 ) {
			currentPos--;
		}

		currentAnimating					= false;
	});	
}

function moveRight() {
	if ( currentAnimating || (currentPos+7) >= theMaxImages ) {
		return false;
	}

	currentAnimating						= true;

	$("#theImage"+currentPos).hide("fast", function() { 
  
		var idx			= 0;

		for ( idx = currentPos+1;idx < currentPos+8;idx++ ) {
			$("#theImage"+idx).animate({left: -77}, "normal");
		}

		$("#theImage"+idx).show();

		if ( currentPos < theMaxImages ) {
			currentPos++;
		}

		currentAnimating					= false;
	});
}
