// -----------------------------------------------------------------------------------
//
//  Photobook Handler
//  requires Prototype and Scriptaculous
//
//	Photobook v0.unversioned
//
// -----------------------------------------------------------------------------------
/*

	var photoList = new Array();
	photoList.push('p1.jpg');
	photoList.push('p2.jpg');
	photoList.push('p3.jpg');
	
	var myPhotobook = new photobook( photoList );
	
	myPhotobook.show();
	myPhotobook.hide();

	
*/
// -----------------------------------------------------------------------------------

// Check for prototype and scriptaculous

if((typeof Effect =='undefined') || 
   (typeof Prototype =='undefined') || 
   (typeof Element == 'undefined') || 
   (typeof Element.Methods =='undefined') ||
   parseFloat(Prototype.Version.split(".")[0] + "." +
              Prototype.Version.split(".")[1]) < 1.6) {
	throw("modal generator requires the Prototype JavaScript framework >= 1.6.0 and script.aculo.us");
}

// constructor

function photobook (pageArray) {
	// initialise variables

	this.currentPage = 1;
	this.pageArray = $A(pageArray);
	this.totalPages = this.pageArray.size();
	
	this.updatePagination();
}

photobook.prototype.canGoNext = function () {
	return (this.currentPage < this.totalPages);
}

photobook.prototype.canGoPrevious = function () {
	return (this.currentPage > 1);
}

photobook.prototype.updatePagination = function () {
	
	if (this.canGoNext()) {
		$('pb_next').show();
	} else {
		$('pb_next').hide();
	}
	if (this.canGoPrevious()) {
		$('pb_previous').show();
	} else {
		$('pb_previous').hide();
	}
	
}

photobook.prototype.nextPage = function () {
	this.currentPage++;
	this.updatePage();
	this.updatePagination();
}

photobook.prototype.previousPage = function () {
	this.currentPage--;
	this.updatePage();
	this.updatePagination();
}

photobook.prototype.updatePage = function () {
	$('bespoke_photo').hide(); 
	$('bespoke_photo').onload = function () { new Effect.Appear('bespoke_photo'); };
	$('bespoke_photo').src = this.pageArray[(this.currentPage - 1)];
}

photobook.prototype.show = function () {
	$('container_viewbook_popup').setStyle( {display: 'block'} );
}

photobook.prototype.hide = function () {
	$('container_viewbook_popup').setStyle( {display: 'none'} );
}