/**
 * @category    Workbox jQuery
 * @package     wbBase
 * @copyright   Copyright (c) 2009-2010 Workbox AB (http://www.workbox.se)
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @version     1.0.0
 */

$(document).ready(function()
{

    $('.lava').lavaLamp({fx:'backout', speed:700});
    $('#bannerHolder').wbRotate({shortName:'banner'});
    $('input#date').live('click', function()
    {
        $(this).datepicker({showOn:'focus', dateFormat:'yy-mm-dd'}).focus();
    });

    var playItem = 0;
    var myPlayList = [
       /* {
            name:'Adam Tensta - My Cool',
            mp3:'http://www.konrad.se/mp3/adam_tensta_my_cool.mp3',
            ogg:'http://www.konrad.se/mp3/adam_tensta_my_cool.ogg'
        },
        {
            name:'Melody Club - Electric',
            mp3:'http://www.konrad.se/mp3/melody_club_electric.mp3',
            ogg:'http://www.konrad.se/mp3/melody_club_electric.ogg'
        },*/
        {
            name:'Summer Mix',
            mp3:'http://www.konrad.se/mp3/2009.mp3',
            ogg:'http://www.konrad.se/mp3/2009.ogg'
        }	
		    ];
    $("#jquery_jplayer").jPlayer({
        ready: function() {
            playListInit(false);
        },
        oggSupport: true
    })
    .jPlayerId("play", "player_play")
    .jPlayerId("pause", "player_pause")
    .jPlayerId("loadBar", "player_progress_load_bar")
    .jPlayerId("playBar", "player_progress_play_bar")
    .jPlayerId("volumeMin", "player_volume_min")
    .jPlayerId("volumeMax", "player_volume_max")
    .jPlayerId("volumeBar", "player_volume_bar")
    .jPlayerId("volumeBarValue", "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();
    });
    $("#ctrl_prev").click(function()
    {
        playListPrev();
        return false;
    });
    $("#ctrl_next").click(function()
    {
        playListNext();
        return false;
    });
    function playListInit(autoplay)
    {
        if (autoplay) {
            playListChange(playItem);
        } else {
            playListConfig(playItem);
        }
    }
    function playListConfig(index)
    {
        playItem = index;
        $('#trackname').html(myPlayList[playItem].name);
        $('#jquery_jplayer').setFile(myPlayList[playItem].mp3, myPlayList[playItem].ogg);
    }
    function playListChange(index)
    {
        playListConfig(index);
        $("#jquery_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);
    }
});
