;(function(jQuery) {

	var defaults = {
		autoslide: 1,
		rotation: 1,
		showPrevNext: 0,
		speed: 1000,
		duration: 4500,
		zIndex: 5,
		slideTitle: 1,
		titleOffset: 5,
		showTitle: true
	};

	
	//extend the fn for the methods
	
	jQuery.fn.simpleSlide = function(settings) {
		
		jQuery.extend(this,{
			slideshowInterval: undefined,
			slideElementCount: 0,
			dontAutoslide: 0,
			activeSlideElement: 0,
			slideList: undefined,
			
			initialize: function() {
				var slideshow = this;
				this.slideList=jQuery(this).find('ul.simple-slide');
				//get count of elements
				this.slideElementCount = jQuery(this.slideList).find('li').length;
				jQuery(this.slideList).find('.slide-title-wrapper').each(function(){
					var height = jQuery(this).height();
					jQuery(this).css('bottom', '-'+height+'px');
				});
				//set height of slide-title-wrapper and top of slide-title
				jQuery(this.slideList).find('li').css({'z-index': this.zIndex, 'display': 'none'});
				//the first one is visible 
				jQuery(this.slideList).find('li[rel='+0+']').css('zIndex', this.zIndex+5).show();
				if (this.showTitle) jQuery(this.slideList).find('li[rel='+0+']').find('.slide-title-wrapper').animate({bottom: 0},'slow');								
						
				/*if (this.autoslide) {
					this.slideshowInterval = setInterval(function() { slideshow.autoSlide(); }, this.duration);
				}*/
				this.resetInterval();
				
				//prev and next buttons
				jQuery(this).find('a.slide-prev').click(function(e){
					slideshow.slidePrev();
					slideshow.resetInterval();
					e.preventDefault();
				});
				jQuery(this).find('a.slide-next').click(function(e){
					slideshow.slideNext();
					slideshow.resetInterval();
					e.preventDefault();
				});
			},
			
			resetInterval: function() {
				//reset interval
				var slideshow = this;
				if (this.autoslide) {
					if (this.slideshowInterval) clearInterval(this.slideshowInterval);
					this.slideshowInterval = setInterval(function() { slideshow.autoSlide(); }, this.duration);
				}				
			},
			
			slidePrev: function() {
				var prev = this.activeSlideElement-1;
				if (prev<0) prev = this.slideElementCount-1;
				this.slideTo(prev);
			},
			
			slideNext: function() {
				var next = this.activeSlideElement+1;
				if (next>=this.slideElementCount) next=0;
				this.slideTo(next);
			},
			
			autoSlide: function() {
				if (this.dontAutoslide==0) this.slideNext();
			},

			slideTo: function(index) {
				this.dontAutoslide=1;
				//var index=jQuery(lielement).attr('rel');
				var slide=this;
				var slideul=jQuery(this).find('ul.simple-slide');
				
				if (index != slide.activeSlideElement) {
					var $activeElement=jQuery(jQuery(slideul).find('li[rel='+slide.activeSlideElement+']'));
					var $nextElement=jQuery(jQuery(slideul).find('li[rel='+index+']'));
					if (this.showTitle) {
						$activeElement.find('.slide-title-wrapper').animate({bottom: '-'+$activeElement.find('.slide-title-wrapper').height()+'px'},'slow',function(){
							$nextElement.fadeIn(slide.speed, function() {
								jQuery(this).css('zIndex',slide.zIndex+5);
								slide.activeSlideElement = index;
								jQuery(this).find('.slide-title-wrapper').animate({bottom: 0},'slow');
							});
							$activeElement.fadeOut(slide.speed, function() {
								jQuery(this).css('zIndex',slide.zIndx+5);
							});
						});
					} else {
						$nextElement.fadeIn(slide.speed, function() {
							jQuery(this).css('zIndex',slide.zIndex+5);
							slide.activeSlideElement = index;
						});
						$activeElement.fadeOut(slide.speed, function() {
							jQuery(this).css('zIndex',slide.zIndx+5);
						});			
					}
				}
				jQuery($nextElement).closest('ul').find('li').removeClass('active');
				jQuery($nextElement).addClass('active');
				this.dontAutoslide=0;
			},
			
			getNextSlideElement: function() {
				var next=this.activeSlideElement+1;
				if (next>=this.slideElementCount) next=0;
				return next;
			}
			
		});

		jQuery.extend(this, defaults, settings);
		
		this.initialize();
		
		return this;
	};
})(jQuery);
