function GalleryImage(img_src) {
    
    this.image = new Image()
    this.image.src = img_src;
    
    this.id = 0;
    this.name = '';
    this.type = '';
    this.width = 0;
    this.height = 0;
    this.artist = '';
    this.sold = false;
}

GalleryImage.prototype.getImage = function() { return this.image; }
GalleryImage.prototype.setImage = function(new_image) { this.image = new_image; }

GalleryImage.prototype.getImageSrc = function() { return this.image.src; }
GalleryImage.prototype.setImageSrc = function(img_src) { this.image.src = img_src; }

GalleryImage.prototype.getImageWidth = function() { return this.image.width; }
GalleryImage.prototype.setImageWidth = function(new_width) { this.image.width = new_width; }

GalleryImage.prototype.getImageHeight = function() { return this.image.height; }
GalleryImage.prototype.setImageHeight = function(new_height) { this.image.height = new_height; }

GalleryImage.prototype.getId = function() { return this.id; }
GalleryImage.prototype.setId = function(new_id) { this.id = new_id; }

GalleryImage.prototype.getName = function() { return this.name; }
GalleryImage.prototype.setName = function(new_name) { this.name = new_name; }

GalleryImage.prototype.getType = function() { return this.type; }
GalleryImage.prototype.setType = function(new_type) { this.type = new_type; }

GalleryImage.prototype.getWidth = function() { return this.width; }
GalleryImage.prototype.setWidth = function(new_width) { this.width = new_width; }

GalleryImage.prototype.getHeight = function() { return this.height; }
GalleryImage.prototype.setHeight = function(new_height) { this.height = new_height; }

/*
GalleryImage.prototype.getWidth = function() { return this.image.width; }
GalleryImage.prototype.setWidth = function(new_width) { this.image.width = new_width; }

GalleryImage.prototype.getHeight = function() { return this.image.height; }
GalleryImage.prototype.setHeight = function(new_height) { this.image.height = new_height; }
*/

GalleryImage.prototype.getArtist = function() { return this.artist; }
GalleryImage.prototype.setArtist = function(new_artist) { this.artist = new_artist; }

GalleryImage.prototype.isSold = function() { return this.sold; }
GalleryImage.prototype.setSold = function(new_status) {
    if(new_status) {
        this.sold = true;
    }
    else  {
        this.sold = false;
    }
}

function ImageList() {
	this.images_ar = new Array();
	this.index = -1;
}

ImageList.prototype.addImage = function(new_image) { return this.images_ar.push(new_image); }
ImageList.prototype.countImages = function() {	return this.images_ar.length; }

ImageList.prototype.next = function() {
	this.index++;
	if(this.index > (this.images_ar.length-1)) {
		this.index = 0;
	}
	return this.images_ar[this.index];
}

ImageList.prototype.prev = function() {	
	this.index--;
	if(this.index < 0) {
		this.index = this.images_ar.length - 1;
	}
	return this.images_ar[this.index];
}

ImageList.prototype.current = function() {
	return this.images_ar[this.index];
}

function QueryString() {
	this.h = new Object();
	this.query = window.location.search.substring(1);
	var parms = this.query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {

			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			this.h[key] = val;
		}
	}
}

QueryString.prototype.getParameter = function(key) {
	return this.h[key];
}

QueryString.prototype.setParameter = function(key, value) {
	this.h[key] = value;
}


function slideCanvas(new_x) {
	new Effect.Move('canvas', {x:new_x,y:0,mode:'absolute',queue:{position:'end',scope:'slider'}});
}

function swapImage(oldImage, newImage) {
	var options = {
		duration:0.75,
		from:1.0,
		to:0.0,
		queue:{position:'end',scope:oldImage.id},
		afterFinish: function() {
			oldImage.src = newImage.src;
			oldImage.width = newImage.width;
			oldImage.height = newImage.height;
		}
	}
	
	new Effect.Opacity(oldImage.id, options);
	new Effect.Opacity(oldImage.id, {duration:0.75,from:0.0,to:1.0,queue:{position:'end',scope:oldImage.id}});
}

function swapTag(id, content) {

	var options = {
		duration:0.75,
		from:1.0,
		to:0.0,
		queue:{position:'end',scope:id},
		afterFinish: function() {
			$(id).innerHTML = content;
		}
	}
	
	new Effect.Opacity(id, options);
	new Effect.Opacity(id, {duration:0.75,from:0.0,to:1.0,queue:{position:'end',scope:id}});
	
}

function loadKollinerPhoto() {
	var id = kiList.current().getId();
	if(id != 0) {
		viewPhoto(id);
	}
}

