var theMaxImages							= 0;
var currentPos								= 0;
var currentAnimating						= false;
var currentChapter							= 0;
var chapterArray							= new Array();
var serverPath								= new String("");
var projectId								= 0;
var savedHash								= "";
var autoPlayChapter							= true;
var safariBrowser							= false;
var timerIntro								= null;

function initializeVP(maxImages) {
	theMaxImages							= maxImages;
}

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

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

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

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

	$(".push_image").fadeTo("fast", 0.5);
	$("#theImage"+index).fadeTo("fast", 1.0);
}

function showIntro() {
	currentChapter							= 0;
	highlightChapter(0);

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

function showChapter(chapterId, index) {
	var mov									= getFlashMovie("theProjectPlayer");

	var theDuration							= chapterArray[0].chapterDuration;
	for ( idx = 1;idx < index;idx++ ) {
		theDuration							+= chapterArray[idx].chapterDuration;
	}

	highlightChapter(index);

	mov.loadChapter(serverPath, projectId, chapterId, savedHash, theDuration);
}

function chapterEnd() {
	if ( autoPlayChapter ) {
		if ( chapterArray.length <= (currentChapter+1) ) {
			currentChapter					= 0;
			showIntro();
		}
		else {
			var theChapter					= chapterArray[++currentChapter];
			showChapter(theChapter.chapterId, currentChapter);
		}
	}
}

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;
	});
}