var playerHTMLBuild='<div class="playingSong"><marquee behavior="scroll" direction="left" scrollamount="1" width="203"><p class="playingSongTitle"></p></marquee></div><div class="controlsFlap"><div id="playerControls" class="ui-widget-header ui-corner-all"><button id="play">Play</button><button id="stop">Stop</button><button id="muteToggle" style="margin-left: 89px; margin-right: 0;">Mute</button></div><div id="scrubber"><div id="bufferProgress"></div><div id="scrubSlider"></div></div><div id="volumeSlider"></div></div><div class="audioPlaylist"></div>';var itsWonderfulLele={title:"It's Wonderful [feat. Lele Cerri]",author:"Bruno Biriaco & Galax Big Band",tagID:"wonderfulLele",number:1,src:"http://media.soundcloud.com/stream/zb3UzBhE9Wre?url=http%3A//api.soundcloud.com/tracks/18454193"};var earlyAutumn={title:"Early Autumn",author:"Bruno Biriaco & Galax Big Band",tagID:"earlyAutumn",number:2,src:"http://media.soundcloud.com/stream/FVPswTxFL4Fu?url=http%3A//api.soundcloud.com/tracks/18453686"};var baisieland={title:"Basieland",author:"Bruno Biriaco & Galax Big Band",tagID:"basieland",number:3,src:"http://media.soundcloud.com/stream/uHBOdXfEjBgY?url=http%3A//api.soundcloud.com/tracks/18453427"};var itsWonderfulJoy={title:"It's Wonderful [feat. Joy Garrison]",author:"Bruno Biriaco & Galax Big Band",tagID:"wonderfulJoy",number:4,src:"http://media.soundcloud.com/stream/7b9ltPxyTZzN?url=http%3A//api.soundcloud.com/tracks/18453986"};var playerTracklist=new Array(itsWonderfulLele,earlyAutumn,baisieland,itsWonderfulJoy);var playerVisible=false;var currentSong;var currentAudioTag;var currentLanguage=(navigator.language)?navigator.language:navigator.userLanguage;var idleMessage;var loadingMessage;var bufferingMessage;var playingMessage;var pausedMessage;var stoppedMessage;var errorMessage;var modalAlertMessage;var refreshPlayerButton;var refreshPageButton;function setupPlayerWithLanguage(language){if(language){switch(language){case'it-it':idleMessage='PRONTO - Seleziona una Canzone dalla Playlist Sottostante o Premi PLAY!'
loadingMessage='IN CARICAMENTO: ';buffering='IN BUFFERING: ';playingMessage='IN RIPRODUZIONE: ';pausedMessage='IN PAUSA: ';stoppedMessage='IN STOP - Seleziona una Canzone dalla Playlist o Premi di nuovo PLAY per Suonare: ';errorMessage='<b>ERRORE PLAYER:</b> Per Cortesia Ricarica!</p>';modalAlertMessage='Errore Durante il Caricamento dei File Audio</p><p><b>Per Cortesia Ricarica il Player o Tutta la Pagina.</b>';refreshPlayerButton='Ricarica Player';refreshPageButton='Ricarica Pagina';break;default:idleMessage='IDLE - Choose a Song from the Playlist Below or Press PLAY!'
loadingMessage='LOADING: ';buffering='BUFFERING: ';playingMessage='PLAYING: ';pausedMessage='PAUSED: ';stoppedMessage='STOPPED: - Choose a Song from the Playlist Below or Press PLAY to Listen Again to: ';errorMessage='<b>PLAYER ERROR:</b> Please Refresh!</p>';modalAlertMessage='An Error Occured during the Audio Loading Operations</p><p><b>Please Refresh the Audio Player or the Whole Page.</b>';refreshPlayerButton='Refresh Player';refreshPageButton='Refresh Page';break;}}}
function setupPlayerUI(){$("#play").button({text:false,icons:{primary:"ui-icon-play"}}).click(function(){var toggleOptions;if($(this).text()==="Play"){toggleOptions={label:"Pause",icons:{primary:"ui-icon-pause"}};if(currentSong&&currentAudioTag){currentAudioTag.play();}else{initAndPlaySong(playerTracklist[0]);}}else{toggleOptions={label:"Play",icons:{primary:"ui-icon-play"}};if(currentSong&&currentAudioTag){currentAudioTag.pause();}}
$(this).button("option",toggleOptions);});$("#stop").button({text:false,icons:{primary:"ui-icon-stop"}}).click(function(){$("#play").button("option",{label:"Play",icons:{primary:"ui-icon-play"}});if(currentSong&&currentAudioTag){currentAudioTag.pause();currentAudioTag.currentTime=0;$("p#"+currentSong.tagID+":hidden").show("bounce","fast");$("p.playingSongTitle").text(stoppedMessage+currentSong.title+" - "+currentSong.author);}});$("div#volumeSlider").slider({range:"min",max:100,value:100,slide:function(event,ui){if(!currentAudioTag.muted){currentAudioTag.volume=(ui.value/100);}}});$("#muteToggle").button({text:false,icons:{primary:"ui-icon-volume-on"}}).click(function(){var toggleOptions;if($(this).text()==='Mute'){if(!currentAudioTag.muted){currentAudioTag.muted=true;toggleOptions={label:'VolumeOn',icons:{primary:"ui-icon-volume-off"}};$("div#volumeSlider").slider({disabled:true});}}else{if(currentAudioTag.muted){currentAudioTag.muted=false;toggleOptions={label:'Mute',icons:{primary:"ui-icon-volume-on"}};$("div#volumeSlider").slider({disabled:false});}}
$(this).button("option",toggleOptions);});$("div#bufferProgress").progressbar({value:0});$("div#scrubSlider").slider({range:"min",max:100,value:0,start:function(event,ui){if(currentSong&&currentAudioTag){if(!currentAudioTag.paused){currentAudioTag.pause();}}},stop:function(event,ui){if(currentSong&&currentAudioTag){if(currentAudioTag.paused){currentAudioTag.currentTime=(ui.value/100)*currentAudioTag.duration;currentAudioTag.play();}}}});$("p.playingSongTitle").text(idleMessage);}
function createPlaylistFromArray(playlistArray){for(var i=0;i<playlistArray.length;i++){$("div.audioPlaylist").append('<p id="'+playlistArray[i].tagID+'" class="playerSong" onclick="playSongWithID(this.id);"">'+playlistArray[i].title+'</p>');}}
function setupPlayerCore(){}
function initAndPlaySong(song){if(song){$(".playerAudioFile").remove();var audioTag=document.createElement('audio');document.getElementById('audioPlayer').appendChild(audioTag);audioTag.setAttribute('id',song.tagID);audioTag.setAttribute('class','playerAudioFile');audioTag.setAttribute('src',song.src);audioTag.addEventListener('loadstart',function(){$("p.playingSongTitle").text(loadingMessage+currentSong.title+" - "+currentSong.author);});audioTag.addEventListener('timeupdate',function(){$("div#scrubSlider").slider({value:(audioTag.currentTime/audioTag.duration)*100});});audioTag.addEventListener('loadedmetadata',function(){audioTag.play();});audioTag.addEventListener('progress',function(){$("div#bufferProgress").progressbar({value:parseInt((audioTag.buffered.end(0)/audioTag.duration)*100,10)});});audioTag.addEventListener('play',function(){$("p#"+currentSong.tagID+":visible").hide("drop","slow");$("p.playingSongTitle").text(playingMessage+currentSong.title+" - "+currentSong.author);$("#play").button("option",{label:"Pause",icons:{primary:"ui-icon-pause"}});});audioTag.addEventListener('pause',function(){$("#play").button("option",{label:"Play",icons:{primary:"ui-icon-play"}});$("p.playingSongTitle").text(pausedMessage+currentSong.title+" - "+currentSong.author);});audioTag.addEventListener('ended',function(){$("#play").button("option",{label:"Play",icons:{primary:"ui-icon-play"}});$("p#"+currentSong.tagID+":hidden").show("bounce","fast");$("p.playingSongTitle").text(stoppedMessage+currentSong.title+" - "+currentSong.author);if(currentSong.number<playerTracklist.length){initAndPlaySong(playerTracklist[(currentSong.number+1)-1]);}else if(currentSong.number==playerTracklist.length){initAndPlaySong(playerTracklist[0]);}});audioTag.addEventListener('error',function(error){$("div.audioPlaylist").html('<div id="playerError" class="ui-widget" style="display: none; margin-bottom: 5px;"><div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> '+errorMessage+'</div></div>');$("div#playerError").show("pulsate","slow");$("div#audioPlayer").append('<div id="playerRefreshAlert"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>'+modalAlertMessage+'</p></div>')
$("div#playerRefreshAlert").dialog({title:"Audio Player Error",modal:true,width:400,resizable:false,position:"center",show:"fold",hide:"explode",buttons:[{text:refreshPlayerButton,click:function(){initAudioPlayer(false,true);$(this).dialog("close");}},{text:refreshPageButton,click:function(){window.location.reload(true);}}]});});currentAudioTag=audioTag;currentSong=song;$("p#"+trackToPlay.tagID+":visible").hide("drop","slow");}}
function playSongWithID(songID){if(currentSong&&currentAudioTag){currentAudioTag.pause();currentAudioTag=null;currentSong=null;$("div.audioPlaylist p:hidden").show("bounce","fast");}
for(var i=0;i<playerTracklist.length;i++){if(playerTracklist[i].tagID==songID){initAndPlaySong(playerTracklist[i]);}}}
function playerVisibilityToggle(){$("div.controlsFlap").mouseenter(function(){if(!playerVisible){$("div#audioPlayer").animate({left:"0px"},700,"easeOutBounce");playerVisible=true;}});$("div#audioPlayer").mouseleave(function(){if(playerVisible){$("div#audioPlayer").delay(1000).animate({left:"-220px"},800,"easeOutBounce");playerVisible=false;}});}
function scrollPlayerWithWindow(){$(window).scroll(function(event){$('div#audioPlayer').css("top",50+($(this).scrollTop()/$(document).height())*100+'%');});}
function initAudioPlayer(autoplay,reset){if(typeof autoplay=='undefined'){autoplay=false;}
if(typeof reset=='undefined'){reset=false;}
if(reset){$("div#audioPlayer").empty();}
$("div#audioPlayer").html(playerHTMLBuild);setupPlayerWithLanguage(currentLanguage);setupPlayerUI();createPlaylistFromArray(playerTracklist);$('div.playingSong marquee').marquee();playerVisibilityToggle();scrollPlayerWithWindow();if(autoplay){initAndPlaySong(playerTracklist[0]);}}
$(document).ready(function(){initAudioPlayer();});
