$(document).ready(function() {
  	if ($('.rotator').length>0)
	{
		$('.rotator').each(function () {
			$(this).data('field', $(this).attr("id"));
			$(this).data('rotators', $(this).children('.rotation-field').children('.rotate').length-$(this).data('field'));
			$(this).data('index', 0);
			$(this).data('offset', $(this).children('.rotation-field').children('.rotate').width());			
			});
		$('.rotator > .left-arrow').each(function () {
			$(this).click(function() {
				$(this).parent().data('index', $(this).parent().data('index') > 0 ? $(this).parent().data('index')-1: $(this).parent().data('rotators'));
				$(this).siblings('.rotation-field').animate({marginLeft: "-" + $(this).parent().data('offset') * $(this).parent().data('index') + "px"}, "slow");
			})
			});
		$('.rotator > .right-arrow').each(function () {
			$(this).click(function() {
				$(this).parent().data('index', $(this).parent().data('index') < $(this).parent().data('rotators') ? $(this).parent().data('index')+1: 0);
				$(this).siblings('.rotation-field').animate({marginLeft: "-" + $(this).parent().data('offset') * $(this).parent().data('index') + "px"}, "slow");
			})
			});
		$('.rotator.foto-video-rotator > .rotation-field > .rotate > a').each(function () {
			$(this).mouseover(function(){
				$(this).parent().parent().siblings('.rotator-preview:first').children('h4').html($(this).attr('title'));
				$(this).parent().parent().siblings('.rotator-preview:first').attr('href', $(this).attr('id'));
				$(this).parent().parent().siblings('.rotator-preview:first').attr('style', 'background: url(' + $(this).attr('rel') + '/w/610) center center');
				});
			});	
		
		
		function rotateplay() {
				/*alert(""+$('.rotator').data('rotators')+"");*/
				$('.rotator').data('index', $('.rotator').data('index') < $('.rotator').data('rotators') ? $('.rotator').data('index')+1: 0);
				/*$('.rotator').data('index', $('.rotator').data('index') < $('.rotator').data('rotators') ? alert('1'): alert('0'));*/
				$('.big-rotator').children('.rotation-field').animate({marginLeft: "-" + $('.rotator').data('offset') * $('.rotator').data('index') + "px"}, "slow");
			};
		
		var refreshRotate = setInterval(function() {
			rotateplay();
		}, 8000);	
			
	}
	
	$.fn.tabPanel = function ()
	{
		this.each (function () {
			$(this).find("table:gt(1)").hide();
			$(this).find(".button:first").addClass('selected');
			$(this).find('.button').each(function() {
				$(this).click(function () {
					$(this).siblings('.button').removeClass('selected');
					$(this).addClass('selected');
					$('.tabs').find("table:gt(0)").hide();
					$('.tabs').find('table#'+$(this).attr('rel')).show ();
				})
			})
		});
	}
	
	$('.tabs').tabPanel();
	//$('input:radio.star-rate').rating({split: 2});
	
	/*
$("#jquery_jplayer").jPlayer({
			swfPath: '/js/jplayer.2.1.0'
	});
*/

	
	
	$('.playlist-play-button.interactive').click(function () {
		
		var stringf = $(this).attr('rel');
		/*
		var stringtoken = stringf.split('/');
		var token_id = stringtoken[5].split('.');
		var token ='token=true&token_id='+token_id[0];
		*/
		
		//var last_a;
		
		$("#jquery_jplayer").jPlayer("stop");
		$("#jquery_jplayer").jPlayer("clearMedia");
		$("#jquery_jplayer").jPlayer("destroy");
		
		$("#jquery_jplayer").jPlayer({
						ready: function () {
							$(this).jPlayer("setMedia", {
								mp3: stringf
							}).jPlayer("play");
						},
						swfPath: "/js/jplayer.2.1.0",
						solution:"html,flash",
						supplied: "mp3"
					});
			
		/*var request = $.ajax({
				type: 'POST',
				url: '/musica/loadmp3/token',
				//url: '/media/audio/002_Crabs.mp3',
				data : token,
				dataType: "html",
				async:true,
				success: function(response){
					/*
					if(last_a){
						last_a.abort();
					};
					last_a = actual;
					*/
					//alert(response);
					//$("#jquery_jplayer").jPlayer("setFile", stringf);
					//$("#jquery_jplayer").jPlayer("play");
					
					/*$("#jquery_jplayer").jPlayer({
						ready: function () {
							$(this).jPlayer("setMedia", {
								mp3: stringf
							}).jPlayer("play");
						},
						swfPath: "/js/jplayer.2.1.0",
						solution:"html,flash",
						supplied: "mp3"
					});*/
					
					//$("#jquery_jplayer").jPlayer("play");				
				/*}
			});*/	
			
			
		resetButtons ();
		$(this).hide();
		$(this).next().show();
	});
	
	$('.playlist-pause-button.interactive').click(function () {
		
		$("#jquery_jplayer").jPlayer("pause");
		resetButtons ();
		$(this).hide();
		$(this).next().show();
		
		/*
var token ='token=false';
			
			$.ajax({
				type: 'POST',
				url: '/musica/loadmp3/token',
				data : token,
				dataType: "text",
				async:false,
				success: function(response){

				}
			});
*/

	});
	
	$('#search_field').click(function () {
		if ($(this).val() == "Cerca") $(this).val('');
	})
	
	$('#search_field').blur(function () {
		if ($(this).val() == "") $(this).val('Cerca');
	})
	
	resetButtons ();
});

