(function(a){a.fn.ticker=function(b){var c=a.extend({},a.fn.ticker.defaults,b);if(a(this).length==0){if(window.console&&window.console.log){window.console.log("Element does not exist in DOM!")}else{alert("Element does not exist in DOM!")}return false}var d="#"+a(this).attr("id");var e=a(this).get(0).tagName;return this.each(function(){function q(b){o();switch(b){case"prev":if(f.position==0){f.position=g(f.newsArr)-2}else if(f.position==1){f.position=g(f.newsArr)-1}else{f.position=f.position-2}a(f.dom.titleElem).html(f.newsArr["item-"+f.position].type);a(f.dom.contentID).html(f.newsArr["item-"+f.position].content);break;case"next":a(f.dom.titleElem).html(f.newsArr["item-"+f.position].type);a(f.dom.contentID).html(f.newsArr["item-"+f.position].content);break}if(f.position==g(f.newsArr)-1){f.position=0}else{f.position++}}function p(){f.play=true;f.paused=false;n()}function o(){f.play=false;a(f.dom.tickerID+","+f.dom.revealID+","+f.dom.titleID+","+f.dom.titleElem+","+f.dom.revealElem+","+f.dom.contentID).stop(true,true);a(f.dom.revealID+","+f.dom.revealElem).hide();a(f.dom.wrapperID).find(f.dom.titleID+","+f.dom.titleElem).show().end().find(f.dom.contentID).show()}function n(){if(f.play){a(f.dom.contentID).delay(c.pauseOnItems).fadeOut(c.fadeOutSpeed);if(c.displayType=="fade"){a(f.dom.contentID).fadeOut(c.fadeOutSpeed,function(){a(f.dom.wrapperID).find(f.dom.revealElem+","+f.dom.contentID).hide().end().find(f.dom.tickerID+","+f.dom.revealID).show().end().find(f.dom.tickerID+","+f.dom.revealID).removeAttr("style");l()})}else{a(f.dom.revealID).hide(0,function(){a(f.dom.contentID).fadeOut(c.fadeOutSpeed,function(){a(f.dom.wrapperID).find(f.dom.revealElem+","+f.dom.contentID).hide().end().find(f.dom.tickerID+","+f.dom.revealID).show().end().find(f.dom.tickerID+","+f.dom.revealID).removeAttr("style");l()})})}}else{a(f.dom.revealElem).hide()}}function m(){a(f.dom.contentID).css("opacity","1");if(f.play){var b=a(f.dom.titleID).width()+20;a(f.dom.revealID).css(c.direction,b+"px");if(c.displayType=="fade"){a(f.dom.revealID).hide(0,function(){a(f.dom.contentID).css(c.direction,b+"px").fadeIn(c.fadeInSpeed,n)})}else if(c.displayType=="scroll"){}else{a(f.dom.revealElem).show(0,function(){a(f.dom.contentID).css(c.direction,b+"px").show();animationAction=c.direction=="right"?{marginRight:distance+"px"}:{marginLeft:distance+"px"};a(f.dom.revealID).css("margin-"+c.direction,"0px").delay(20).animate(animationAction,time,"linear",n)})}}else{return false}}function l(){f.contentLoaded=true;a(f.dom.titleElem).html(f.newsArr["item-"+f.position].type);a(f.dom.contentID).html(f.newsArr["item-"+f.position].content);if(f.position==g(f.newsArr)-1){f.position=0}else{f.position++}distance=a(f.dom.contentID).width();time=distance/c.speed;m()}function k(){if(f.contentLoaded==false){if(c.ajaxFeed){if(c.feedType=="xml"){a.ajax({url:c.feedUrl,cache:false,dataType:c.feedType,async:true,success:function(a){count=0;for(var b=0;b<a.childNodes.length;b++){if(a.childNodes[b].nodeName=="rss"){xmlContent=a.childNodes[b]}}for(var d=0;d<xmlContent.childNodes.length;d++){if(xmlContent.childNodes[d].nodeName=="channel"){xmlChannel=xmlContent.childNodes[d]}}for(var e=0;e<xmlChannel.childNodes.length;e++){if(xmlChannel.childNodes[e].nodeName=="item"){xmlItems=xmlChannel.childNodes[e];var h,j=false;for(var k=0;k<xmlItems.childNodes.length;k++){if(xmlItems.childNodes[k].nodeName=="title"){h=xmlItems.childNodes[k].lastChild.nodeValue}else if(xmlItems.childNodes[k].nodeName=="link"){j=xmlItems.childNodes[k].lastChild.nodeValue}if(h!==false&&h!=""&&j!==false){f.newsArr["item-"+count]={type:c.titleText,content:'<a href="'+j+'">'+h+"</a>"};count++;h=false;j=false}}}}if(g(f.newsArr<1)){i("Couldn't find any content from the XML feed for the ticker to use!");return false}f.contentLoaded=true;l()}})}else{i("Code Me!")}}else if(c.htmlFeed){if(a(d+" LI").length>0){a(d+" LI").each(function(b){f.newsArr["item-"+b]={type:c.titleText,content:a(this).html()}})}else{i("Couldn't find HTML any content for the ticker to use!");return false}}else{i("The ticker is set to not use any types of content! Check the settings for the ticker.");return false}}}function j(){k();a(d).wrap('<div id="'+f.dom.wrapperID.replace("#","")+'"></div>');a(f.dom.wrapperID).children().remove();a(f.dom.wrapperID).append('<div id="'+f.dom.tickerID.replace("#","")+'" class="ticker"><p id="'+f.dom.contentID.replace("#","")+'" class="ticker-content"></p><div id="'+f.dom.revealID.replace("#","")+'" class="ticker-swipe"><span><!-- --></span></div></div>');a(f.dom.wrapperID).removeClass("no-js").addClass("ticker-wrapper has-js "+c.direction);a(f.dom.tickerElem+","+f.dom.contentID).hide();if(c.controls){a(f.dom.controlsID).live("click mouseover mousedown mouseout mouseup",function(b){var c=b.target.id;if(b.type=="click"){switch(c){case f.dom.prevID.replace("#",""):f.paused=true;a(f.dom.playPauseID).addClass("paused");q("prev");break;case f.dom.nextID.replace("#",""):f.paused=true;a(f.dom.playPauseID).addClass("paused");q("next");break;case f.dom.playPauseID.replace("#",""):if(f.play==true){f.paused=true;a(f.dom.playPauseID).addClass("paused");o()}else{f.paused=false;a(f.dom.playPauseID).removeClass("paused");p()}break}}else if(b.type=="mouseover"&&a("#"+c).hasClass("controls")){a("#"+c).addClass("over")}else if(b.type=="mousedown"&&a("#"+c).hasClass("controls")){a("#"+c).addClass("down")}else if(b.type=="mouseup"&&a("#"+c).hasClass("controls")){a("#"+c).removeClass("down")}else if(b.type=="mouseout"&&a("#"+c).hasClass("controls")){a("#"+c).removeClass("over")}});a(f.dom.wrapperID).append('<ul id="'+f.dom.controlsID.replace("#","")+'" class="ticker-controls"><li id="'+f.dom.playPauseID.replace("#","")+'" class="jnt-play-pause controls"><a href=""><!-- --></a></li><li id="'+f.dom.prevID.replace("#","")+'" class="jnt-prev controls"><a href=""><!-- --></a></li><li id="'+f.dom.nextID.replace("#","")+'" class="jnt-next controls"><a href=""><!-- --></a></li></ul>')}if(c.displayType!="fade"){a(f.dom.contentID).mouseover(function(){if(f.paused==false){o()}}).mouseout(function(){if(f.paused==false){p()}})}if(!c.ajaxFeed){l()}}function i(a){if(c.debugMode){if(window.console&&window.console.log){window.console.log(a)}else{alert(a)}}}function h(){var a=new Date;return a.getTime()}function g(a){var b=0,c;for(c in a){if(a.hasOwnProperty(c))b++}return b}var b=h();var f={position:0,time:0,distance:0,newsArr:{},play:true,paused:false,contentLoaded:false,dom:{contentID:"#ticker-content-"+b,titleID:"#ticker-title-"+b,titleElem:"#ticker-title-"+b+" SPAN",tickerID:"#ticker-"+b,wrapperID:"#ticker-wrapper-"+b,revealID:"#ticker-swipe-"+b,revealElem:"#ticker-swipe-"+b+" SPAN",controlsID:"#ticker-controls-"+b,prevID:"#prev-"+b,nextID:"#next-"+b,playPauseID:"#play-pause-"+b}};if(e!="UL"&&e!="OL"&&c.htmlFeed===true){i("Cannot use <"+e.toLowerCase()+"> type of element for this plugin - must of type <ul> or <ol>");return false}c.direction=="rtl"?c.direction="right":c.direction="left";j();})};a.fn.ticker.defaults={speed:.35,ajaxFeed:false,feedUrl:"",feedType:"xml",displayType:"fade",htmlFeed:true,debugMode:false,controls:false,titleText:"",direction:"ltr",pauseOnItems:3500,fadeInSpeed:600,fadeOutSpeed:300}})(jQuery)
