/* 
 * Rotator
 * Version 1.0.6
 * Author Michael Neil
 * URI: http://www.fluxar.com/
 * 
 * The MIT License
 *
 * Copyright (c) 2011 Michael Neil, Fluxar Studios
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 */
(function(c){var a=0;c.fn.rotator=function(d){c(this).each(function(e){if(e>0){a++}c(this).data("rotator",new b(this,d,a))});a++};var b=function(e,s,d){var h=c.extend({arrows:{left:".leftarrow"+d,right:".rightarrow"+d},tranSpeed:800,delay:4000,auto:true,loop:true,backwards:false,onChange:function(n){},endChange:function(n){}},s||{});var s=h;var u=false;if(!c(e)){this.onError({target:"init",error:"An element must be defined to rotate. ex: $('.slider').rotator();"});return false}if(c(e).children().length<=1){u=true;this.onError({target:"init",error:e+" has one or fewer children to rotate through"})}var q=false;if(s.backwards){q=true}var m=c(e);var k="";var j=0;var C="";var l=0;if(s.loop){var y=0;j=c(e).children().length;C=c(e).html();c(e).children(":first").before(C);c(e).children(":last").after(C)}var r=c(e).children().width();var t=c(e).children().length;var g=j;var i=false;function p(){B(0)}function B(n){if(u){return}if(n===1){s.backwards=false}else{if(n===-1){s.backwards=true}}if(i){return}if(!s.backwards){g++;if(g===t){g=0}}else{g--;if(g<0){g=t-1}}i=true;if(s.backwards){l=(g===j)?-j:g-j;l=l+j}else{l=(g-j===j)?0:g-j}if(l>=j){l-=j}s.onChange(l);x();m.animate({marginLeft:-g*r},s.tranSpeed,A)}function v(n){if(n===undefined||n>j||n<0){this.onError({target:"goToIndex",error:"The passed index is out of the range of available children to rotate to"});return false}if(i){return false}c(k).removeClass("active");c(k).eq(n).addClass("active");g=j+n;if(s.backwards){g-=j}i=true;m.animate({marginLeft:-g*r},s.tranSpeed,A);l=n;s.onChange(l);if(s.auto){clearInterval(z);z=setInterval(p,s.delay)}}function f(w){if(u){return}var n=j;k="<ul class='slider-numbers slider-numbers-"+w+"'>";var o=0;for(;o<n;o++){k+="<li><a href=''>"+(o+1)+"</a></li>"}k+="</ul>";c(e).after(k);k=".slider-numbers-"+w+" a";c(k).each(function(D){if(D===0){c(this).addClass("active")}c(this).click(function(){v(D);return false})})}function A(){i=false;if((g===0||g===t-j)){g=j;c(e).css({"margin-left":-g*r})}s.endChange(l)}function x(){c(k).removeClass("active");c(k).eq(l).addClass("active")}this.goNext=B;this.goToIndex=v;this.onError=function(n){};f(d);c(e).css({"margin-left":-g*r});c(e).css({width:r*t});c(s.arrows.right).bind("click",function(){if(s.auto){clearInterval(z);z=setInterval(p,s.delay)}s.backwards=false;B();return false});c(s.arrows.left).bind("click",function(){if(s.auto){clearInterval(z);z=setInterval(p,s.delay)}s.backwards=true;B();return false});if(s.auto&&!u){var z=setInterval(p,s.delay)}}}(jQuery));
