﻿
var NextAlbumHtml;

var closeButtonHtml = '<div class="albumCloseButton"><a href="javascript:CloseAlbumInfo();">X</a></div>';

function CloseAlbumInfo() {
    $('div.MusicContent').fadeOut();
}

function FinishShowAlbumInfo() {

    var musicContent = 'No Content Found';

    try {
        musicContent = NextAlbumHtml
    }
    catch (ex) { }

    $('div.MusicContent').html(musicContent);
    $('div.MusicContent').fadeIn();
}


function ShowAlbumInfo() {
    try {

    $('div.callToAction_bgMask').hide();
    $('div.callToAction').hide();

    NextAlbumHtml = $(this).parent().parent().html();
    
    $('div.MusicContent').hide();

    var musicContent = NextAlbumHtml;

    $('div.MusicContent').html(musicContent + closeButtonHtml);
    $('div.MusicContent').fadeIn();

    
    return false;
   }
catch(ex)
{
alert(ex);

} 
}





function OpenMusicPlayer(eventObject) {


    return SetSongPlay($(this), 'td.cell_play');
    
//    $('td.cell_play').removeClass('showPlayer');
//    $(this).parent().addClass('showPlayer');

//    currentSelectedSongLink = $(this);
//    niftyplayer(musicPlayer).loadAndPlay(currentSelectedSongLink.attr("href"));
//    onPlayEvent();
//    
//    niftyplayer(musicPlayer).registerEvent('onPlay', 'onPlayEvent()');
//    niftyplayer(musicPlayer).registerEvent('onPause', 'onPauseEvent()');
//    niftyplayer(musicPlayer).registerEvent('onStop', 'onStopEvent()');
    
//    $('div.mini_player div.playButton').addClass('pause');
//    $('div.mini_player div.status').text('playing');
}

function albumOn(eventObject) {
    $(this).parent().parent().addClass('hovered');
}

function albumOff(eventObject) {
    $(this).parent().parent().removeClass('hovered');
}


function hiOn(eventObject) {
    $(this).addClass('hovered');
}

function hiOff(eventObject) {
    $(this).removeClass('hovered');
}


function ShowPlayingStatus() {
    currentSelectedSongLink.text('Playing...');
}
function ShowLoadingStatus() {
    currentSelectedSongLink.text('Loading...');
}
function ShowDoneStatus() {
    currentSelectedSongLink.text('Play');
}

function InitMusic() {


    //musicPlayer = niftyplayer('niftyPlayer1');

    //$('div.album_image a').hover(albumOn, albumOff);
    $('div.MusicList div.album_image a').live('click',ShowAlbumInfo);
    $('div.MusicContent a.play').live('click', OpenMusicPlayer);


//    niftyplayer(musicPlayer).registerEvent('onPlay', 'onPlayEvent()');
//    niftyplayer(musicPlayer).registerEvent('onPause', 'onPauseEvent()');
//    niftyplayer(musicPlayer).registerEvent('onStop', 'onStopEvent()');


//    niftyplayer('niftyPlayer1').registerEvent('onBufferingStarted', 'ShowLoadStatus()');
//    niftyplayer('niftyPlayer1').registerEvent('onPlay', 'ShowPlayStatus()');
//    
    
    
    //niftyplayer('niftyPlayer1').registerEvent('onPlay', 'alert("playing!")');
    
//    niftyplayer(musicPlayer).registerEvent('onBufferingComplete', 'ShowPlayingStatus()');
    //niftyplayer(musicPlayer).registerEvent('onStop', 'ShowDoneStatus()');
    
    try {    
        $('div.MusicContent div.album_listing table tbody tr').livequery(function(){ 
        // use the helper function hover to bind a mouseover and mouseout event 
            $(this) 
                .hover(function() { 
                    $(this).addClass('hovered'); 
                }, function() { 
                    $(this).removeClass('hovered'); 
                }); 
        }, function() { 
            // unbind the mouseover and mouseout events 
            $(this) 
                .unbind('mouseover') 
                .unbind('mouseout'); 
        }); 
    }
    catch(ex) {
        alert(ex);
    }

}




$(document).ready(function() {
    InitMusic();
});