
function Gallery_Widget (images, parent, owner, files) {
	this.images = images;
	this.parent = parent;
	this.owner  = owner;
	this.files = files;
}

Gallery_Widget.prototype.empty_gallery = function () {
	_get(this.parent).innerHTML = "<div style=\"height: 200px;\">" + "<div style=\"background-color: #222; margin-top: 200px; padding: 14px;\" align=\"center\"><div id=\"banner\" onMouseOver=\"_get('banner').background='#111'\" onMouseOut=\"_get('banner').background=''\" style=\" padding: 8px; width: 300px\">This gallery is not showing.</div></div>" + "</div>";
}

Gallery_Widget.prototype.mini_gallery_display = function (num) {
	_get('display_mode').innerHTML = "<a href=\"javascript:time_stamp()\" onClick=\"quick_display()\">Quick Display</a>";
	_get(this.parent).innerHTML = this.mini_gallery_html(num);
}

Gallery_Widget.prototype.mini_gallery_html = function (num) {
	var index = num;
	var valid = new Array();
	var i = 0;
	var x = 0;
	var text = "";
	
	if(this.images.length<=0) {
		return this.quick_gallery_html();
	}
	
	for(i=0;i<this.images.length;i++) {
		var st = this.images[i].source.lastIndexOf(".");
		var e = this.images[i].source.length;
		var ext = this.images[i].source.substr(st, e);
		if(ext == ".jpg" || ext == ".gif" || ext == ".png") {
			valid[x] = this.images[i];
			x++;
		}
	}
	
	this.valid_images = valid;
	data = "image";
	var length = this.valid_images.length-1;
	
	text = "<table width=\"100%\"><tr><td colspan=\"3\">";
	text += "<b>" + valid[num].name + "</b>" ;
	text += "</td></tr>";
	text += "<tr><td valign=\"top\" width=\"50%\">";
	
	if(index>0){
		text +=	"<a href=\"javascript:time_stamp();\" onClick=\"previous_gallery_image()\" >previous</a>";
	}
	
	text += "</td>";
	text += "<td>";
	text += "<div style=\"overflow: auto; text-align: center; width: 400px; margin-bottom: 30px; padding: 4px; background-color: #111; border: 4px solid #222\">";
	text += "<div align=\"center\" style=\"width: 100%; padding-top: 10px; padding-bottom: 10px\">";
	
	if(data == 'image') {
		text += this.mini_gallery_image(num);
	} else {
		text += "<object width=\"400\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#4,0,0,0\">";
			text += "<param name=\"SRC\" value=\"user/" + this.files[num].source + "\">";
			text += "<embed src=\"user/" + this.files[num].source + "\" width=\"400\"></embed></object>";
	}
	
	text += "</div>";
	if(valid[num].info) {
		text += "<center><div style=\"width: 300px; text-align: left; font-size: 10px; margin-top: 4px\">";
		text += valid[num].info;
		text += "<div></center>";
	}
	text += "</div>";
	if(valid.length>1) {
		text += "<div id=\"slideshow_control\">";
	
		if(true_start == false) {
			text += "<a onclick=\"true_timer_start()\">Start Slideshow</a>";
		} else {
			text += "<a onclick=\"true_timer_stop()\">Stop Slideshow</a>";
		}
	
		text += "</div><div id=\"timer\">10</div>";
	}
	text += "</td>";
	text += "<td valign=\"top\" width=\"50%\">";
	
	if(index<length) {
		text +=	"<a href=\"javascript:time_stamp();\" onClick=\"next_gallery_image()\">next</a>";
	}
	
	text += "</td></tr></table>";
	return text;
}

Gallery_Widget.prototype.mini_gallery_image = function (index) {
	var factor = 300/this.valid_images[index].w;
	var width = 300;
	var height = this.valid_images[index].h * factor;
 	var image = "<div style=\"position: relative; width: " + width + "px; height: " + height + "px;\">";
		image += "<div onMouseOver=\"stop_timer()\" onMouseOut=\"start_timer()\" style=\"cursor: wait; position: absolute; z-index: 1; width: 300px; height: " + height + "px;\"></div>";
		image += "<div align=\"center\" style=\"z-index: 0; width: 300px; cursor: wait; border: 1px solid #222; background-color: #222\"><image src=\"user/" + this.valid_images[index].source + "\" width=\"300px\" onload=\"set_timer(10)\"/></div>";
		image + "</div>";
	return image;
}