function selectKolliner() {
	Event.stopObserving('kollinerButton', 'mouseover', kollinerMouseOver);
	Event.stopObserving('kollinerButton', 'mouseout', kollinerMouseOut);
	Event.observe('longButton', 'mouseover', longMouseOver);
	Event.observe('longButton', 'mouseout', longMouseOut);
	swapImage($('kollinerButton'), kollinerSelectedImg);
	swapImage($('longButton'), longSelectImg);
	slideCanvas(3);
}

function nextKolliner() {
	var galleryImage = kiList.next();
	var content = '<ul class="tag" style="text-align:right">';
	content = content + "<li>&nbsp;" + galleryImage.getName() + "<\/li>";
	content = content + "<li>&nbsp;" + galleryImage.getType() + "<\/li>";
	content = content + "<li>&nbsp;" + galleryImage.getWidth() + '&nbsp;x&nbsp;' + galleryImage.getHeight() + " inches<\/li>";
	if(galleryImage.isSold()) {
		content = content + "<li>Sold<\/li>";
	}
	else {
		content = content + "<li>&nbsp;<\/li>";
	}
	content = content + "<li>&nbsp;" + galleryImage.getArtist() + "<\/li>";
	content = content + "<\/ul>";
	swapImage($('kollinerImage'), galleryImage.getImage());
	swapTag('kollinerTag', content);
}

function prevKolliner() {
	var galleryImage = kiList.prev();
	var content = '<ul class="tag" style="text-align:right">';
	content = content + "<li>&nbsp;" + galleryImage.getName() + "<\/li>";
	content = content + "<li>&nbsp;" + galleryImage.getType() + "<\/li>";
	content = content + "<li>&nbsp;" + galleryImage.getWidth() + '&nbsp;x&nbsp;' + galleryImage.getHeight() + " inches<\/li>";
	if(galleryImage.isSold()) {
		content = content + "<li>Sold<\/li>";
	}
	else {
		content = content + "<li>&nbsp;<\/li>";
	}
	content = content + "<li>&nbsp;" + galleryImage.getArtist() + "<\/li>";
	content = content + "<\/ul>";
	swapImage($('kollinerImage'), galleryImage.getImage());
	swapTag('kollinerTag', content);
}

function loadLongPhoto() {
	var id = loList.current().getId();
	if(id != 0) {
		viewPhoto(id);
	}
}

function selectLong() {
	Event.observe('kollinerButton', 'mouseover', kollinerMouseOver);
	Event.observe('kollinerButton', 'mouseout', kollinerMouseOut);
	Event.stopObserving('longButton', 'mouseover', longMouseOver);
	Event.stopObserving('longButton', 'mouseout', longMouseOut);
	swapImage($('longButton'), longSelectedImg);
	swapImage($('kollinerButton'), kollinerSelectImg);
	slideCanvas(-729);
}

function nextLong() {
	var galleryImage = loList.next();
	var content = '<ul class="tag">';
	content = content + "<li>" + galleryImage.getName() + "&nbsp;<\/li>";
	content = content + "<li>" + galleryImage.getType() + "&nbsp;<\/li>";
	content = content + "<li>" + galleryImage.getWidth() + '&nbsp;x&nbsp;' + galleryImage.getHeight() + " inches<\/li>";
	if(galleryImage.isSold()) {
		content = content + "<li>Sold<\/li>";
	}
	else {
		content = content + "<li>&nbsp;<\/li>";
	}
	content = content + "<li>" + galleryImage.getArtist() + "&nbsp;<\/li>";
	content = content + "<\/ul>";
	swapImage($('longImage'), galleryImage.getImage());
	swapTag('longTag', content);
}

function prevLong() {
	var galleryImage = loList.prev();
	var content = '<ul class="tag">';
	content = content + "<li>" + galleryImage.getName() + "&nbsp;<\/li>";
	content = content + "<li>" + galleryImage.getType() + "&nbsp;<\/li>";
	content = content + "<li>" + galleryImage.getWidth() + '&nbsp;x&nbsp;' + galleryImage.getHeight() + " inches<\/li>";
	if(galleryImage.isSold()) {
		content = content + "<li>Sold<\/li>";
	}
	else {
		content = content + "<li>&nbsp;<\/li>";
	}
	content = content + "<li>" + galleryImage.getArtist() + "&nbsp;<\/li>";
	content = content + "<\/ul>";
	swapImage($('longImage'), galleryImage.getImage());
	swapTag('longTag', content);
}
