
var myPlayList = [
	{name:"Intervista radiofonica",mp3:"templates/frontend/mp3/la_nuova_parola.mp3",ogg:"templates/frontend/mp3/la_nuova_parola.ogg"},
/* 	{name:"Tempered Song",mp3:"http://www.miaowmusic.com/mp3/Miaow-01-Tempered-song.mp3",ogg:"http://www.miaowmusic.com/ogg/Miaow-01-Tempered-song.ogg"},*/
];

var playItem = 0;



$(document).ready(function(){

/* 	$('a.gallery').lightBox({fixedNavigation:true});
	$('a.facebox').facebox({
		loadingImage: _IMAGES_URI+'/facebox/loading.gif',
		closeImage: _IMAGES_URI+'/facebox/closelabel.gif'
	});
 */
/*
	$('.slideshow').accessNews({
		speed : "normal",
		slideBy : 1
	});
*/

	if(_STILE == 'normale'){
	    var cover = $('<div></div>');
	    cover.css({
		    'width': '100%',
		    'height': $('body').height()+'px',
		    'position': 'absolute',
		    'top': '0px',
		    'left': '0px',
		    'opacity': '.01',
		    'filter': 'alpha(opacity=1)',
		    'z-index': '100',
		    'display': 'none'
	    });
	    $('body').prepend(cover);

	    $('#styles ul').css({
		    'display': 'none',
		    'z-index': '101'
	    });
	    /*
	    $('#langs ul').css({
		    'display': 'none',
		    'z-index': '101'
	    });
	    */ 
	    $('#styles a').unbind("click").click(function(){
	    	$('#styles ul').toggle('normal', function(){
	    		cover.css('display', $('#styles ul').css('display'))
	    	});
	    }); 
	    
	    /*
	    $('#langs').click(function(){
		    $('#langs ul').toggle('normal', function(){
			    cover.css('display', $('#langs ul').css('display'))
		    });
	    });
	    */
	}
	
	
	cover.click(function(){
		$('#styles ul').hide('normal');
		$('#langs ul').hide('normal');
		$(this).hide();
	});
	
	$('#slideshow').goslide({timeout: 5000});
	$('.rounded').corners("8px bottom-left bottom-right");
	$("a.zoom").fancybox();
	$("a.gallery").fancybox();	
	
	
	$('.marque').vTicker({
           speed: 500,
           pause: 2500,
           showItems: 3,
           animation: ' ',
           mousePause: true
          });
	

	$("#jquery_jplayer").jPlayer({
		ready: function () {
			displayPlayList();
			playListInit(true); // Parameter is a boolean for autoplay.
		},
		nativeSupport: true,
		oggSupport: true,
		customCssIds: false
	})
	.jPlayer("onSoundComplete", function() {
		playListNext();
	});

	$("#jplayer_previous").click( function() {
		playListPrev();
		return false;
	});
	$("#jplayer_next").click( function() {
		playListNext();
		return false;
	});	
	
});


// -- Funzioni creazione playlist jPlayer ----------------------------------- //

function displayPlayList() {
	$("#jplayer_playlist").append('<ul>');
	for (i=0; i < myPlayList.length; i++) {
		$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
		$("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
			var index = $(this).data("index");
			if (playItem != index) {
				playListChange( index );
			} else {
				$("#jquery_jplayer").jPlayer("play");
			}
		});
	}
}

function playListInit(autoplay) {
	if(autoplay) {
		playListChange( playItem );
	} else {
		playListConfig( playItem );
	}
}

function playListConfig( index ) {
	$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current");
	$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current");
	playItem = index;
	$("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
}

function playListChange( index ) {
	playListConfig( index );
	$("#jquery_jplayer").jPlayer("play");
}

function playListNext() {
	var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
	playListChange( index );
}

function playListPrev() {
	var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
	playListChange( index );
}

