// var playItem = 0;
// var ready = 0;
//
// var myPlayList = [
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/c5393716a8b0dd313b714ed27a7fb5c7"},
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/d2b294f7b2605f7148fa0b782434bf08"},
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/0c3fd4713c8d908947dff2a54d5f73b4"},
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/a0333113c5f29ca230f0bf8a4c4d8c63"},
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/d386b7b0a7482dd57065f76c5b94e82a"},
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/47dce2e7a0b5f824b92d6129efb082e2"},
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/16ed16a85f69b9ffa890221c9b3a8b22"},
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/24c22a206c2a3ac863dfa55beb9cdf7c"},
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/a7214187c1f7ae8ae89867dad8c39176"},
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/dd43c2efe0c1780b5dfda2b88b7c7513"},
//     {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/e87e47eff34a4102dd809de2a946f200"}
// ];
//
// function displayPlayList() {
//     for (i=0; i < myPlayList.length; i++) {
//         //$("#playlist_list ul").append("<li id='playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
//         $("#playlist-item-"+i).data( "index", i ).hover(
//             function() {
//                 if (playItem != $(this).data("index")) {
//                     $(this).addClass("playlist_hover");
//                 }
//             },
//             function() {
//                 $(this).removeClass("playlist_hover");
//             }
//         ).click( function() {
//             var index = $(this).data("index");
//             if (playItem != index) {
//                 playListChange( index );
//             }
//         });
//     }
// }
//
// function playListInit(autoplay) {
//     if(ready == 0) return;
//
//     if(autoplay) {
//         playListChange(playItem);
//     } else {
//         playListConfig(playItem);
//     }
// }
//
// function playListConfig( index ) {
//     $("#playlist-item-"+playItem).removeClass("playlist-current");
//     $("#playlist-item-"+index).addClass("playlist-current");
//     playItem = index;
//     $("#jquery_jplayer_widget").setFile(myPlayList[playItem].t);
// }
//
// function playListChange( index ) {
//     playListConfig( index );
//     $("#jquery_jplayer_widget").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 );
// }
//
// function BindWidget()
// {
//     $("div#jquery_jplayer_widget").jPlayer({
//         ready: function() {
//                 displayPlayList();
//                 playListInit(false); // Parameter is a boolean for autoplay.
//                 ready = 1;
//         },
//         volume: 100,
//         swfPath:"/system/application/assets/swf"
//     })
//     .jPlayerId("play", "play")
//     .jPlayerId("pause", "pause")
//     .jPlayerId("stop", "stop")
//     .jPlayerId("loadBar", "load-bar")
//     .jPlayerId("playBar", "play-bar")
//     .jPlayerId("volumeMin", "volume-min")
//     .jPlayerId("volumeMax", "volume-max")
//     .onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
//         var myPlayedTime = new Date(playedTime);
//         var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" + myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
//         var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" + myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
//         $("#play-time").text(ptMin+":"+ptSec);
//
//         var myTotalTime = new Date(totalTime);
//         var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" + myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();
//         var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
//         $("#total-time").text(ttMin+":"+ttSec);
//     })
//     .onSoundComplete( function() {
//         playListNext();
//     });
//
//     $("#prev").click( function() {
//         playListPrev();
//         return false;
//     });
//
//     $("#next").click( function() {
//         playListNext();
//         return false;
//     });
// }
//
// $(document).ready(function(){
//     BindWidget();
// });









var playItem = 0;

var myPlayList = [
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/c5393716a8b0dd313b714ed27a7fb5c7"},
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/d2b294f7b2605f7148fa0b782434bf08"},
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/0c3fd4713c8d908947dff2a54d5f73b4"},
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/a0333113c5f29ca230f0bf8a4c4d8c63"},
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/d386b7b0a7482dd57065f76c5b94e82a"},
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/47dce2e7a0b5f824b92d6129efb082e2"},
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/16ed16a85f69b9ffa890221c9b3a8b22"},
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/24c22a206c2a3ac863dfa55beb9cdf7c"},
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/a7214187c1f7ae8ae89867dad8c39176"},
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/dd43c2efe0c1780b5dfda2b88b7c7513"},
    {t:"http://provident.s3.amazonaws.com/tenthavenuenorth/t/e87e47eff34a4102dd809de2a946f200"}
];



var RecaptchaVerified = false;
function CaptchaCheck(callBackFunction)
{

    Boxy.load('/main/recaptcha',
    {
        modal:true,
        unloadOnHide:true,
        title:'Please Enter the Code Below',
        afterHide: function() {
            if(RecaptchaVerified)
                callBackFunction();
        }
    });

}

