function getPlayer(gid) {
     return document.getElementById(gid);
     //return (navigator.appName.indexOf("Microsoft") != -1)? window[gid]:document[gid]; 
};
function introplayer() {
    swfobject.embedSWF(
        //"/SBCCD/Shared/Files/jlv_mediaplayer/mediaplayer_5.3.swf", 
        "/SBCCD/Shared/Files/minicaster/minicaster.swf", 
        "liveplayer_container", 
        "180", 
        "70", 
        "9.0.124", 
        "/SBCCD/Shared/js/expressinstall.swf", 
        /*{
            width:"320", 
            height:"20", 
            file:"http://mp3.kvcr.org/Pre-Stream.mp3",
            autostart:"true",
            skin:"/SBCCD/Shared/Files/jlv_mediaplayer/simple.swf",
            usefullscreen:"false",
            provider:"sound",
            duration:"0",
            bufferlength:0,
            tracecall:"console.log"
        }, */
        {
            "allowfullscreen":"false",
            "allowscriptaccess":"always", 
            "seamlesstabbing":"true", 
            "wmode":"transparent"
        }, 
        {
            id:"liveplayer", 
            name:"liveplayer"
        }
    );
    
    //$(document).oneTime("23s", liveplayer);
};

function liveplayer() {
    swfobject.embedSWF(
        //"/SBCCD/Shared/Files/jlv_mediaplayer/mediaplayer_5.3.swf", 
        "/SBCCD/Shared/Files/minicaster/minicaster-live.swf", 
        "liveplayer_container", 
        "180", 
        "70", 
        "9.0.124", 
        "/SBCCD/Shared/js/expressinstall.swf", 
        /*{
            width:"320", 
            height:"20", 
            file:"http://mp3.kvcr.org/Pre-Stream.mp3",
            autostart:"true",
            skin:"/SBCCD/Shared/Files/jlv_mediaplayer/simple.swf",
            usefullscreen:"false",
            provider:"sound",
            duration:"0",
            bufferlength:0,
            tracecall:"console.log"
        }, */
        {
            "allowfullscreen":"false",
            "allowscriptaccess":"always", 
            "seamlesstabbing":"true", 
            "wmode":"transparent"
        }, 
        {
            id:"liveplayer", 
            name:"liveplayer"
        }
    );
};

jQuery(document).ready(introplayer);

var liveStarted = false;
var length = 18000;
var label = "Start_Live";

function xtrace(_st) {
    if (window.console)
    {
        console.log(_st); 
    }

    if (!liveStarted)
    {
        var matches = _st.match(/position=(\d+)/i);
        if (matches)
        {
            var position = parseInt(matches[1]);
            $(document).stopTime(label);
            $(document).oneTime(length-position, label, startLive);
            if (window.console)
            {
                console.log(length-position); 
            }
        }
        
    }    
} 

function startLive() {
    var player = getPlayer("liveplayer_container");
    player.playpause(1);
	player.setconfig("/SBCCD/Shared/Files/minicaster/minicaster-live.xml");
	liveStarted = true;
}

//$(document).oneTime("23s", startLive);

/*
function startLive() {
    var player = getPlayer("liveplayer");
    var playList = player.getPlaylist();
    playList[0].file = "http://mp3.kvcr.org/live.mp3";
    player.sendEvent("LOAD",playList);
    player.sendEvent("PLAY","true");
}

function stateTracker(obj) { 
    //console.log("New State: "+obj.newstate+"\nOld State: "+obj.oldstate); 
    var player = getPlayer("liveplayer");
    var playList = player.getPlaylist();
    var ocnfig = player.getConfig();
    if (obj.newstate == "COMPLETED") {
        //console.log("Loading stream"); 
        player.sendEvent("LOAD","http://mp3.kvcr.org/live.mp3");
        player.sendEvent("PLAY","true");
    }
    if (obj.newstate == "PLAYING") {
        //console.log(playList[0].file);
        var file = playList[0].file;
        if (file == "http://mp3.kvcr.org/Pre-Stream.mp3")
        {
            $(document).oneTime("23s", startLive);
            $(document).oneTime("24s", function() {
            	setInterval(startLive, 20000);
            });
        }
    }
};
function playerReady(obj) {
    var id = obj['id'];
    if(id == "liveplayer") {
        var player = getPlayer("liveplayer");
        player.addModelListener("STATE","stateTracker");
    }
};
*/
