
var ticker=function(){var options,animateDuration,pauseDuration,count,current,paused,nav;function init(options){options=options||{};ticker.options=options;ticker.animateDuration=350;ticker.pauseDuration=3000;ticker.count=0;ticker.current=0;ticker.paused=false;if($(ticker.options.ticker).length==1){makeTicker();}}
function makeTicker(){ticker.count=$(ticker.options.items).hide().filter(":eq(0)").show(0).add(ticker.options.items).size()-1;if(ticker.count>0){ticker.nav=$($('<div class="controlNav" />').append('<ul><li class="previous" title="Previous"><span class="displace">Previous</span></li><li class="pause" title="Start/Pause"><span class="displace">Start/Pause</span></li><li class="next" title="Next"><span class="displace">Next</span></li>')).appendTo(ticker.options.ticker);$(".previous",ticker.nav).click(function(){previous();});$(".next",ticker.nav).click(function(){next();});$(".pause",ticker.nav).click(function(){if(!ticker.paused){scrollPause();}
else{scrollPlay();}});$($(ticker.options.items).get(ticker.current)).animate({"opacity":1},ticker.pauseDuration,"linear",function(){startAuto();});}}
function startAuto(){goTo("auto");}
function stopAuto(){$(ticker.options.items).each(function(){$(this).stop();hideShow(ticker.current);});}
function scrollPause(){ticker.paused=true;ticker.nav.find(".pause").removeClass("pause").addClass("play");stopAuto();}
function scrollPlay(){ticker.paused=false;ticker.nav.find(".play").removeClass("play").addClass("pause");startAuto();}
function next(){scrollPause();goTo("next");}
function previous(){scrollPause();goTo("prev");}
function goTo(dir){var from,to;if(dir=="prev"){to=ticker.current-1;from=ticker.current;if(to<0){to=ticker.count;from=0;}}
else{if(dir=="next"||dir=="auto"){to=ticker.current+1;from=ticker.current;if(to>ticker.count){to=0;from=ticker.count;}}}
if(dir=="auto"){animate(from,to);}
else{hideShow(to);}}
function animate(from,to){$($(ticker.options.items).get(from)).fadeOut(ticker.animateDuration,function(){$($(ticker.options.items).get(to)).fadeIn(ticker.animateDuration,function(){ticker.current=to;$(this).animate({"opacity":1},ticker.pauseDuration,"linear",function(){goTo("auto");});});});}
function hideShow(to){$(ticker.options.items).css({"display":"none","opacity":1});ticker.current=to;$($(ticker.options.items).get(to)).show(0);}
return{init:init};}();$(document).ready(function(){ticker.init({"ticker":"#ticker","items":"#ticker dd"});});