var ImageTextSlider = $.klass({
  initialize:function(container, options) {
    this.options = {
    	itemClass: 'slideritem',
    	interval: 8,
    	duration: 1
    };
    $.extend(this.options, options);
    this.init(container);
  },
  
  init:function(container) {
		this.container = $('#' + container);
		if (!this.container) throw("Slider container is missing!");
		this.items = $('#' + container + ' .' + this.options.itemClass);
		this.itemCount = this.items.length;
		this.containerHeight = 0;
		
		for(i=0;i<this.itemCount;i++) {
			if ($(this.items[i]).height() > this.containerHeight) {
				this.containerHeight = $(this.items[i]).height();
			}
			$(this.items[i]).css({
				'position' : 'absolute',
				'width' :  $(this.items[i]).width() + 'px',
				'height' : $(this.items[i]).height() + 'px'
			});
			if (i > 0) {
				$(this.items[i]).css({
					'display' : 'none'
				});
			}
		}
		
		$(this.container).css({'height' : this.containerHeight + 'px'});
		
		if (this.itemCount > 1)
		  this.start();
  },
  
	start:function() {
		this.current = 0;	
    this.pe = setInterval($.bind(function() {
      this.slide();
    }, this), this.options.interval * 1000);						
	},
	
	slide:function() {
    $(this.items[this.current]).fadeOut(this.options.duration * 1000);
		if (this.current == this.itemCount-1) {
			this.current = 0;
		}
		else {
			this.current++;
		}
		$(this.items[this.current]).fadeIn(this.options.duration * 1000);
	}
});