function resetButtons () {
	$('.interactive.playlist-play-button').show();
	$('.interactive.playlist-pause-button').hide();
}

function print_email (address, host)
{
	var _host = host != undefined ? host:   'rollingstonemagazine.it';
	var emailaddress = address + '@' + _host;
	document.write('<span class="gray"><a href="mailto:' + emailaddress + '">'+emailaddress+'</a></span>');
}

// OAS_sitepage = 'www.rollingstonemagazine.it/10/ros';
OAS_sitepage = 'www.rollingstonemagazine.it/10/ros';
OAS_listpos = 'BackGround,Top,VideoBox,PopUp,LittleBox_01';
OAS_query = '?';
OAS_url ='http://adv.ilsole24ore.it/';
OAS_rn = '001234567890'; OAS_rns = '1234567890';
OAS_rn = new String (Math.random()); OAS_rns = OAS_rn.substring (2, 11);
OAS_req = OAS_sitepage+'/1'+OAS_rns+'@'+OAS_listpos;
function OAS_RICH(pos) {
  document.write('<A HREF="'+OAS_url+'1c/'+OAS_req+'!'+pos+OAS_query+'" TARGET="_top" >');
  document.write('<IMG SRC="'+OAS_url+'1/'+OAS_req+'!'+pos+OAS_query+'" BORDER=0></A>');
}

