﻿function Gallery(
	aImages,
	iMaxWidth,
	iMaxHeight
	) {
	
	this.aImages = aImages;	
	this.iMaxWidth = iMaxWidth;
	this.iMaxHeight = iMaxHeight;
	this.oWindow = null;
	this.iIndex = -1;
	
}

Gallery.prototype = {

	show : function(iIndex) {
	
		this.iIndex = iIndex;
	
		if(this.oWindow) {			
			this.oWindow.close();
		}
	
		var
			iLeftOffset = screen.availWidth / 2 - this.iMaxWidth / 2,
			iTopOffset = screen.availHeight / 2 - this.iMaxHeight / 2
			;	
	
		this.oWindow = window.open(
			'.',
			'',
			'left=' + iLeftOffset + ', ' +
			'top = ' + iTopOffset + ', ' +
			'width=' + (this.iMaxWidth + 20) + ', ' +
			'height=' + (this.iMaxHeight + 40) + ', ' +			
			'status=yes' 
			);
			
		this.oWindow.document.open();
			
		this.oWindow.document.write('<html><head></head>' +
			'<body style="background: #FFF; margin: 0px; padding: 0px;">' +
			'<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"><tr height="100%"><td align="center">' + 
			'<img src="' + this.aImages[iIndex] + '" /></td></tr><tr><td align="center" style="padding: 5px"><a href="#"><img src="/f/objects/global/prev.gif" border="0"/></a> <a href="#"><img src="/f/objects/global/next.gif" border="0"/></a></td></tr></table></body></html>'
			);
			
		this.checkButtons();
			
		var oThis = this;												
		
		this.oWindow.document.getElementsByTagName('a')[0].onclick = function() { oThis.prev(); return false; };
			
		this.oWindow.document.getElementsByTagName('a')[1].onclick = function() { oThis.next(); return false; };

		this.oWindow.document.close();
		
		this.oWindow.focus();
		
		return false;
	
	},
	
	prev : function() {
	
		if(this.iIndex < 0) {
			return;
		}
		
		this.iIndex--;
		
		this.oWindow.document.getElementsByTagName('img')[0].src = this.aImages[this.iIndex];
		
		this.checkButtons();
			
	},
	
	next : function() {
	

		if(this.iIndex < 0) {
			return;
		}
		
		this.iIndex++;
		
		this.oWindow.document.getElementsByTagName('img')[0].src = this.aImages[this.iIndex];
		
		this.checkButtons();
			
	},
	
	checkButtons : function() {
	
		var aButtons = this.oWindow.document.getElementsByTagName('a');
		
		if(this.iIndex == 0) {
			aButtons[0].style.visibility = 'hidden';
		}
		else {
			aButtons[0].style.visibility = 'visible';
		}
		
		if(this.iIndex == this.aImages.length - 1) {
			aButtons[1].style.visibility = 'hidden';
		}
		else {
			aButtons[1].style.visibility = 'visible';
		}
	
	}

};