(function($){var container,elements,settings;var currentTimeout=null;var count=0;$.fn.innerFade=function(options){return this.each(function(){$.innerFade(this,options);});};$.innerFade=function(container,options){var defaultSettings={'animationType':'fade','easing':'linear','speed':'normal','type':'sequence','timeout':2000,'loop':true,'containerHeight':'auto','runningClass':'innerFade','children':null,'cancelLink':null,'pauseLink':'.pause','prevLink':'.prev','nextLink':'.next','indexContainer':null,'currentItemContainer':null,'totalItemsContainer':null};if(options){settings=$.extend(defaultSettings,options);}
elements=(settings.children===null)?$(container).children():$(container).children(settings.children);container=container;if(elements.length>1){$.bindControls();if(settings.cancelLink){$.bindCancel();};$(container).css({'position':'relative','height':settings.containerHeight}).addClass(settings.runningClass);if(settings.indexContainer){$.innerFadeIndex();};$(elements).filter(':gt(0)').hide(0);for(var i=0;i<elements.length;i++){$(elements[i]).css('z-index',String(elements.length-i)).css('position','absolute');}
var toShow='';var toHide='';if(settings.type=="random"){toHide=Math.floor(Math.random()*elements.length);do{toShow=Math.floor(Math.random()*elements.length);}while(toHide==toShow);$.fadeTimeout(toShow,toHide,true);$(elements[toHide]).show();}else if(settings.type=='random_start'){settings.type='sequence';toShow=Math.floor(Math.random()*(elements.length));$.fadeTimeout((toShow+1)%elements.length,toShow,true);$(elements[toShow]).show();}else{toShow=0;toHide=elements.length-1;$.fadeTimeout(toShow,toHide,true);$(elements[0]).show();}
if(settings.currentItemContainer){$.currentItem(toShow);};if(settings.totalItemsContainer){$.totalItems();};$.bindPause();}};$.fadeToItem=function(toShow,toHide){var buildControls=function(){if(settings.nextLink||settings.prevLink){$.bindControls();}};if(settings.animationType=='slide'){$(elements[toHide]).slideUp(settings.speed);$(elements[toShow]).slideDown(settings.speed,function(){buildPreviousNext();});}else if(settings.animationType=='slideOver'){var itemWidth=$(elements[0]).width();$(container).css({'overflow':'hidden'});$(elements[toHide]).css({'left':'0px','position':'absolute','right':'auto','top':'0px'});$(elements[toShow]).css({'left':'auto','position':'absolute','right':'-'+itemWidth+'px','top':'0px'}).show();$(elements[toHide]).animate({'left':'-'+itemWidth+'px'},settings.speed,settings.easing,function(){$(this).hide();});$(elements[toShow]).animate({'right':'0px'},settings.speed,settings.easing,function(){buildControls();});}else{$(elements[toHide]).fadeOut(settings.speed);$(elements[toShow]).fadeIn(settings.speed,function(){buildControls();});}
if(settings.currentItemContainer){$.currentItem(toShow);};if(settings.indexContainer){$.updateIndexes(toShow);};};$.fadeTimeout=function(toShow,toHide,firstRun){if(firstRun!=true){$.fadeToItem(toShow,toHide);};count++;if(settings.loop==false&&count>=elements.length){$.stopSlideshow();return;};if(settings.type=="random"){toHide=toShow;while(toShow==toHide){toShow=Math.floor(Math.random()*elements.length);}}else{toHide=(toHide>toShow)?0:toShow;toShow=(toShow+1>=elements.length)?0:toShow+1;}
currentTimeout=setTimeout((function(){$.fadeTimeout(toShow,toHide,false);}),settings.timeout);};$.fn.innerFadeUnbind=function(){return this.each(function(index){$.stopSlideshow();});};$.stopSlideshow=function(){clearTimeout(currentTimeout);currentTimeout=null;};$.bindControls=function(){$(settings.nextLink).unbind().one('click',function(event){event.preventDefault();$.stopSlideshow();var $currentElement=$(elements).filter(':visible');var currentElementIndex=$(elements).index($currentElement);var $nextElement=($currentElement.next().length>0)?$currentElement.next():$(elements).filter(':first');var nextElementIndex=$(elements).index($nextElement);$.fadeToItem(nextElementIndex,currentElementIndex);});$(settings.prevLink).unbind().one('click',function(event){event.preventDefault();$.stopSlideshow();var $currentElement=$(elements).filter(':visible');var currentElementIndex=$(elements).index($currentElement);var $previousElement=($currentElement.prev().length>0)?$currentElement.prev():$(elements).filter(':last');var previousElementIndex=$(elements).index($previousElement);$.fadeToItem(previousElementIndex,currentElementIndex);});};$.bindPause=function(){$(settings.pauseLink).unbind().click(function(event){event.preventDefault();if(currentTimeout!=null){$.stopSlideshow();}else{var tag=$(container).children(':first').attr('tagName').toLowerCase();var nextItem='';var previousItem='';if(settings.type=="random"){previousItem=Math.floor(Math.random()*elements.length);do{nextItem=Math.floor(Math.random()*elements.length);}while(previousItem==nextItem);}else if(settings.type=="random_start"){previousItem=Math.floor(Math.random()*elements.length);nextItem=(previousItem+1)%elements.length;}else{previousItem=$(tag,$(container)).index($(tag+':visible',$(container)));nextItem=((previousItem+1)==elements.length)?0:previousItem+1;}
$.fadeTimeout(nextItem,previousItem,false);}});};$.bindCancel=function(){$(settings.cancelLink).unbind().click(function(event){event.preventDefault();$.stopSlideshow();});};$.updateIndexes=function(toShow){$(settings.indexContainer).children().removeClass('active');$('> :eq('+toShow+')',$(settings.indexContainer)).addClass('active');};$.createIndexHandler=function(count,link){$(link).click(function(event){event.preventDefault();var $currentVisibleItem=$(elements).filter(':visible');var currentItemIndex=$(elements).index($currentVisibleItem);$.stopSlideshow();if($currentVisibleItem.size()<=1){$.fadeToItem(count,currentItemIndex);};});};$.createIndexes=function(){var $indexContainer=$(settings.indexContainer);for(var i=0;i<elements.length;i++){var $link=$('<li><a href="#">'+(i+1)+'</a></li>');$.createIndexHandler(i,link);return $link;};};$.linkIndexes=function(){var $indexContainer=$(settings.indexContainer);var $indexContainerChildren=$('> :visible',$indexContainer);if($indexContainerChildren.size()==elements.length){var count=elements.length;for(var i=0;i<count;i++){$('a',$indexContainer).click(function(event){event.preventDefault();});$.createIndexHandler(i,$indexContainerChildren[i]);};}else{alert("There is a different number of items in the menu and slides. There needs to be the same number in both.\nThere are "+$indexContainerChildren.size()+" in the indexContainer.\nThere are "+elements.length+" in the slides container.");};};$.innerFadeIndex=function(){var $indexContainer=$(settings.indexContainer);if($indexContainer.html().length<=0){$.createIndexes();}else{$.linkIndexes();};};$.currentItem=function(current){var $container=$(settings.currentItemContainer);$container.text(current+1);};$.totalItems=function(){var $container=$(settings.totalItemsContainer);$container.text(elements.length);};})(jQuery);