/*
    jQuery News Ticker is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 2 of the License.
 
    jQuery News Ticker is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

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