(function($){
	$.fn.plaxml=function(options){
		var settings = $.extend({
			file:	'',
			timer:	30,
			inter:	'',
			cont:	''
		}, options);
		return this.each(function() {
			var $this = $(this);
			var $set = settings;
			var Init = function(){
				var div = $('<div />').attr({'id':'lbl_cont','name':'lbl_cont'}).appendTo($this);
				$set.cont = $('<div />').attr({'id':'OnairSong','name':'OnairSong','class':'box_grigio_open'}).css({'padding':'10px','width':'496px','text-align':'left','height':'30px'}).appendTo(div);
				CS();
				$set.inter = setInterval(function() { CS(); }, $set.timer+'000');
			}
			var CS = function(){
				$.ajax({
					type: "GET",
					cache: false,
					url: '/player/xml/'+$set.file,
					dataType: "xml",
					success: PXml,
					error: function(XMLHttpRequest, textStatus, errorThrown){this;}
				});
			}
			var PC = function(str){return str.toLowerCase().replace(/\w+/g, function(s){return s.charAt(0).toUpperCase() + s.substr(1);});}
			var PXml = function(xml){
				$(xml).find('item').each(function(){
					if ($(this).attr('sequence') == 'present') 
						if($(this).find('Class').text() == 'Music'){
							var title 	= $('<div />').attr({'class':'testo_b0'}).css({'color':'#ED1C24','font-weight':'bold'}).html('Song On Air').appendTo($set.cont.empty());
							var song	= $('<div />').attr({'class':'testo_b'}).appendTo($set.cont)
							var span	= $('<span />').css({'font-weight':'bold'}).html(PC($(this).find('artist').text())).appendTo(song);
							var span	= $('<span />').html(' - '+PC($(this).find('title').text())).appendTo(song);
							if($this.css('display') == 'none') $this.show('fast');
						}
						else if($(this).find('title').text().indexOf('RTL 102.5 Giornale Orario') != -1){
							var now    = new Date();
							var title 	= $('<div />').attr({'class':'testo_b0'}).css({'color':'#ED1C24','font-weight':'bold'}).html('Giornale Orario').appendTo($set.cont.empty());
							var song	= $('<div />').attr({'class':'testo_b'}).appendTo($set.cont);
							var span	= $('<span />').css({'font-weight':'bold'}).html('Edizione delle '+now.getHours()+':00').appendTo(song);
							if($this.css('display') == 'none') $this.show('fast');
						}
						else{
							$this.hide('fast');
						}
				});
			}
			Init();
			window.onbeforeunload = function(){clearInterval($set.inter);}
		});
	};
})(jQuery);