function ImageCollection(element, ownName){
    this.imageUrls = new Array();
    this.locationUrls = new Array();
    this.currentElem = -1;
    this.currentUrl = null;
    this.elementToShowAt = element;
    this.imageForLoading = element.src;
    this.interval = 0;
    this.timer = null;
    this.timerProc = ownName + '.showNextByTimer()';
}

ImageCollection.prototype.add = function(locationUrl, imageUrl){
    if (imageUrl){
        this.locationUrls.push(locationUrl);
        this.imageUrls.push(imageUrl);
    }
}

ImageCollection.prototype.setInterval = function(value){
    this.clearTimer();
    this.interval = value;
    this.timer = setTimeout(this.timerProc, this.interval);
}

ImageCollection.prototype.onImageClick = function(){
    if (this.currentUrl){
        window.location = this.currentUrl;
    }
}

ImageCollection.prototype.showNextByTimer = function(){
    this.timer = null;
    this.showNext();
   	this.setInterval(this.interval);
}

ImageCollection.prototype.clearTimer = function(){
    if (this.timer){
        clearTimeout(this.timer);
        this.timer = null;
    }
}

ImageCollection.prototype.showNext = function(){
    var timer = this.timer;
    this.clearTimer();
    if (!this.imageForLoading || !this.elementToShowAt)
        return;
	this.currentElem++;
	if (this.currentElem >= this.imageUrls.length){
	    this.currentElem = 0;
	}
	this.showCurrent();
	if (timer)
    	this.setInterval(this.interval);
}

ImageCollection.prototype.showPrev = function(){
    var timer = this.timer;
    this.clearTimer();

    if (!this.imageForLoading || !this.elementToShowAt)
        return;
	this.currentElem--;
	if (this.currentElem < 0){
	    this.currentElem = this.imageUrls.length - 1;
	}
    this.showCurrent();
}

ImageCollection.prototype.showCurrent = function(){
    this.elementToShowAt.src = this.imageForLoading;
    this.currentUrl = null;
	this.elementToShowAt.style.cursor = 'auto';
	var elem = document.createElement('img');
	var callerClass = this;
	elem.onload = function(evt){
		callerClass.elementToShowAt.src = elem.src;
		callerClass.elementToShowAt.style.cursor = ((callerClass.locationUrls[callerClass.currentElem]) ? 'hand' : 'auto');
		callerClass.currentUrl = callerClass.locationUrls[callerClass.currentElem];
	}
	elem.src = this.imageUrls[this.currentElem];
}