/*
	Name: Rotary
	Purpose: fairly loose function for a few different types of interactivity; image fading/sliding with carousel type interactions (index / next/previous)
	Author: James Crockford
	Version: 0.4 beta
*/

/*
OPTIONS:
	auto: {interval:5000},
	changer: 'img',
	control: {
		ind: {
			element: $('#ind a'),
			binding: 'mouseover',
			onclass: 'current'
		},
		arrows: {
			nxt: $('#rightarrow'),
			prv: $('#leftarrow'),
			binding: 'click'
		}
	},
	onstage: {
		opacity:1
	},
	offstage: {
		opacity:0
	},
	ext: {
		queue:false,
		duration:500,
		easing:'swing'
	}
	
*/


//compiled
(function(h){h.fn.extend({rotary:function(i){i=h.extend({auto:{interval:3E3},changer:"img",control:{ind:false,arrows:false},onstage:{opacity:1},offstage:{opacity:0},ext:{queue:false,duration:500,easing:"swing"},hash:false},i);return this.each(function(){function f(k){e.children(a.changer).animate(a.offstage,{queue:a.ext.queue,easing:a.ext.easing,duration:a.ext.duration}).eq(k).animate(a.onstage,{queue:a.ext.queue,easing:a.ext.easing,duration:a.ext.duration});typeof a.control.ind.onclass=="string"&& a.control.ind.element.removeClass(a.control.ind.onclass).eq(k).addClass(a.control.ind.onclass)}var a=i,e=h(this),g,b=false,c={auto:typeof a.auto,control:typeof a.control,changer:typeof a.changer,ind:typeof a.control.ind,arrows:typeof a.control.arrows,onclass:typeof a.control.ind.onclass};if(e.children(a.changer).length)var j=e.children(a.changer).length-1;if(a.hash&&location.hash){first=location.hash.substr(1);if(first>e.children(a.changer).length)first=e.children(a.changer).length}else first=1;var d= first-1;if(c.changer=="string"){e.children(a.changer).css(a.offstage).eq(first-1).css(a.onstage);c.onclass=="string"&&a.control.ind.element.removeClass(a.control.ind.onclass).eq(0).addClass(a.control.ind.onclass)}if(c.auto=="object"&&c.changer=="string"){d=first;g=setInterval(function(){f(d);if(d==j)d=0;else d++},a.auto.interval)}if(c.control=="object"&&c.changer=="string"){c.ind=="object"&&a.control.ind.element.bind(a.control.ind.binding,function(){c.auto=="object"&&clearInterval(g);ti=a.control.ind.element.index(this); if(c.arrows=="object")b=ti;f(ti);return false});if(c.arrows=="object"){a.control.arrows.nxt.bind(a.control.arrows.binding,function(){if(c.auto=="object"&&b===false){clearInterval(g);b=d}else{if(b===false)b=a.hash?d:0;if(b==j)b=0;else b++}f(b);return false});a.control.arrows.prv.bind(a.control.arrows.binding,function(){if(c.auto=="object"&&b===false){clearInterval(g);b=d}else{if(b===false)b=a.hash?d:0;if(b==0)b=j;else b--}f(b);return false})}}})}})})(jQuery);


