﻿$(document).ready(function() {
    // More link for events
    $('.event a.more').click(function() {
        var elems = $(this).parents('.event').find('.body');
        if (elems.length) {
            elems.slideDown('normal').prev().hide();
            return false;
        }
    })

    // Show Searchform
    $('#headerSearch').click(function() { $('#headerSearch #searchString').show("slow"); })


    $("div.jp-ctr:has(div.jp-plyr)").each(function() {

        var jpid = $(this).children("div.jp-plyr").attr("id")
        var jpfileanchor = $(this).find("ul.playlist>li>a")
        var jpfile = jpfileanchor.attr("href")
        var jptitle = jpfileanchor.text();
        //alert(jpid + " ::: " + jpfile + " ::: " + jptitle);
        $("#" + jpid).jPlayer({
            ready: function() {
                $(this).setFile(jpfile);

            },
            cssPrefix: "jp",
            volume: 50
        })
            .jPlayerId("play", "play-" + jpid)
                .jPlayerId("pause", "pause-" + jpid)
                .jPlayerId("stop", "stop-" + jpid)
                .jPlayerId("loadBar", "loadbar-" + jpid)
                .jPlayerId("playBar", "playbar-" + jpid)
                .jPlayerId("volumeMin", "min-" + jpid)
                .jPlayerId("volumeMax", "max-" + jpid)
                .jPlayerId("volumeBar", "volumebar-" + jpid)
                .jPlayerId("volumeBarValue", "volumebarvalue-" + jpid)
                .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();
                    $("#pt-" + jpid).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();
                    $("#tt-" + jpid).text(ttMin + ":" + ttSec);
                    if (loadPercent > 0) { $("#time-" + jpid).show(); }
                })
                ;

    });



});
