(function($)
{
	$.fn.slideShow = function(options){
	if (this.length > 1){
		this.each(function() { $(this).slideShow(options)});
		return this;}
	this.defaults = {
		start: 0, interval: 4, repeat: true, transition:{/* interval was 3 changed on 10-24-10 by afa*/
			mode: 'fade',speed: 1000},
			slideSize: 'auto', hoverNavigation:false, slideClick: false, gotoSlide: false };
	this.options = $.extend({}, this.defaults, options);
	this.SlideNumber = this.find('.slides li').length;
	if (this.options.start == 'random' || this.options.start == 'rnd'){
		this.current = Math.floor(Math.random() * this.SlideNumber) + 1;}
	else{this.current = this.options.start;}
	if (this.current >= this.SlideNumber){
		this.current = this.SlideNumber - 1;}
	this.last = false;
	this.elm = $(this);
	this.interval = false;
	this.mouse = { x: 0, y: 0, over: false };
	this.init = function(){
	if (this.find('.slides').length){
		if (this.options.slideSize == 'auto'){
			this.options.slideSize = {
					width: this.find('.slides li:first img').width(),
					height: this.find('.slides li:first img').height()};}
		}
	this.find('.slides li').css('position', 'absolute');
	this.find('.slides li:not(:eq(' + this.current + '))').hide();
	this.find('.paging, .slides li, li a, .slides').data('slideShow', this);
	this.find('.paging li a:eq(' + this.current + ')').addClass('selected');
	this.find('.paging li a').click(function(e) {
		if (!(slideShow = $(this).data('slideShow'))) {
			var slideShow = this;}
		var index = $(this).html();
		if (!(index = parseInt($(this).html()-1))) {
			var index = $(this).parents('.paging').find('li a').index($(this));}
		e.preventDefault();
		slideShow.gotoSlide(index);});
	g = this.current;
	this.current = -1;
	this.gotoSlide(g);
	if (this.options.interval > 0) {
		this.auto();}
	return this;};
	this.auto = function() {
		if (!(slideShow = $(this).data('slideShow'))) {
			var slideShow = this;}
		if (!slideShow.interval && slideShow.options.interval > 0.001) {
			slideShow.interval = window.setInterval(function() {
				slideShow.next();
				}, slideShow.options.interval * 1000);}
		return this; }
	this.isPlaying = function() {
		if (!(slideShow = $(this).data('slideShow'))) {
			var slideShow = this; }
		return slideShow.options.interval;}
	this.stopAuto = function(){
		if (!(slideShow = $(this).data('slideShow'))){
			var slideShow = this;}
		if (slideShow.interval) {
			window.clearInterval(slideShow.interval);
			slideShow.interval = false;	}
		return this;}
	this.first = function(elm) {
		if (!(slideShow = $(this).data('slideShow'))) {
			var slideShow = this; }
		return slideShow.gotoSlide(0);};
		this.next = function() {
			if (!(slideShow = $(this).data('slideShow'))) {
				var slideShow = this;}
			return slideShow.gotoSlide(slideShow.current + 1); };
			this.previous = function() {
				if (!(slideShow = $(this).data('slideShow'))) {
					var slideShow = this;}
				return slideShow.gotoSlide(slideShow.current - 1);};
				this.last = function() {
					if (!(slideShow = $(this).data('slideShow'))) {
						var slideShow = this;}
					return slideShow.gotoSlide(slideShow.SlideNumber);};
					this.gotoSlide = function(index, noanimation) {
						if (index < 0) {
							index = this.SlideNumber - 1;}
						if (index >= this.SlideNumber) {
							index = 0;}
						if (index === this.current) return this;
						
						var oldSlide = this.find('.slides li:eq(' + this.current +')');
						var newSlide = this.find('.slides li:eq(' + index +')');
						
						oldFinished = function () {
							$(this).removeClass('selected');
							if (!(slideShow = $(this).data('slideShow'))) {
								var slideShow = this;}
							slideShow.elm.find('.paging li a:eq(' + slideShow.current + ')').addClass('selected');
							if (!slideShow.mouse.over) {
								slideShow.auto();}}
						newFinished = function() {
							if (!(slideShow = $(this).data('slideShow'))) {
								var slideShow = this;}
							if (slideShow.current >= 0) {
								slideShow.elm.find('.paging li a:not(:eq(' + slideShow.current + '))').removeClass('selected');	}
							$(this).addClass('selected');}
						
						if (!(slideShow = $(this).data('slideShow'))) {
							var slideShow = this;}
						slideShow.stopAuto();
						
						if (typeof(this.options.gotoSlide) == 'function') {
							this.options.gotoSlide(slideShow, index);}
						
						if (noanimation) {
							oldSlide.hide(1, oldFinished);
							newSlide.show(1, newFinished);
							} else {
								if (typeof(this.options.transition.mode) == 'function') {
									this.call(this.options.transition.mode, newSlide, oldSlide);
									} else {
										switch(this.options.transition.mode) {
										default:
											case 'fade':
												oldSlide.fadeOut(this.options.transition.speed, oldFinished);
												newSlide.fadeIn(this.options.transition.speed, newFinished);
												break;}	}}
						this.last = this.current;
						this.current = index;
						return this;};
						return this.init();	}
	})(jQuery);
