/*	BILLY The Carousel jquery plugin v 0.4	By. Jason Howmans (jasonhowmans@me.com)		-- Options		- scrollSpeed : The time a single transition will take	- slidePause : Amount of time between scrolls	- indicators : The target <ul> for displaying the indicators (indicators arent required for basic functionality)	- indicatorLinks : Clicking on indicators jumps to slide, true by default	- activeClass : Class to attach to the active indicator. default is 'active'	- scrollAmount : Amount to scroll by on each transition. Set to 'auto' by default	- nextLink : The element which will scroll next on click	- prevLink : The element which will scroll back on click	- autoAnimate : Do you want the carousel to play without the user pressing the next/prev buttons	- loop : Loops back to the beginning after final slide	- customIndicators : Build your own indicators. This offers developers more functionality than just a standard carousel (false by default). 	- noAnimation : Turns off fancy animation, all actions will be static	*/(function($){     	$.fn.extend({   		billy: function(options) { 					// Defaults			var defaults = {				scrollSpeed		: 500,				slidePause		: 10000,				indicators		: $('ul.indicators'),				indicatorLinks	: true,				activeClass		: 'active',				scrollAmount	: 'auto',				nextLink		: $('#scroller .next'),				prevLink		: $('#scroller .prev'),				autoAnimate		: true,				loop			: true,				customIndicators: false,				numberIndicators: false,				noAnimation		: false			};						// Set Options			var options = $.extend(defaults, options);						// Def			var option;			var object;			var slides;			var slidewidth;			var slidecount;			var currentslide;			var defautindicator;			var the_indicators;			var hreftag;			var indicatorsli;			var currentindicator;						// Loop throuch Carousels			return this.each(function() {				// Set Options				option = options;				// Set currently selected				object = $(this);				// Sets up slide size				slides = object.find('li');				if (option.scrollAmount	== 'auto') { 					slidewidth		= slides.width();				}else{ 					slidewidth = option.scrollAmount; 				}				// Other vars				slidecount = (slides.width() * slides.length) / slidewidth;				slidecount = Math.round(slidecount);				currentslide = 0;				// append clone of first slide after last, to allow seamless slide forward from the last to the first				if (jQuery.browser.msie) {					object.append( innerShiv( slides.eq(0).html() ), false );				} else {					object.append( slides.eq(0).clone() );				}								// If there's slides, continue				if (slides.length > 0) {									if( slides.length == 1 ) {						option.prevLink.hide();						option.nextLink.hide();						return;					}										// If the developer wants default indicators					if (!option.customIndicators) {						// Loop / no. of slides						option.indicators.each( function(y) {							for (var i = 0; i<slidecount; i++) {								// -- Insert Indicators								if (!option.indicatorLinks) {									$( this ).append('<li></li>');								}else{									$( this ).append('<li><a href="#'+i+'"></a></li>');								}							}						});					}					if (option.customIndicators && option.numberIndicators) {						for (var i = 0; i<slidecount; i++) {							// -- Insert Indicators							if (!option.indicatorLinks) {								option.indicators.append('<li></li>');							}else{								option.indicators.append('<li><a href="#'+i+'">'+(i+1)+'</a> '+((i+1)<slidecount?'|':'')+'</li>');							}						}					}						// Indicator Functionality					defautindicator = option.indicators.find('li:eq(0)');					defautindicator.addClass(option.activeClass)					the_indicators = option.indicators.find('li a');								// Thanks to Tomas Nikl for the below fix					the_indicators.click( function() {						hreftag = $(this).attr('href');						hreftag = hreftag.substring(hreftag.search('#')+1, hreftag.length);						jumptospecific(hreftag);						if (option.autoAnimate) {							clearInterval(period);							period = window.setInterval(function() {								if (currentslide >= (slidecount - 1)) {									jumptostart();								}else{									jumpnext();								}							}, option.slidePause);						}						return false;					});													// -- Jump Functions					var jumptostart = function() {						if (option.noAnimation) {							object.css('marginLeft', "0");						}else if (currentslide == (slidecount - 1)){							// if at last slide, continue to the final clone							currentslide ++;							object.animate({'marginLeft': "-"+(slidewidth*currentslide)}, option.scrollSpeed, function() {								// jump instantly back to the real first item								object.css('marginLeft', "0");							});							indicatorsli = option.indicators.find('li');							indicatorsli.removeClass();							currentindicator = option.indicators.find('li:eq(0)');							currentindicator.addClass(option.activeClass);							if (option.autoAnimate) {								clearInterval(period);								period = window.setInterval(function() {									if (currentslide >= (slidecount - 1)) {										jumptostart();									}else{										jumpnext();									}								}, option.slidePause);							}						}else{							object.animate({'marginLeft': "0"}, option.scrollSpeed);						}					    currentslide = 0;					    indicatorsli = option.indicators.find('li');						indicatorsli.removeClass();					   	currentindicator = option.indicators.find('li:eq('+(currentslide)+')');						currentindicator.addClass(option.activeClass);					};						var jumptoend = function() {					    currentslide = slidecount-1;						if (option.noAnimation) {							object.css('marginLeft', "-"+(currentslide*slidewidth)+"px");						}else{					    	object.animate({'marginLeft': "-"+(currentslide*slidewidth)}, option.scrollSpeed);						}					    indicatorsli = option.indicators.find('li')						indicatorsli.removeClass();					    currentindicator = option.indicators.find('li:eq('+(currentslide)+')');						currentindicator.addClass(option.activeClass);					};					var jumpnext = function() {						if (currentslide < (slidecount - 1)) {							currentslide ++;							if (option.noAnimation) {								object.css('marginLeft', "-"+(slidewidth*currentslide)+"px");							}else{								object.animate({'marginLeft': "-"+(slidewidth*currentslide)}, option.scrollSpeed);							}							indicatorsli = option.indicators.find('li');							indicatorsli.removeClass();							currentindicator = option.indicators.find('li:eq('+(currentslide)+')');							currentindicator.addClass(option.activeClass);							if (option.autoAnimate) {								clearInterval(period);								period = window.setInterval(function() {									if (currentslide >= (slidecount - 1)) {										jumptostart();									}else{										jumpnext();									}								}, option.slidePause);							}						}else{							if (option.loop)								jumptostart();						}					};					var jumpback = function() {						if (currentslide > 0) {							currentslide --;							if (option.noAnimation) {								object.css('marginLeft', "-"+(slidewidth*currentslide)+"px");							}else{								object.animate({'marginLeft': "-"+(slidewidth*currentslide)}, option.scrollSpeed);							}							indicatorsli = option.indicators.find('li');							indicatorsli.removeClass();							currentindicator = option.indicators.find('li:eq('+(currentslide)+')');							currentindicator.addClass(option.activeClass);							if (option.autoAnimate) {								clearInterval(period);								period = window.setInterval(function() {									if (currentslide >= (slidecount - 1)) {										jumptostart();									}else{										jumpnext();									}								}, option.slidePause);							}						}else{							if (option.loop)								jumptoend();						}					};					var jumptospecific = function(frame) {						if (currentslide !== frame) {							currentslide = frame;							if (option.noAnimation) {								object.css('marginLeft', "-"+(slidewidth*currentslide)+"px");							}else{						    	object.animate({'marginLeft': "-"+(slidewidth*currentslide)}, option.scrollSpeed);							}						    indicatorsli = option.indicators.find('li');							indicatorsli.removeClass();						    currentindicator = option.indicators.find('li:eq('+(currentslide)+')');							currentindicator.addClass(option.activeClass);						}					};										// -- Click next/prev					option.nextLink.click( function() {						jumpnext();						return false;					});										option.prevLink.click( function() {						jumpback();						return false;					});										// -- Autoanimate					if (option.autoAnimate) {						// -- Periodical						var period;						// Run						period = window.setInterval(function() {											if (currentslide >= (slidecount - 1)) {								jumptostart();							}else{								jumpnext();							}								}, option.slidePause);					}				}							});					}			});})(jQuery);
