
function Gallery(name)
{
	this.name = name;
	this.items = new Array();
	this.current = 0;
	this.motion = 0;
	this.type = 'swap';

	this.add = gallery_add;
	this.swap = gallery_swap;
	this.draw = gallery_draw;
	this.next = gallery_next;
	this.prev = gallery_prev;

	// attributes - private
	this.browser = 'n6';       if(document.layers) this.browser = 'n4'; if(document.all) this.browser = 'ie';
}

function gallery_add(title, description, view, thumbnail, map)
{
	if(title) this.items[this.items.length] = new Gallery_Item(title, description, view, thumbnail, map);
}

function gallery_swap(index)
{
	var title = document.getElementById('gallery_'+this.name+'_title');
	var description = document.getElementById('gallery_'+this.name+'_description');
	var view = document.getElementById('gallery_'+this.name+'_view');
	var map = document.getElementById('gallery_'+this.name+'_map');
	if(this.type == 'swap') thumbnail = document.getElementById('gallery_'+this.name+'_thumbnail_'+index);
	
	if(title) title.innerHTML = this.items[index].title;
	if(description) description.innerHTML = this.items[index].description;
	if(view) view.innerHTML = this.items[index].view;
	if(map) map.innerHTML = this.items[index].map;
	if(this.type == 'swap') if(thumbnail) thumbnail.innerHTML = this.items[this.current].thumbnail;

	if(this.type == 'swap') this.items[index].swap(this.items[this.current]);

	//if(this.browser == 'n6') alert('Refresh');

	this.motion = index;
}

function gallery_draw(part)
{
	var args = gallery_draw.arguments;
	var width = 0;  if(args.length >= 2 && args[1] != null) width = args[1];
	var height = 0; if(args.length >= 3 && args[2] != null) height = args[2];
	if(args.length >= 4 && args[3] != null)this.current = args[3];

	switch(part)
	{
		case('title'):
		{
			document.write("<span id='gallery_"+this.name+"_title'>&nbsp;</span>");
			document.getElementById('gallery_'+this.name+'_title').innerHTML = this.items[this.current].title;
		}
		break;
		case('description'):
		{
			document.write("<span id='gallery_"+this.name+"_description'>&nbsp;</span>");
			document.getElementById('gallery_'+this.name+'_description').innerHTML = this.items[this.current].description;
		}
		break;
		case('view'):
		{
			document.write("<span id='gallery_"+this.name+"_view'>&nbsp;</span>");
			document.getElementById('gallery_'+this.name+'_view').innerHTML = this.items[this.current].view;
		}
		break;
		case('map'):
		{
			document.write("<span id='gallery_"+this.name+"_map'>&nbsp;</span>");
			document.getElementById('gallery_'+this.name+'_map').innerHTML = this.items[this.current].map;
		}
		break;
		default:
		{
			if(part >= 0 && part < this.items.length)
			{
				out = "<a href='javascript:void(0);'";
				out += "onclick='"+this.name+".swap("+part+")'>";
				out += "<div id=gallery_"+this.name+"_thumbnail_"+part+" ";
				out += "style='position:relative; ";
				out += "overflow:hidden; clip:rect(0, "+width+", "+height+", 0); ";
				out += "text-align:center; ";
				out += "vertical-align:middle; cursor:hand;";
				if(width && height)
				{
					out += "width:"+width+"; ";
					out += "height:"+height+"; ";
				}
				out += "'>";
				out += "&nbsp;";
				out += "</div>";
				out += "</a>";
				document.write(out);
				document.getElementById('gallery_'+this.name+'_thumbnail_'+part).innerHTML = this.items[part].thumbnail;
			}
		}
		break;
	}
}

function gallery_next()
{
	if(this.motion >= this.items.length-1)
	{
		if(this.type == 'swap') this.motion = 1;
		else this.motion = 0;
	}
	else ++this.motion;

	this.swap(this.motion);
}

function gallery_prev()
{
	if((this.motion <= 1 && this.type == 'swap') || this.motion <= 0) this.motion = this.items.length-1;
	else --this.motion;

	this.swap(this.motion);
}

function Gallery_Item(title, description, view, thumbnail, map)
{
	this.name = title
	this.title = title;
	this.description = description;
	this.view = view;
	this.thumbnail = thumbnail;
	this.map = map;

	this.swap = gallery_item_swap;
}

function gallery_item_swap(item)
{
	temp = this.title; this.title = item.title; item.title = temp;
	temp = this.description; this.description = item.description; item.description = temp;
	temp = this.view; this.view = item.view; item.view = temp;
	temp = this.thumbnail; this.thumbnail = item.thumbnail; item.thumbnail = temp;
	temp = this.map; this.map = item.map; item.map = temp;
}