Highlight = function(name) {
  this.init(name);
}

$.extend(Highlight.prototype, {
   // object variables
   name: '',

   init: function(name) {
     // do initialization here
     this.name = name;
  	 this.timer;
  	 this.holder = $('#'+this.name);
  	 this.duration = 5000;
  	 this.index = 0;
  	 this.images = $('#'+this.name+' > img');
  	 this.length = this.images.length;
  	 this.playing = true;
  	 
  	 $('#slides-0').removeClass('hide');
  	 this.play();
  	 
   },

   play: function() {
   	var _this = this;
	 if (this.playing) this.timer = setTimeout(function(){ _this.next() }, this.duration);
   },

   next: function() {
   	var _this = this;
  	this.reset();
  	this.prev = Number(this.index);
  	this.index = (this.index < (this.length-1)) ? this.index + 1 : 0;
  	
  	if ($('#slides-'+this.index).attr('complete')) {
  		$('#slides-' + this.prev).css('z-index', 10);
  		$('#slides-'+this.index).removeClass('hide');
  		$('#slides-'+this.index).show();
		var _this = this;
  		$('#slides-' + this.prev).fadeOut("slow", function () { _this.resetItem() });
  	} else {
  		this.play();
  	}
   },
  
  resetItem: function(e){
  	$('#slides-' + this.prev).css('z-index', this.index);
  	$('#slides-' + this.prev).addClass('hide');
  	this.play();
  },
   
   reset: function() {
  	for (i=0; i < this.length; i++){
	  	$('#slides-'+i).css('z-index', i);
  	}
   }
});
