ImageWindow.prototype = new BaseWindow();
ImageWindow.prototype.constructor = ImageWindow;

/**
 * @constructor
 * @base BaseWindow
 */
function ImageWindow() {
	
	// fields =====================================================================================
	/**
	 * @type Boolean
	 */
	var _showArrows = false;
	
	/**
	 * @type jQuery
	 */
	var $_imgContainer = null;
	
	// methods ====================================================================================
	
	/**
	 * @param {Boolean} showArrows
	 */
	this.setShowArrows = function(showArrows) {
		_showArrows = showArrows;
	};
	
	this.setupImgWindowTrigger = function($context) {
		var $triggerElement = null;
		if ($context instanceof jQuery) {
			$triggerElement = $("a#main_photo", $context);
			$_imgContainer = $context;
		} else {
			$triggerElement = $("a#main_photo");
		}
			
		this.setTriggerElement($triggerElement);
	};
	
	// overridden =================================================================================
	this._getContainer = function() {
		return $("div#img_box");
	};
	
	this._getCloseButtonSelector = function() {
		return "a.img_close";
	};
	
	this._initHook = function(callback) {
		
		// bind arrow click
		var hrefs = new Array();
		
		var $mainPhoto = null;
		if ($_imgContainer instanceof jQuery) {
			$mainPhoto = $("a#main_photo", $_imgContainer);
		} else {
			$mainPhoto = $("a#main_photo");	
		}
		
		var mainPhotoHref = $mainPhoto.attr("href");
		if (mainPhotoHref !== undefined) {
			hrefs.push(mainPhotoHref);
		}
		
		$(".other_fotos a").each(function(i) {
			var href = $(this).attr("href");
			if(href !== undefined) {
				hrefs.push(href);
			}
		});	
		var currIndex = 0;
		
		
		var $arrows = $("div#big_img_arrows", this.getContainer());
		$arrows.unbind("click.imageWindow");
		$arrows.bind("click.imageWindow", $.proxy(function(event) {
			event.preventDefault();
			
			var $target = $(event.target);
			if ($target.hasClass("prev_image_a")) {
				currIndex = currIndex - 1;
				if (currIndex < 0) {
					currIndex = hrefs.length - 1;
				}
			} else if ($(event.target).hasClass("next_image_a")) {
				currIndex = currIndex + 1;
				if (currIndex > hrefs.length - 1) {
					currIndex = 0;
				}
			}
			$("img", this.getContainer()).attr("src", hrefs[currIndex]);
		}, this));
		
		if ($.isFunction(callback)) {
			callback();
		}		
	};
	
	this.setTriggerElement = function($triggerElement) {
		if ($triggerElement instanceof jQuery) {
			$triggerElement.unbind("click.baseWindow");
			var _this = this; 
			$triggerElement.bind("click.baseWindow", function(event) {
				event.preventDefault();
				var $target = $(this);
				var href = $triggerElement.attr("href");
				if (href === undefined) {
					return;
				}
				_this.show($target);
			});
		}		
	};
	
	this._preShowHook = function($triggerElement) {
		$("img", this.getContainer()).attr("src", $triggerElement.attr("href"));		
	};
	
	this._postShowHook = function($triggerElement) {
		if (_showArrows) {
			$("div#big_img_arrows", this.getContainer()).css("display", "block");
		}
	};
	
	this._postHideHook = function() {
		$("img", this.getContainer()).attr("src", blankImagePath);
	};
}
