//////////////////////////////////////////////////////////
// new / refactored functions for mvc version
//////////////////////////////////////////////////////////

// image changer (click on thumb changes big image)
function MarketplaceImageChanger() {

	this.imageField = 0;
	this.mouseoverField = 0;
    this.zoomField = 0;
	this.imagesNumber = 0;
	this.imagesList = new Array();
	this.mouseoverList = new Array();
    this.zoomList = new Array();

	this.addImage = function (id,src,mouseover, zoom) {
		this.imagesList[id] = src;
		this.mouseoverList[id] = mouseover;
        this.zoomList[id] = zoom;
		this.imagesNumber++;
	}

	this.initField = function(fieldId, mouseoverFieldId, zoomFieldId) {
		field = document.getElementById(fieldId);
		mouseoverField = document.getElementById(mouseoverFieldId);
        zoomField = document.getElementById(zoomFieldId);
		if (field) {
			this.imageField = field;
            if(mouseoverField) {
                this.mouseoverField = mouseoverField;
            }
            if(zoomField) {
                this.zoomField = zoomField;
            }
			return true;
		} else {
			return false;
		}
	}

	this.change = function(id) {
		if (this.imageField) {
			if (this.imagesList[id]) {
				this.imageField.src = this.imagesList[id]
				if(this.mouseoverList[id] != '') {
				    this.mouseoverField.src = this.mouseoverList[id]
				} else {
				    this.mouseoverField.src = this.imagesList[id]
				}
                if(this.zoomList[id] !='' && this.zoomField) {
                    MagicZoom.update(this.zoomField, this.zoomList[id], this.imagesList[id]);
                }
				this.imageField.style.display = 'inline';
			} else {
				this.imageField.src = '';
				this.mouseoverField.src = '';
				this.imageField.style.display = 'none';
			}
		}
		return false;
	}
}