(function($){$.fn.player=function(settings){var config={'playerUrl':'http://beta.jiwa.fm/res/widget/DesktopPlayer.swf','trackInfosUrl':'/ajax/tools/jiwatrackdetail/id/','swfDiv':'jwPlayerDiv','framePlayer':'am_frmOhlin','frameContent':'am_frmContent','index':0,'total':0,'loop':0,'volume':1,'shuffle':0,'mute':0,'playlist':[],'tracks':[],'flashvars':{engineReadyHandler:"player.engineReadyHandler",engineClearQueueHandler:"player.engineClearQueueHandler",engineEndQueueHandler:"player.engineEndQueueHandler",engineLoadingTrackHandler:"player.engineLoadingTrackHandler",enginePlayTrackHandler:"player.enginePlayTrackHandler",enginePauseHandler:"player.enginePauseHandler",engineResumeHandler:"player.engineResumeHandler",engineCompletePlayHandler:"player.engineCompletePlayHandler",engineProgressHandler:"player.engineProgressHandler",engineLoadProgressHandler:"player.engineLoadingTrackHandler",log:"player.amTrace"},'params':{allowscriptaccess:"always"},'attributes':{}};if(settings){config=$.extend(config,settings);}
var length=config.playlist.length;if(length>0){config.total=(length-1);}
var _isPlaying=0;var _isTrackLoaded=0;var _locked=0;var _isSlideLocked=0;var _smartCheckInterval=500;var _smartCheckInit=0;var _smartCheckObj=null;var _smartCheckMinTime=2;var _engine=null;var $this=$(this);swfobject.embedSWF(config.playerUrl,config.swfDiv,"1","1","9.0.0","/flash/expressinstall.swf",config.flashvars,config.params,config.attributes);function resizePlayer()
{}
function changeVolume($value)
{var goodFrame=top.frames[config.frameContent];if(goodFrame){$("#ohlin_slider1",goodFrame.document).removeClass('selected');$("#ohlin_slider2",goodFrame.document).removeClass('selected');$("#ohlin_slider3",goodFrame.document).removeClass('selected');$("#ohlin_slider4",goodFrame.document).removeClass('selected');$("#ohlin_slider5",goodFrame.document).removeClass('selected');switch($value){case 0.2:$("#ohlin_slider1",goodFrame.document).addClass('selected');break;case 0.4:$("#ohlin_slider1",goodFrame.document).addClass('selected');$("#ohlin_slider2",goodFrame.document).addClass('selected');break;case 0.5:$("#ohlin_slider1",goodFrame.document).addClass('selected');$("#ohlin_slider2",goodFrame.document).addClass('selected');$("#ohlin_slider3",goodFrame.document).addClass('selected');break;case 0.8:$("#ohlin_slider1",goodFrame.document).addClass('selected');$("#ohlin_slider2",goodFrame.document).addClass('selected');$("#ohlin_slider3",goodFrame.document).addClass('selected');$("#ohlin_slider4",goodFrame.document).addClass('selected');break;case 1:$("#ohlin_slider1",goodFrame.document).addClass('selected');$("#ohlin_slider2",goodFrame.document).addClass('selected');$("#ohlin_slider3",goodFrame.document).addClass('selected');$("#ohlin_slider4",goodFrame.document).addClass('selected');$("#ohlin_slider5",goodFrame.document).addClass('selected');break;}}}
return{getInstance:function()
{return $this;},getConfig:function()
{return config;},getFramePlayer:function()
{return config.framePlayer;},getFrameContent:function()
{return config.frameContent;},setTotal:function(i)
{config.total=i;return;},getTotal:function()
{return config.total;},setPosition:function(i)
{config.index=i;return;},resetPosition:function()
{return this.setPosition(0);},getPosition:function()
{return config.index;},getNextPosition:function()
{if((config.index+1)>config.total){return-1;}
return(config.index+1);},getPrevPosition:function()
{if((config.index-1)==-1||(config.index-1)<0){return-1;}
return(config.index-1);},setPlaying:function(i)
{_isPlaying=i;},isPlaying:function()
{return _isPlaying;},setTrackLoaded:function(i)
{_isTrackLoaded=i;},isTrackLoaded:function()
{return _isTrackLoaded;},setLocked:function(i)
{_locked=i;},isLocked:function()
{return _locked;},setEngine:function(engine)
{_engine=engine;},getEngine:function()
{return _engine;},setPlaylist:function(playlist)
{config.playlist=playlist;config.total=(playlist.length-1);this.resetPosition();this.setPlaying(0);this.setTrackLoaded(0);return;},getPlaylist:function()
{return config.playlist;},hasPlaylist:function()
{return config.playlist.length>0;},getItemAt:function(indice)
{return config.playlist[indice];},getCurrentItem:function()
{var indice=this.getPosition();return config.playlist[indice];},getCurrentItemArtistId:function()
{var item=this.getCurrentItem();return item.artistId;},getCurrentItemTrackId:function()
{var item=this.getCurrentItem();return item.id;},getCurrentItemMediaId:function()
{var item=this.getCurrentItem();return item.id_media;},getNextTrack:function()
{return this.getNextPosition();},getPrevTrack:function()
{return this.getPrevPosition();},playNextTrack:function()
{var nextPos=this.getNextTrack();if(nextPos==-1&&this.getLoop()==1){nextPos=0;}else if(nextPos==-1){this.displayMsg('Pas de track suivante');this.displayDialog('Pas de track suivante','');this.displayTime('');this.hideLoading();this.hideEffect();return;}
var item=this.getItemAt(nextPos);this.loadData(item.id_jiwa,nextPos);},playPrevTrack:function()
{var prevPos=this.getPrevTrack();if(prevPos==-1&&this.getLoop()==1){prevPos=this.getTotal();}else if(prevPos==-1){this.displayMsg('Pas de track précédente');this.displayDialog('Pas de track précédente','');this.displayTime('');this.hideLoading();this.hideEffect();return;}
var item=this.getItemAt(prevPos);this.loadData(item.id_jiwa,prevPos);},playPause:function()
{if(!this.hasPlaylist()){this.displayMsg('Cette chanson est indisponible');this.displayDialog('Cette chanson est indisponible, passez à la suivante','');this.displayTime('');this.hideLoading();this.hideEffect();return;}
if(this.isPlaying()==0)
{if(!this.isTrackLoaded()){var indice=this.getPosition();var item=this.getItemAt(indice);this.loadData(item.id_jiwa,indice);}else{this.setPlaying(1);this.resume();}}else{this.setPlaying(0);this.pause();}
this.refreshPlayPause();},refreshPlayPause:function()
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){if(this.isPlaying()==0)
{$('button#ohlin_playpause',goodFrame.document).css({"background":"transparent url(/images/ohlin/btn_play.gif) no-repeat center top"});this.hideEffect();}else{$('button#ohlin_playpause',goodFrame.document).css({"background":"transparent url(/images/ohlin/btn_pause.gif) no-repeat center top"});this.displayEffect();}}},resume:function()
{var engine=this.getEngine();if(engine!=null){engine.jwResume();}else{}},pause:function()
{var engine=this.getEngine();if(engine!=null){engine.jwPause();}else{}},setLoop:function(i)
{config.loop=i;},getLoop:function()
{return config.loop;},toggleLoop:function()
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){if(this.getLoop()==0){this.setLoop(1);$('button#ohlin_toggles_loop',goodFrame.document).css({"background":"transparent url(/images/ohlin/btn_loopOn.gif) no-repeat center top"});}else{this.setLoop(0);$('button#ohlin_toggles_loop',goodFrame.document).css({"background":"transparent url(/images/ohlin/btn_loopOff.gif) no-repeat center top"});}}},setShuffle:function(i)
{config.shuffle=i;},getShuffle:function()
{return config.shuffle;},toggleShuffle:function()
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){if(this.getShuffle()==0){this.setShuffle(1);$('button#ohlin_toggles_random',goodFrame.document).css({"background":"transparent url(/images/ohlin/btn_randomOn.gif) no-repeat center top"});}else{this.setShuffle(0);$('button#ohlin_toggles_random',goodFrame.document).css({"background":"transparent url(/images/ohlin/btn_randomOff.gif) no-repeat center top"});}}},loadData:function(id_jiwa,nextindice)
{if(this.isLocked()==1){this.displayLoading();return;}
this.setLocked(1);this.displayMsg('');this.displayTime('');this.displayLoading();this.smartCheckStop();var $this=this;$.ajax({type:"GET",url:config.trackInfosUrl+id_jiwa,cache:false,dataType:"json",success:function(resp){if(resp.success==false){var msg=resp.error;if(msg=='ERR__TRACK_NOT_FOUND'){msg='Cette chanson est indisponible, passez à la suivante';}
if($this.hasPlaylist()){if($this.isPlaying()==1)
{$this.pause();}}
$this.displayMsg(msg);$this.displayDialog(msg);$this.displayTime('');$this.hideLoading();$this.hideEffect();$this.setLocked(0);return false;}else{var id=id_jiwa;var options={play:true};$this.getEngine().jwAddTracks([resp.track],options);$this.setPosition(nextindice);$this.setTrackLoaded(1);$this.setPlaying(1);$this.refreshPlayPause();$this.setLocked(0);}},error:function(error){$this.displayError('Connexion échouée');$this.displayDialog('Connexion échouée','');$this.setLocked(0);return false;}});},displayError:function(msg)
{this.hideLoading();this.hideEffect();var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){$('div#ohlin_trackCtxt',goodFrame.document).html(msg);}},displayMsg:function(msg)
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){$('div#ohlin_trackCtxt',goodFrame.document).html(msg);}},displayDialog:function(msg,dialogtitle)
{if(typeof(dialogtitle)=="undefined"||dialogtitle==''){var dialogtitle='Player';}
var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){goodFrame.dialogBox(msg,dialogtitle);}},displayTime:function(msg)
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){$('div#ohlin_trackTime',goodFrame.document).html(msg);}},displayEffect:function()
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){$('div#am_ohlingGfxEq',goodFrame.document).show();}},hideEffect:function()
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){$('div#am_ohlingGfxEq',goodFrame.document).hide();}},displayLoading:function()
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){$('div#ohlin_progress',goodFrame.document).show();}},hideLoading:function()
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){$('div#ohlin_progress',goodFrame.document).hide();}},toggleContextual:function()
{if(_isSlideLocked==1){return;}
_isSlideLocked=1;var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){$('div#am_ohlinPlayerContext',goodFrame.document).slideToggle(1300,function(){_isSlideLocked=0;});}},contextualScript:function(artistId,trackId)
{$this=this;var goodFrame=top.frames[$this.getFrameContent()];if(goodFrame){var urlCoulisses='/player/infoscoulisses/artistId/'+artistId;$('#tabInfosCoulisses',goodFrame.document).attr('href',urlCoulisses);var urlInfos='/player/informations/artistId/'+artistId+'/trackId/'+trackId;$('#tabInformations',goodFrame.document).attr('href',urlInfos);this.contextualInfosLoad(urlCoulisses);var loadingInfosCoulisses='<div style="margin:0 auto;"><img src="/images/loading.gif"/></div>';$("#InfosCoulissesTab_player a",goodFrame.document).tabs().click(function(){t=$(this);var urlAjax=t.attr("href");$('#InfosCoulissesContainer_player',goodFrame.document).html(loadingInfosCoulisses);$.ajax({type:"POST",url:urlAjax,cache:false,success:function(msg){$('#InfosCoulissesContainer_player',goodFrame.document).html(msg);$('.am_BlocContentTabsPaneInlinePicto a',goodFrame.document).click(function(){var url=$(this).attr("href");goodFrame.location.href=url;return false;});$('.am_innerBloc a',goodFrame.document).click(function(){var url=$(this).attr("href");goodFrame.location.href=url;return false;});}});$("#InfosCoulissesTab_player a",goodFrame.document).each(function(){if($(this).attr('title')==t.attr('title'))
{$(this).parent().addClass('selected');}
else
{$(this).parent().removeClass('selected');}});});$("#firstInfosCoulisses_player a",goodFrame.document).click();}},contextualInfosLoad:function(urlAjax){$this=this;var loadingInfosCoulisses='<div style="margin:0 auto;"><img src="/images/loading.gif"/></div>';var goodFrame=top.frames[$this.getFrameContent()];if(goodFrame){$('#InfosCoulissesContainer_player',goodFrame.document).html(loadingInfosCoulisses);$.ajax({type:"POST",url:urlAjax,cache:false,success:function(msg){$('#InfosCoulissesContainer_player',goodFrame.document).html(msg);$('.am_BlocContentTabsPaneInlinePicto a',goodFrame.document).click(function(){var url=$(this).attr("href");goodFrame.location.href=url;return false;});$('.am_innerBloc a',goodFrame.document).click(function(){var url=$(this).attr("href");goodFrame.location.href=url;return false;});$("#InfosCoulissesTab_player a",goodFrame.document).each(function(){$(this).parent().removeClass('selected');});$("#InfosCoulissesTab_player a:first",goodFrame.document).parent().addClass('selected');}});}},refreshContextualInfos:function()
{var artistId=this.getCurrentItemArtistId();var trackId=this.getCurrentItemTrackId();this.contextualScript(artistId,trackId);},engineReadyHandler:function()
{this.setEngine(document.getElementById(config.swfDiv));},engineCompletePlayHandler:function()
{this.amTrace('engineCompletePlayHandler');},enginePauseHandler:function()
{this.amTrace('enginePauseHandler');},engineResumeHandler:function()
{this.amTrace('engineResumeHandler');},engineLoadingTrackHandler:function(track,currentIndex,previousTracks,nextTracks)
{this.displayMsg('');this.displayTime('');this.hideEffect();this.displayLoading();},enginePlayTrackHandler:function(track,currentIndex,previousTracks,nextTracks)
{this.hideLoading();var item=this.getCurrentItem();this.displayMsg(item.artistName+" - "+item.title);},engineProgressHandler:function(currentTimeInt,maxTimeInt,currentTimeStr,maxTimeStr)
{this.refreshPlayPause();this.hideLoading();var item=this.getCurrentItem();this.displayMsg(item.artistName+" - "+item.title);this.displayTime(currentTimeStr+" / "+maxTimeStr);if((maxTimeInt-currentTimeInt)<=_smartCheckMinTime){if(_smartCheckInit==0){this.smartCheckStart();}}},engineEndQueueHandler:function()
{smartCheckStop();$this.playNextTrack();},engineClearQueueHandler:function()
{},engineRemoveTracksHandler:function()
{},setMute:function()
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){if(config.mute==0){config.mute=1;this.getEngine().jwSetVolume(0);$('button#ohlin_slider',goodFrame.document).removeClass('selected');return 0;}else{config.mute=0;this.getEngine().jwSetVolume(config.volume);$('button#ohlin_slider',goodFrame.document).addClass('selected');return config.volume;}}},setVolume:function(volume)
{var goodFrame=top.frames[this.getFrameContent()];if(goodFrame){config.volume=volume;config.mute=0;$('button#ohlin_slider',goodFrame.document).addClass('selected');this.getEngine().jwSetVolume(volume);}
return config.volume;},getVolume:function()
{return config.volume;},amTrace:function(msg)
{},smartCheckInit:function()
{},smartCheckStart:function()
{_smartCheckInit=1;this.smartCheckNext();},smartCheckStop:function()
{_smartCheckInit=0;},smartCheckNext:function()
{this.smartCheckStop();this.playNextTrack();},initScript:function()
{var $this=this;var goodFrame=top.frames[this.getFrameContent()];var dollar_goodFrame=top.frames[$this.getFrameContent()];var am_goodFrame=top.frames['am_frmContent'];if(goodFrame){$('button#ohlin_playpause',goodFrame.document).bind('click',function(event){event.preventDefault();$this.playPause();return false;});$('#ohlin_prev',goodFrame.document).bind('click',function(event){event.preventDefault();$this.playPrevTrack();return false;});$('#ohlin_next',goodFrame.document).bind('click',function(event){event.preventDefault();$this.playNextTrack();return false;});$('#ohlin_toggles_loop',goodFrame.document).bind('click',function(event){event.preventDefault();$this.toggleLoop();return false;});$('#ohlin_toggles_random',goodFrame.document).bind('click',function(event){event.preventDefault();$this.toggleShuffle();return false;});$('button#ohlin_slider',goodFrame.document).click(function(event){event.preventDefault();changeVolume($this.setMute());return false;});$('button#ohlin_slider1',goodFrame.document).click(function(event){event.preventDefault();changeVolume(0.2);$this.setVolume(0.2);return false;});$('button#ohlin_slider2',goodFrame.document).click(function(event){event.preventDefault();changeVolume(0.4);$this.setVolume(0.4);return false;});$('button#ohlin_slider3',goodFrame.document).click(function(event){event.preventDefault();changeVolume(0.5);$this.setVolume(0.5);return false;});$('button#ohlin_slider4',goodFrame.document).click(function(event){event.preventDefault();changeVolume(0.8);$this.setVolume(0.8);return false;});$('button#ohlin_slider5',goodFrame.document).click(function(event){event.preventDefault();changeVolume(1);$this.setVolume(1);return false;});}
if(am_goodFrame){}
if(goodFrame){changeVolume(this.getVolume());if(config.mute==0){changeVolume(this.getVolume());$('button#ohlin_slider',goodFrame.document).addClass('selected');}
$('#am_ohlinPlayerContext-close',goodFrame.document).bind('click',function(event){event.preventDefault();$this.toggleContextual();return false;});$("#player-ctx-moreInfo",goodFrame.document).click(function(event){event.preventDefault();if(!$this.hasPlaylist()){$this.displayMsg('Pas de musique');return false;}
$this.toggleContextual();$this.refreshContextualInfos();return false;});$("#am_ohlinPlayerContext-refresh",goodFrame.document).click(function(event){event.preventDefault();$this.refreshContextualInfos();return false;});$("#player-ctx-ficheArtiste",goodFrame.document).click(function(event){event.preventDefault();if(!$this.hasPlaylist()){$this.displayMsg('Pas de musique');return false;}
var artistId=$this.getCurrentItemArtistId();var url='/artiste/'+artistId;var child_goodFrame=top.frames[$this.getFrameContent()];if(child_goodFrame){child_goodFrame.location.href=url;}
return false;});$("#ohlin_buy",goodFrame.document).click(function(event){event.preventDefault();if(!$this.hasPlaylist()){$this.displayMsg('Pas de musique');return false;}
var trackId=$this.getCurrentItemTrackId();var url='/comparateur/product/type/2/id/'+trackId;var child_goodFrame=top.frames[$this.getFrameContent()];if(child_goodFrame){child_goodFrame.location.href=url;}
return false;});$("#ohlin_AddToPlaylist",goodFrame.document).click(function(event){event.preventDefault();if(!$this.hasPlaylist()){$this.displayMsg('Pas de musique');return false;}
var mediaId=$this.getCurrentItemMediaId();var urlAjax='/playlist/membre-add-media-to-my-playlist/media/'+mediaId;var child_goodFrame=top.frames['am_frmContent'];if(child_goodFrame){child_goodFrame.dialogAjaxCall(urlAjax,'Ajouter à ma playlist ');}
return false;});$this.displayMsg('J\'écoute ici toute la musique que j\'aime');$("#am_ohlinPlayerContainer",goodFrame.document).show();}}}}})(jQuery);