function CaptchaSuccess()
{
    Boxy.get('#captchaFrame').hide();
    RecaptchaVerified = true;
}

function GetU13()
{
    SONYMUSIC_COPPA_13.updateForm($('#U13Form'));
}

function displayPlayList() {
        for (i=0; i < myPlayList.length; i++) {
            //$("#playlist_list ul").append("<li id='playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
            $("#playlist-item-"+i).data( "index", i ).hover(
                function() {
                    if (playItem != $(this).data("index")) {
                        $(this).addClass("playlist_hover");
                    }
                },
                function() {
                    $(this).removeClass("playlist_hover");
                }
            ).click( function() {
                var index = $(this).data("index");
                if (playItem != index) {
                    playListChange( index );
                }
            });
        }
    }

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

function PlayerReady()
{
    displayPlayList();
    playListInit(false); // Parameter is a boolean for autoplay.
}



    function playListConfig( index ) {
        $("#playlist-item-"+playItem).removeClass("playlist-current");
        $("#playlist-item-"+index).addClass("playlist-current");
        playItem = index;
        $("#jquery_jplayer_widget").setFile(myPlayList[playItem].t, myPlayList[playItem].ogg);
    }

    function playListChange( index ) {
        playListConfig( index );
        $("#jquery_jplayer_widget").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 );
    }

$(document).ready(function(){

    $("#jquery_jplayer_widget").jPlayer({
        ready: function() {
            // ready stuff
            $('body').oneTime(1000, 'player', PlayerReady);
        },
        volume: 100,
        swfPath:"/system/application/assets/swf"

    })
    .jPlayerId("play", "play")
    .jPlayerId("pause", "pause")
    .jPlayerId("stop", "stop")
    .jPlayerId("loadBar", "load-bar")
    .jPlayerId("playBar", "play-bar")
    .jPlayerId("volumeMin", "top_player_volume_min")
    .jPlayerId("volumeMax", "top_player_volume_max")
    .jPlayerId("volumeBar", "top_player_volume_bar")
    .jPlayerId("volumeBarValue", "top_player_volume_bar_value")
    .onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
        var myPlayedTime = new Date(playedTime);
        var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" + myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
        var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" + myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
        $("#play-time").text(ptMin+":"+ptSec);

        var myTotalTime = new Date(totalTime);
        var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" + myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();
        var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
        $("#total-time").text(ttMin+":"+ttSec);
    })
    .onSoundComplete( function() {
        playListNext();
    });

    $("#prev").click( function() {
        playListPrev();
        return false;
    });

    $("#next").click( function() {
        playListNext();
        return false;
    });



    // Share twitter link
    $('a.shareTwitter').click(function() {
        var songName = $('ul.albumTitles li:eq(' + playItem + ')').text();
        var shortUrl = $('ul.shortUrls li:eq(' + playItem + ')').text();

        var message = '#CrownsFans Loving the Casting Crowns song, "' + songName + '" Hear it now! ' + shortUrl;

        location.href = 'http://twitter.com/home?status=' + escape(message);
    });

    // Share twitter link
    $('a.shareFacebook').click(function() {
        var songName = $('ul.albumTitles li:eq(' + playItem + ')').text();
        var trackNumber = playItem + 1;

        location.href = 'http://www.facebook.com/sharer.php?u=http://www.crownsfans.com/music/8/' + trackNumber + '&t=Until%20The%20Whole%20World%20Hears%20on%20CrownsFans.com';
    });

     // Share Email
     $('a.shareEmail').click(function() {
         var trackNumber = playItem+1;
         Boxy.load('/home/shareemail/8/' + trackNumber, {
             title: "Share this Track via Email!",
             modal: true,
             unloadOnHide: true,
             afterShow: function() {
                 var theWindow = this;
                 $('#shareEmailForm').ajaxForm({
                     dataType: 'json',
                     beforeSubmit:function() {
                         if(!RecaptchaVerified)
                         {
                             CaptchaCheck(function() {
                                 $('form#shareEmailForm').submit()
                             });
                             return false;
                         }
                     },
                     success: function(data) {
                         if(data.success == true)
                         {
                             // Success
                             Boxy.alert('You email has been sent!');
                             theWindow.hide();

                             //location.href = 'http://www.facebook.com/sharer.php?u='+encodeURIComponent(data.url)+'&t='+encodeURIComponent(data.title);
                         }
                         else
                         {
                             Boxy.alert(data.message);
                         }
                     }
                 });
             }
         });
     });



});

