function object ( o ) {
  function F() {};
  F.prototype = o;
  return new F();
};

function BookPreview ( ) {
  /**
   * private variables 
   */
  var that = object(this),
  imageList = new Array(),
	imageElem = null,
	imageUrl = "",
	currIdx = 0;

  /**
   * public functions
   */
  that = {
    setUrl : function ( iUrl ) {
			//console.log(iUrl);
			imageUrl = iUrl;
		},

    addImage : function ( iPage ) {
			imageList.push(iPage);
		},
		
		setImage : function ( ) {
			if ( ! imageElem ) {
				imageElem = $jq('#previewpageimage');
			}
			imageElem.attr({ src : imageUrl + "/" + imageList[currIdx] });
			//console.log(imageElem);
		},
		
		setArrows : function ( ) {
			var al_on = $jq("#preview_arrow_left");
			var al_off = $jq("#preview_arrow_left_inactive");
			var ar_on = $jq("#preview_arrow_right");
			var ar_off = $jq("#preview_arrow_right_inactive");

			al_status = "on";
			ar_status = "on";
			if ( currIdx <= 0 ) {
				al_status = "off";
			}
			if ( currIdx >= imageList.length - 1 ) {
				ar_status = "off";
			}
			if (al_status == "on") {
				al_on.show();
				al_off.hide();
			} else {
				al_on.hide();
				al_off.show();
			}
			if (ar_status == "on") {
				ar_on.show();
				ar_off.hide();
			} else {
				ar_on.hide()
				ar_off.show();
			}
		},
		
		previous : function ( ) {
			if ( currIdx > 0 ) {
				currIdx -= 1;
				this.setImage();
			}
			this.setArrows();
		},
		
		next : function ( ) {
			if ( currIdx < (imageList.length - 1) ) {
				currIdx += 1;
				this.setImage();
			}
			this.setArrows();
		}
		
  };

  return that;
};


function BookPreviewChoice ( ) {
	/**
   * private variables 
   */
  var that = object(this),
	currDiv = 0;
	divArr = Array("previewOptionSimple",
			"previewOptionDesign",
			"previewOptionKeep",
			"previewOptionRemove",
			"previewOptionUpload"
			);
			
  /**
   * public functions
   */
  that = {
		showDetails : function ( choice ) {
			if ( (choice == null) || (choice < 1) || (choice > divArr.length) ) {
				return;
			}

			// Out with the old
			if ( currDiv > 0 ) {
				$jq('#'+divArr[currDiv-1]).hide();
			}

			// In with the new
			$jq('#'+divArr[choice-1]).show();
			currDiv = choice;

			// Fade in/out for design-your-own options arrow image
			var elem = $jq('#previewFocusArrow');
			if ( choice == 2 || choice == 5 ) {
				elem.show();
			} else {
				elem.hide();
			}
		}
	};
	
	return that;
};

// Class for navigating book previews
// function BookPreview ( )
// {
// 	MochiKit.Base.bindMethods(this);
// 	this.imageList = new Array();
// 	this.imageElem = null;
// 	this.imageUrl = "";
// 	this.currIdx = 0;
// }
// 
// /**
//  * Set the url/path for page images
//  */
// BookPreview.prototype.setUrl = function ( iUrl )
// {
// 	this.imageUrl = iUrl;
// }
// 
// /**
//  * Add an image filename to list of page images.  Used during init.
//  */ 
// BookPreview.prototype.addImage = function ( iPage )
// {
// 	this.imageList.push(iPage);
// }
// 
// /**
//  * Sets member variable that holds reference to img tag with page image
//  */
// BookPreview.prototype.setImage = function ( )
// {
// 	if ( ! this.imageElem ) {
// 		this.imageElem = MochiKit.DOM.getElement("previewpageimage");
// 	}
// 
// 	this.imageElem.src = this.imageUrl + "/" + this.imageList[this.currIdx];
// }
// 
// /**
//  * Sets the highlight style of the navigation arrows based on boundary 
//  * conditions from previous() and next()
//  */
// BookPreview.prototype.setArrows = function ( )
// {
// 	al_on = MochiKit.DOM.getElement("preview_arrow_left");
// 	al_off = MochiKit.DOM.getElement("preview_arrow_left_inactive");
// 	ar_on = MochiKit.DOM.getElement("preview_arrow_right");
// 	ar_off = MochiKit.DOM.getElement("preview_arrow_right_inactive");
// 
// 	al_status = "on";
// 	ar_status = "on";
// 	if ( this.currIdx <= 0 ) {
// 		al_status = "off";
// 	}
// 	if ( this.currIdx >= this.imageList.length - 1 ) {
// 		ar_status = "off";
// 	}
// 	if (al_status == "on") {
// 		al_on.style.display = "block";
// 		al_off.style.display = "none";
// 	} else {
// 		al_on.style.display = "none";
// 		al_off.style.display = "block";
// 	}
// 	if (ar_status == "on") {
// 		ar_on.style.display = "block";
// 		ar_off.style.display = "none";
// 	} else {
// 		ar_on.style.display = "none";
// 		ar_off.style.display = "block";
// 	}
// }
// 
// /**
//  * Move to previous page image
//  */
// BookPreview.prototype.previous = function ( )
// {
// 	if ( this.currIdx > 0 ) {
// 		this.currIdx -= 1;
// 		this.setImage();
// 	}
// 	this.setArrows();
// }
// 
// /**
//  * Move to next page image
//  */
// BookPreview.prototype.next = function ( )
// {
// 	if ( this.currIdx < this.imageList.length -1 ) {
// 		this.currIdx += 1;
// 		this.setImage();
// 	}
// 	this.setArrows();
// }

/**
 * Class for preview wizard option display
 */
// function BookPreviewChoice ( )
// {
// 	MochiKit.Base.bindMethods(this);
// 	this.currDiv = 0;
// 	this.divArr = Array("previewOptionSimple",
// 			"previewOptionDesign",
// 			"previewOptionKeep",
// 			"previewOptionRemove",
// 			"previewOptionUpload"
// 			);
// }
// 
// BookPreviewChoice.prototype.showDetails = function ( choice )
// {
// 	var elem;
// 
// 	if ( (choice == null) || (choice < 1) || (choice > this.divArr.length) ) {
// 		return;
// 	}
// 
// 	// Out with the old
// 	if ( this.currDiv > 0 ) {
// 		elem = MochiKit.DOM.getElement(this.divArr[this.currDiv-1]);
// 		MochiKit.Visual.fade(elem, {duration: 0});
// 	}
// 
// 	// In with the new
// 	elem = MochiKit.DOM.getElement(this.divArr[choice-1]);
// 	MochiKit.Visual.appear(elem, {duration: 0});
// 	this.currDiv = choice;
// 
// 	// Fade in/out for design-your-own options arrow image
// 	elem = MochiKit.DOM.getElement('previewFocusArrow');
// 	if ( choice == 2 || choice == 5 ) {
// 		MochiKit.Visual.appear(elem, {duration: 0});
// 	} else {
// 		MochiKit.Visual.fade(elem, {duration: 0});
// 	}
// }
