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