
function ImgInnerfade(elementId, htmlSnippets){
	
	this.htmlSnippets = htmlSnippets;
	this.itemIDs = new Array();
	var i = 0
	for(var id in htmlSnippets){
		this.itemIDs[i] = id;
		i++;
	}
	this.parent = $(elementId);	
	this.currentIndex = 0;	
   
	this.next();	
}

ImgInnerfade.prototype.getCurrentItem = function(){
	var id = this.itemIDs[this.currentIndex]
	return this.getItem(id);
}

ImgInnerfade.prototype.getItem = function(itemID){
	var listid = 'innerfade-item-' + itemID;		
	var item = $('#'+listid);
	if( item.length == 0 ){
		var html = this.htmlSnippets[itemID];
		this.parent.append( '<li style="z-index: 0; position: absolute; display: none;" id="' + listid + '">' + html + '</li>');
		item = $('#'+listid);		
	} 		
	return item;
}




ImgInnerfade.prototype.next = function(){
	
	var previousItem = this.getCurrentItem();	
	this.currentIndex =  (this.currentIndex+1)%(this.itemIDs.length);	
	var nextItem = this.getCurrentItem();	
		
	previousItem.fadeOut('slow');	
	nextItem.fadeIn('slow');			
	
	
	var _self = this;
	this.timeoutID = setTimeout(function(){
		_self.next()
	}, 3000);
}

ImgInnerfade.prototype.pause = function(interuptId){        
	this.interruptItem = this.getItem(interuptId);
		
	clearTimeout($.innerfade.timeoutID);
						
	this.getCurrentItem().hide();			
	this.interruptItem.show();
}
	
ImgInnerfade.prototype.resume = function(){		
	if(this.interruptItem != null)
		this.interruptItem.hide();
	this.interruptItem = null;
	
	this.getCurrentItem().show();
	
	var _self = this;	
	this.timeoutID = setTimeout(function(){
		_self.next()
	}, 2000);
}