// JavaScript Document
/*
* jQuery.fn.slider( options );
*
* Eternal slide plugin, slide your content for ever.
*
* USAGE:
* $('.element').slider();
* $('.element').slider({
*     direction: 'ltr or rtl', // DEF: ltr
*     vertical: 'true, false', // DEF: false
*     speed: 'in millisec', // DEF: 20000
*     easing: 'require easing plugin', // DEF: linear
* });
*
* Version 0.5.2
* www.labs.skengdon.com/slider/
* www.labs.skengdon.com/slider/js/slider.min.js
*/
/*;(function($){
	$.fn.slider = function( options ) {
		var animater = function( e, settings ) {
			
			$holder = $(e);
			
			if ( settings.vertical ) {
				var tf = -(settings.cHeight-settings.tHeight);
			} else {
				var tf = -(settings.cWidth-settings.tWidth);
			};
			
			if ( settings.direction == 'ltr' ) {
				if ( settings.vertical ) {
					$holder.css({ top: 0 });
					$holder.animate( { top: tf }, settings.speed, settings.easing, function() { animater( e, settings ); } );
				} else {
					$holder.css({ left: 0 });
					$holder.animate( { left: tf }, settings.speed, settings.easing, function() { animater( e, settings ); } );
				}
			} else {
				if ( settings.vertical ) {
					$holder.css({ top: tf });
					$holder.animate( { top: 0 }, settings.speed, settings.easing, function() { animater( e, settings ); } );
				} else {
					$holder.css({ left: tf });
					$holder.animate( { left: 0 }, settings.speed, settings.easing, function() { animater( e, settings ); } );
				}
			}
		};
		
		return this.each(function() {
			var settings = {
				direction: 'ltr',
				vertical: false,
				speed: 20000,
				sleep: 5000,
				easing: 'linear'
			};
			$.extend( settings, options );
		
			settings.tHeight = $(this).height();
			settings.tWidth = $(this).width();
			var $kids = $(this).children();
			
			if ( settings.vertical ) {
				settings.cWidth = settings.tWidth;
				settings.cHeight = settings.tHeight * ($kids.length + 1);
			} else {
				settings.cWidth = settings.tWidth * ($kids.length + 1);
				settings.cHeight = settings.tHeight;
			};
			
			// holder to animation
			$kids.wrapAll('<div></div>');
			var $holder = $(this).find('div:first');
			$holder.css({ position: 'relative' });
			$holder.css({ width: settings.cWidth, height: settings.cHeight });
			
			if (settings.direction == 'ltr') {
				$holder.append( $kids.first().clone() );
			} else {
				$holder.prepend( $kids.last().clone() );
			};
			
			var $kids = $holder.children();
	
			$(this).css({ overflow: 'hidden', whiteSpace: 'nowrap' });
			$(this).css({ width: settings.tWidth, height: settings.tHeight });
			
			$kids.css({ 'float': 'left' });
			$kids.css({ width: settings.tWidth, height: settings.tHeight });
			
			animater( $holder, settings );
		});
	};
}(jQuery));*/

(function($){
	$.fn.slideContent = function(options){
		
		var defaults = {
			pauseSeconds: 2,
			fadeSpeed: 0,
			width: 468,
			height: 120,
			caption: true,
			cssClass: 'slideshowlite'
		};
		
		var options = $.extend(defaults, options);
		
		var target = this;
		var items  = $(target).children("div");
		var instance;
		
		$(this).css({
			width: options.width + "px",
			height: options.height + "px"
		});
		
		$(this).children("div").wrap(document.createElement("span"));
		
		var i = 1;
		$(this).children("span").each(function(){
			$(this).attr("rel", i++);			
		});
		
		$(this).append("<ul></ul>");
		var pagination = $(this).children("ul");
		var i = 1;
		$(this).children("span").each(function(){
			pagination.append("<li><a href=\"javascript:void(0)\">" + i++ + "</a></li>");
		}); 
		pagination.fadeTo(0, 0.8);
		var firstItem   = $(target).children("span:first");
		var lastItem    = $(target).children("span:last");
		var currentItem = firstItem;
		
		// ----------------------------------------
		// pagination highlight
		// ----------------------------------------
		var paginationHighlight = function(sequence){
			pagination.children("li").children("a").removeClass("current");
			pagination.children("li").children("a:nth(" + sequence + ")").addClass("current");
		}
		
		
		var makeSlideshow = function(){
			
			// pagination click
			pagination.children("li").children("a").click(function(){
				if (!$(this).hasClass("current"))
				{					
					// select the current item after the pagination click
					currentItem = $(target).children("span:nth(" + ($(this).text()-1) + ")");
					currentItem.show();
					startSlideshow();
				}
			});
			// pagination highlight
			paginationHighlight(currentItem.attr("rel")-1); 
			
			currentItem.fadeIn(options.fadeSpeed*1000, function(){
				$(target).children("span").hide();
				$(this).show().css("z-index", 1);
			});
			if (currentItem.attr("rel") == lastItem.attr("rel"))
			{
				currentItem = firstItem;
				currentItem.css("z-index", 2);
			}
			else
			{
				currentItem = currentItem.next();
			}
		};
		
		var startSlideshow = function(){
			clearInterval(instance);
			makeSlideshow();
			instance = setInterval(makeSlideshow, options.pauseSeconds*1000);
		};
		
		// ----------------------------------------
		// start the slideshow!
		// ----------------------------------------
		
		startSlideshow();
	};
})(jQuery);
