/*!
 * SimpleFlame Content rotator
 * Version 0.2 (28.04.2009)
 * Possible effects to use :
 *  - if UI effects have been added: 'blind', 'bounce', 'clip', 'drop', 'explode', 'fold', 'highlight', 'puff', 'pulsate', 'scale', 'shake', 'size', 'slide', 'transfer'
 *  - basic effects from jQuery: fadeIn, fadeOut, show, hide, slideUp, slideDown
 */
(function(){var sfRotator=function(el,options){this.settings={'item':'li','activeClass':'active','duration':5000,'autorotate':true,'effectIn':'fadeIn','optionsIn':{},'speedIn':'normal','effectOut':'fadeOut','optionsOut':{},'speedOut':'normal'};jQuery.extend(this.settings,options);this.$container=jQuery(el);this.build();};sfRotator.prototype.build=function(){this.$container.addClass('sf-items');this.$wrapper=jQuery('<div class="sf-rotator" />');this.$container.before(this.$wrapper);this.$wrapper.append(this.$container);this.$controls=jQuery('<ul class="sf-controls" />');this.$wrapper.append(this.$controls);this.$items=this.$container.children(this.settings.item);this.$current=this.$items.index(this.$items.filter('.'+this.settings.activeClass));if(this.$current<0){this.$current=0;}var self=this;this.$items.addClass('sf-item').each(function(index,item){var trigger=jQuery('<li><a href="#">'+parseInt(index+1,10)+'</a></li>');self.$controls.append(trigger);trigger.find('a').data('item',item).bind('click',{self:self},self.trigger);});this.activate(this.$current,true);if(this.settings.autorotate){this.autorotate();}};sfRotator.prototype.trigger=function(event){event.preventDefault();var self=event.data.self;self.stopAutorotate();self.$rotationTerminated=true;var position=self.$items.index(jQuery(this).data('item'));self.activate(position);};sfRotator.prototype.activate=function(position){var instant=arguments[1]||false;var activeClass=this.settings.activeClass;var oldItem=this.$items.eq(this.$current);var newItem=this.$items.eq(position);var onHide=function(){oldItem.removeClass(activeClass);};var onShow=function(){newItem.addClass(activeClass).css('zIndex',10);};var effects=['blind','bounce','clip','drop','explode','fold','highlight','puff','pulsate','scale','shake','size','slide','transfer'];if(instant===true){oldItem.removeClass(activeClass).hide();newItem.addClass(activeClass).show();}else{if(jQuery.inArray(this.settings.effectOut,effects)>-1){oldItem.hide(this.settings.effectOut,this.settings.optionsOut,this.settings.speedOut,onHide);}else if(jQuery.isFunction(oldItem[this.settings.effectOut])){oldItem[this.settings.effectOut](this.settings.speedOut,onHide);}else{throw"Unsupported hide transition";}newItem.css('zIndex',100);if(jQuery.inArray(this.settings.effectIn,effects)>-1){newItem.show(this.settings.effectIn,this.settings.optionsIn,this.settings.speedIn,onShow);}else if(jQuery.isFunction(newItem[this.settings.effectIn])){newItem[this.settings.effectIn](this.settings.speedIn,onShow);}else{throw"Unsupported show transition";}}this.$controls.find('a').removeClass('active').eq(position).addClass('active');this.$current=position;};sfRotator.prototype.autorotate=function(){this.$rotationTerminated=false;var self=this;this.$container.mouseenter(function(){self.stopAutorotate();});this.$container.mouseleave(function(){self.startAutorotate();});this.startAutorotate();};sfRotator.prototype.startAutorotate=function(){if(this.$rotationTerminated===true){return;}var self=this;this.$rotationInterval=window.setInterval(function(){var next=self.$current+1;if(next===self.$items.length){next=0;}self.activate(next);},this.settings.duration);};sfRotator.prototype.stopAutorotate=function(){if(this.settings.autorotate){window.clearInterval(this.$rotationInterval);}};jQuery.fn.sfRotator=function(options){options=options||{};return this.each(function(){var r=new sfRotator(this,options);});};})();