Gallery_Widget.prototype.quick_display = function () {
	_get(this.parent).innerHTML = this.quick_gallery_html();
	_get('display_mode').innerHTML = "<a href=\"javascript:time_stamp();\" onClick=\"full_gallery()\">Gallery Mode</a>";
}

Gallery_Widget.prototype.quick_gallery_html = function () {
	var i = 0;
	var x = 0;
	var text = "<div style='text-align: left'>";
	for(i=0;i<this.images.length;i++) {
		var st = this.images[i].source.lastIndexOf(".");
		var e = this.images[i].source.length;
		var ext = this.images[i].source.substr(st, e);
		if(ext == ".jpg" || ext == ".gif" || ext == ".png") {
			text += "<hr style=\"border: 1px dotted #333\"/><div class=\"gallery_banner\" style=\"padding: 6px; font-size: 10px; cursor: pointer;\" onClick=\"gallery_image(" + i + ")\">"
			text += "<table width=\"100%\"><tr><td width=\"100%\">";
			text+= "<b>" + this.images[i].name + "</b>";
			
			var factor = 40/this.images[i].h;
			var height = 40;
			var width = this.images[i].w * factor;
		
		 	text += "<div style=\"position: relative; width: " + width + "px\">";
			text += "<div style=\"position: absolute; z-index: 1; width: " + width + "px; height: " + height + "px;\"></div>";
			text += "<div style=\"z-index: 0; width: " + width + "px;\">";
			text += "<img valign=\"bottom\" height=\"" + height + "px\" src=\"user/" + this.images[i].source + "\"/>";
			text += "</div>";
			text += "</div>";
			
			text += "</td><td>";
			if(this.images[i].info) {
				text += "<div style=\"width: 280px; background-color: #111; padding: 6px\">";
		 		text += this.images[i].info;
		 		text += "</div>";
		 	}
		 	text += "</td></tr></table>";
		 	text += "</div>";
		}
	}
	
	for(x=0;x<this.files.length;x++){
			text += "<hr style=\"border: 1px dotted #333\"/><div style=\"padding: 6px; font-size: 10px; cursor: pointer\" onMouseOver=\"this.style.background='#222'\"  onMouseOut=\"this.style.background=''\" onClick=\"gallery_image(" + i + ")\">"
			text += "<table width=\"100%\"><tr><td width=\"100%\">";
			text+= "<b>" + this.files[x].name + "</b>";
		 	text += "<br />" + "<object width=\"400\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#4,0,0,0\">";
			text += "<param name=\"SRC\" value=\"user/" + this.files[x].source + "\">";
			text += "<embed src=\"user/" + this.files[x].source + "\" width=\"400\"></embed></object>";
			text += "</td><td>";
			if(this.files[x].info) {
				text += "<div style=\"width: 280px; background-color: #111; padding: 6px\">";
		 		text += this.files[x].info;
		 		text += "</div>";
		 	}
		 	text += "</td></tr></table>";
		 	text += "</div>";
	}
	text += "<hr style=\"border: 1px dotted #333\"/></div>";
	return text;
}

Gallery_Widget.prototype.navigation = function (index) {
	
	var text = "";
	var length = this.valid_images.length-1;
	
	if(index>0){
		text +=	"<a class=\"silver\" href=\"javascript:time_stamp();\" onClick=\"previous_gallery_image()\" >previous</a>";
	}
	
	if(index>0 && index<length) {
		text += "&nbsp;&nbsp;&nbsp;&nbsp;";
	}
	
	if(index<length) {
		text +=	"<a class=\"silver\" href=\"javascript:time_stamp();\" onClick=\"next_gallery_image()\">next</a>";
	}
	return text;
}