// The following lines will override the  OAS_RICH function using the Open AdStream MJX call.
if (navigator.userAgent.indexOf('Mozilla/3') == -1) {
  document.write('<SC'+'RIPT LANGUAGE=JavaScript SRC="'+OAS_url+'4/'+OAS_req+OAS_query+'"></SCRIPT>');
};

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';5(29.1j)(7($){5($.1L.1J)1I{1t.1H("1K",J,H)}1M(e){};$.n.3=7(i){5(4.Q==0)k 4;5(A I[0]==\'1h\'){5(4.Q>1){8 j=I;k 4.W(7(){$.n.3.y($(4),j)})};$.n.3[I[0]].y(4,$.1T(I).1U(1)||[]);k 4};8 i=$.12({},$.n.3.1s,i||{});$.n.3.K++;4.2a(\'.9-3-1f\').o(\'9-3-1f\').W(7(){8 a,l=$(4);8 b=(4.23||\'21-3\').1v(/\\[|\\]/g,\'Z\').1v(/^\\Z+|\\Z+$/g,\'\');8 c=$(4.1X||1t.1W);8 d=c.6(\'3\');5(!d||d.18!=$.n.3.K)d={z:0,18:$.n.3.K};8 e=d[b];5(e)a=e.6(\'3\');5(e&&a)a.z++;x{a=$.12({},i||{},($.1b?l.1b():($.1S?l.6():s))||{},{z:0,F:[],v:[]});a.w=d.z++;e=$(\'<1R V="9-3-1Q"/>\');l.1P(e);e.o(\'3-15-T-17\');5(l.S(\'R\'))a.m=H;e.1c(a.E=$(\'<P V="3-E"><a 14="\'+a.E+\'">\'+a.1d+\'</a></P>\').1g(7(){$(4).3(\'O\');$(4).o(\'9-3-N\')}).1i(7(){$(4).3(\'u\');$(4).G(\'9-3-N\')}).1l(7(){$(4).3(\'r\')}).6(\'3\',a))};8 f=$(\'<P V="9-3 q-\'+a.w+\'"><a 14="\'+(4.14||4.1p)+\'">\'+4.1p+\'</a></P>\');e.1c(f);5(4.11)f.S(\'11\',4.11);5(4.1r)f.o(4.1r);5(a.1F)a.t=2;5(A a.t==\'1u\'&&a.t>0){8 g=($.n.10?f.10():0)||a.1w;8 h=(a.z%a.t),Y=1y.1z(g/a.t);f.10(Y).1A(\'a\').1B({\'1C-1D\':\'-\'+(h*Y)+\'1E\'})};5(a.m)f.o(\'9-3-1o\');x f.o(\'9-3-1G\').1g(7(){$(4).3(\'1n\');$(4).3(\'D\')}).1i(7(){$(4).3(\'u\');$(4).3(\'C\')}).1l(7(){$(4).3(\'r\')});5(4.L)a.p=f;l.1q();l.1N(7(){$(4).3(\'r\')});f.6(\'3.l\',l.6(\'3.9\',f));a.F[a.F.Q]=f[0];a.v[a.v.Q]=l[0];a.q=d[b]=e;a.1O=c;l.6(\'3\',a);e.6(\'3\',a);f.6(\'3\',a);c.6(\'3\',d)});$(\'.3-15-T-17\').3(\'u\').G(\'3-15-T-17\');k 4};$.12($.n.3,{K:0,D:7(){8 a=4.6(\'3\');5(!a)k 4;5(!a.D)k 4;8 b=$(4).6(\'3.l\')||$(4.U==\'13\'?4:s);5(a.D)a.D.y(b[0],[b.M(),$(\'a\',b.6(\'3.9\'))[0]])},C:7(){8 a=4.6(\'3\');5(!a)k 4;5(!a.C)k 4;8 b=$(4).6(\'3.l\')||$(4.U==\'13\'?4:s);5(a.C)a.C.y(b[0],[b.M(),$(\'a\',b.6(\'3.9\'))[0]])},1n:7(){8 a=4.6(\'3\');5(!a)k 4;5(a.m)k;4.3(\'O\');4.1a().19().X(\'.q-\'+a.w).o(\'9-3-N\')},O:7(){8 a=4.6(\'3\');5(!a)k 4;5(a.m)k;a.q.1V().X(\'.q-\'+a.w).G(\'9-3-1k\').G(\'9-3-N\')},u:7(){8 a=4.6(\'3\');5(!a)k 4;4.3(\'O\');5(a.p){a.p.6(\'3.l\').S(\'L\',\'L\');a.p.1a().19().X(\'.q-\'+a.w).o(\'9-3-1k\')}x $(a.v).1m(\'L\');a.E[a.m||a.1Y?\'1q\':\'1Z\']();4.20()[a.m?\'o\':\'G\'](\'9-3-1o\')},r:7(a,b){8 c=4.6(\'3\');5(!c)k 4;5(c.m)k;c.p=s;5(A a!=\'B\'){5(A a==\'1u\')k $(c.F[a]).3(\'r\',B,b);5(A a==\'1h\')$.W(c.F,7(){5($(4).6(\'3.l\').M()==a)$(4).3(\'r\',B,b)})}x c.p=4[0].U==\'13\'?4.6(\'3.9\'):(4.22(\'.q-\'+c.w)?4:s);4.6(\'3\',c);4.3(\'u\');8 d=$(c.p?c.p.6(\'3.l\'):s);5((b||b==B)&&c.1e)c.1e.y(d[0],[d.M(),$(\'a\',c.p)[0]])},m:7(a,b){8 c=4.6(\'3\');5(!c)k 4;c.m=a||a==B?H:J;5(b)$(c.v).S("R","R");x $(c.v).1m("R");4.6(\'3\',c);4.3(\'u\')},1x:7(){4.3(\'m\',H,H)},24:7(){4.3(\'m\',J,J)}});$.n.3.1s={E:\'25 26\',1d:\'\',t:0,1w:16};$(7(){$(\'l[27=28].9\').3()})})(1j);',62,135,'|||rating|this|if|data|function|var|star|||||||||||return|input|readOnly|fn|addClass|current|rater|select|null|split|draw|inputs|serial|else|apply|count|typeof|undefined|blur|focus|cancel|stars|removeClass|true|arguments|false|calls|checked|val|hover|drain|div|length|disabled|attr|be|tagName|class|each|filter|spw|_|width|id|extend|INPUT|title|to||drawn|call|andSelf|prevAll|metadata|append|cancelValue|callback|applied|mouseover|string|mouseout|jQuery|on|click|removeAttr|fill|readonly|value|hide|className|options|document|number|replace|starWidth|disable|Math|floor|find|css|margin|left|px|half|live|execCommand|try|msie|BackgroundImageCache|browser|catch|change|context|before|control|span|meta|makeArray|slice|children|body|form|required|show|siblings|unnamed|is|name|enable|Cancel|Rating|type|radio|window|not'.split('|'),0,{}))
