MAX_COL = 3;

GalleryElement = function(){
	this.href = "";
	this.image = "";
	this.description = "";
	this.newWin = false;
}

Gallery = function(){
	this.imgPath = '';
	this.elem = new Array();
}
Gallery.prototype.setPath = function (path){
	this.imgPath = path;
}

Gallery.prototype.addElement = function (image, href, description, newWindow){
	var id = this.elem.length;
	this.elem[id] = new GalleryElement();
	this.elem[id].href = href || '';
	this.elem[id].image = image || '';
	this.elem[id].description = description || '';
	this.elem[id].newWin = newWindow || false;
}

Gallery.prototype.getGallery = function(width, height){
	var strDocumentWrite = '';
	var temp = '';
	var fullImgName;
	var colCounter = 0;
	var w = width ||''
	var h = height ||''
	strDocumentWrite += '<table width=100% align=center cellspacing=0 cellpadding=0 border=0>';
	for (i=0; i< this.elem.length; i++){
		fullImgName =  this.imgPath + this.elem[i].image;
		if(i%MAX_COL == 0) {
			strDocumentWrite +='<tr>';
			temp +='<tr>';
		}
		if(this.elem[i].newWin){
			strDocumentWrite += '<td align=center valign=middle><a href="javascript:newWindow(\'' + this.elem[i].href + '\',800,600);"><img src="' + fullImgName + '" alt="" width=' +w + ' height='+ h +' border=0 onload="this.border=0"></a></td>';		
			temp += '<td align=center valign=middle><a href="javascript:newWindow(\'' + this.elem[i].href + '\',800,600);">' + this.elem[i].description + '</a></td>';
		}
		else{
			strDocumentWrite += '<td align=center valign=middle><a href="' + this.elem[i].href + '"><img src="' + fullImgName + '" alt="" width=' +w + ' height='+ h +' border=0 onload="this.border=0"></a></td>';		
			temp += '<td align=center valign=middle><a href="' + this.elem[i].href + '">' + this.elem[i].description + '</a></td>';
		}
		colCounter++;
		if(i%MAX_COL == MAX_COL-1) {
			strDocumentWrite +='</tr>';
			temp +='</tr>';
			strDocumentWrite += temp;
			colCounter=0;
			temp = '';
			strDocumentWrite += '<tr><td height=25 colspan=' + MAX_COL + '>&nbsp;</td></tr>'
		}

	}
	if(colCounter!=0){
			strDocumentWrite += '<td colspan='+ (MAX_COL-colCounter) +' align=center valign=middle>&nbsp;</td></tr>';
			temp += '<td colspan='+ (MAX_COL-colCounter) +' align=center valign=middle>&nbsp;</td></tr>';
			strDocumentWrite += temp;
			temp = '';
	}
	strDocumentWrite += '</table>';
	document.write(strDocumentWrite);
}

function newWindow(url, width, height){
	w = width || 800;
	h = height || 600;
	var name = "myFriends";
 	var x = (screen.availWidth-w)/2;
	var y = (screen.availHeight-h)/2;
	newWin = window.open(url, name, "toolbar=0,location=0,directories=0,hotkeys=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + w + ",height=" + h + ",top=" + y + ",right=200,left=" + x + "");
  newWin.focus();
}