// ------------------------------------------------------------------------------
// Copyright notice
// Author: Niels Klomp
// copyright (C) 2011 Centis B.V.
// www.centis.nl
// info@centis.nl
//
// Any sourcecode modification has to be approved by Centis B.V.
// Redistribution and/or modification is explicitly prohibited without consent
// ------------------------------------------------------------------------------





function fireImageClick(imageId) {
	var subject = document.getElementById(imageId);
	if (subject != null) {
		if (typeof subject.click == 'function') {
			subject.click();
		} else {
			document.lightbox.start(subject);
		}
	}
}


function Slot(parentId, parentClass, imageId, primaryImageURL) {
	this.parentId = parentId;
	this.imageId = imageId;
	this.imageInfo = new Array();
	this.addImageInfo(primaryImageURL, parentClass);
}	

Slot.prototype.addImageInfo = function(imageURL, parentClass) {
	this.setImageInfo(null, imageURL, parentClass);
};

Slot.prototype.setImageInfo = function(index, imageURL, parentClass) {
	var value = new Array();
	value[0] = imageURL;
	value[1] = parentClass;
	if (index == null) {
		this.imageInfo.push(value);
	} else {
		this.imageInfo[index] = value;
	}
};


Slot.prototype.getImageURL = function(index) {
	if (this.imageInfo[index] == undefined || this.imageInfo[index][0] == undefined) {
		return null;
	}
	return this.imageInfo[index][0];
};

Slot.prototype.getParentClassName = function(index) {
	if (this.imageInfo[index] == undefined || this.imageInfo[index][1] == undefined) {
		return null;
	}
	return this.imageInfo[index][1];
};


Slot.prototype.getDIV = function(index) {
	var div = null;
	if (index != null && this.getImageURL(index) != null) {
		if (index == 0) {
			div = document.getElementById(this.parentId);
		} else {
			div = document.getElementById(this.parentId + "." + index.toString());
		}
	}
	return div;
};


Slot.prototype.showImage = function(index) {
	var imageURL = this.getImageURL(index);
	var div = this.getDIV(index);

	if (index == null || (index != 0 && imageURL == null)) {
		this.showImage(0);
		return;
	}
	
	if (div != null && imageURL != null) {
		var oldImage = document.getElementById(this.imageId);
		var newImage = document.createElement("img");

      		newImage.src = imageURL;
		newImage.id = this.imageId;
		newImage.className = this.getParentClassName(index);
		newImage.zIndex = 1;

		// replace old with new
		this.getDIV(0).replaceChild(newImage, oldImage);
		this.getDIV(1).zIndex = 10;
		this.getDIV(2).zIndex = 10;
		this.getDIV(3).zIndex = 10;

	}

};



