
(function($){$.slideShow=function(sel,options){return(function(){var els=$(sel);for(var i=0;i<els.length;++i){els[i].slideshow={};$.extend(els[i].slideshow,$.slideShow.proto);els[i].slideshow.settings.rotatorElement=els[i];if(options)$.extend(els[i].slideshow.settings,options);els[i].slideshow.start();}});}
$.slideShow.proto={settings:{rotatorElement:'#slideshow',slideElement:'.slide',interval:5000,fadeTime:1000,styleConsole:false,styleSlideshow:true,makeConsole:true,fadeConsole:false,pauseOnHover:true,consoleFadeout:500,consoleFadein:100},_timer:null,_index:-1,_items:[],_root:null,_hoverTimer:null,_onHover:function(){if(this.settings.pauseOnHover){this._stopTimer();}
if(!this.settings.fadeConsole){return;}
if(this._hoverTimer){window.clearTimeout(this._hoverTimer);}
this._root.find('.console').fadeTo(this.settings.consoleFadein,0.95);},_onUnhover:function(){if(this.settings.pauseOnHover){this._startTimer();}
var _this=this;if(!this.settings.fadeConsole){return;}},_populateConsole:function(){var rotator=this;var cons=$("<div class='console'></div>");if(rotator.settings.styleConsole){cons.css({position:'absolute',bottom:'0px',left:'0px',width:rotator._root.width()+'px',background:'rgba(5,5,5,0.5)',zIndex:10});}
this._root.append(cons);for(var i=0;i<this._items.length;++i){classname="item-"+(i+1);var newNode=$('<a href="#" class="'+classname+'">'+(i+1)+'</a>');newNode[0].index=i;newNode.click(function(){rotator.flipTo(this.index);return false;});cons.append(newNode);}
this._root.hover(function(){_this._onHover();},function(){_this._onUnhover();});},_stopTimer:function(){if(this._timer){window.clearTimeout(this._timer);}},_startTimer:function(){this._stopTimer();this._timer=window.setTimeout(function(){_this.flip();},this.settings.interval);},start:function(){var _this=this;this._root=$(this.settings.rotatorElement);this._items=this._root.find(this.settings.slideElement);item_top=this._items.css('top');item_left=this._items.css('left');if(!item_top){item_top="0px";}
if(!item_left){item_left="0px";}
this._items.css({visibility:'visible',display:'none'});if(this.settings.styleSlideshow){this._root.css({position:'relative'});this._items.css({position:'absolute',top:item_top,left:item_left,zIndex:'0'});}
if(this.settings.makeConsole){this._populateConsole();}
this._startTimer();this.flip();},flipTo:function(target){this._stopTimer();this._items.stop();this._items.css({zIndex:0});$(this._items[target]).css({zIndex:1}).fadeTo(1,1.0);for(var i=0;i<this._items.length;++i){if(i!=target){$(this._items[i]).fadeTo(1,0.0);}}
this._index=target;this._updateConsole(this._index);if(!this.settings.pauseOnHover){this._startTimer();}},_updateConsole:function(){var links=this._root.find('.console a');links.removeClass('active');$(links[this._index]).addClass('active');links.each(function(){newClass="item-"+(this.index+1)+"-active";if($(this).is('.active')){$(this).addClass(newClass);}else{$(this).removeClass(newClass);}});},flip:function(n){_this=this;old_el=null;if(_this._index!=-1){old_el=$(_this._items[_this._index]);}
_this._index++;if(_this._index>=_this._items.length){_this._index=0;}
new_el=$(this._items[this._index]);fadeTime=this.settings.fadeTime;if(!old_el){var others=_this._items;others.css({zIndex:0}).show().fadeTo(1,0.0);new_el.css({zIndex:1});new_el.show().fadeTo(1,1.0);this._index=0;this._updateConsole();}else{old_el.css({zIndex:0});new_el.css({zIndex:1});this._items.stop();var rotator=this;new_el.fadeTo(fadeTime,1.0,function(){old_el.fadeTo(1,0.0);rotator._updateConsole();});}
this._startTimer();}};})(jQuery);
