var vp;
function playerReady(obj){
	vp = document.getElementById(obj['id']);
}

function playVideo(playerEvent, theObject) {
	openPlayer(playerEvent, theObject);
	openPlayer("PLAY", "true");
}

function videoPlayer(playerEvent, theObject){
	if (typeof(theObject) == "object") {
        if ((typeof(vp) == null || typeof(vp) == "undefined") || (navigator.userAgent.indexOf('Firefox') > -1 && playerParams.popup)) {
            createPlayer(theObject);
            if (playerParams.popup) 
                $(playerParams.modalWindow).jqmShow();
        }
        else {
            if (playerParams.popup) 
                $(playerParams.modalWindow).jqmShow();
            openPlayer(playerEvent, theObject);
        }
    }
    else {
        createPlaylistPlayer(theObject);
    }
}

function createPlaylistPlayer(theObject){
    var flashvars = {
        file: theObject,
        playlist: 'bottom',
		playlistsize: 200,
        backcolor: 'ffffff',
        logo: '/images/vdc_logo_sm.png',
        id: playerParams.placeholder,
        controlbar: 'bottom'
    }
    var params = {
        allowfullscreen: "true",
        allowscriptaccess: "always",
				wmode: "transparent"
    }
    var attributes = {
        id: playerParams.placeholder,
        name: playerParams.placeholder
    }
    swfobject.embedSWF(playerParams.url, playerParams.placeholder, playerParams.width, playerParams.height, playerParams.version, false, flashvars, params, attributes);
}


function createPlayer(theObject){
    var flashvars = {
        streamer: theObject.streamer,
        file: theObject.file,
        id: playerParams.placeholder,
        subscribe: true,
        type: theObject.type,
        autostart: theObject.autostart,
        image: theObject.image,
        controlbar: 'bottom',
		displaytitle: true
    }
    var params = {
        allowfullscreen: "true",
        allowscriptaccess: "always",
				wmode: "transparent"
    }
    var attributes = {
        id: playerParams.placeholder,
        name: playerParams.placeholder
    }
    swfobject.embedSWF(playerParams.url, playerParams.placeholder, playerParams.width, playerParams.height, playerParams.version, false, flashvars, params, attributes);
}

function createMultiPlayer(theObject, placeholder){
    var flashvars = {
        streamer: theObject.streamer,
        file: theObject.file,
        id: playerParams.placeholder,
        subscribe: true,
        type: theObject.type,
        autostart: theObject.autostart,
        image: theObject.image,
        controlbar: 'bottom',
		displaytitle: true
    }
    var params = {
        allowfullscreen: "true",
        allowscriptaccess: "always",
				wmode: "transparent"
    }
    var attributes = {
        id: placeholder,
        name: placeholder
    }
    swfobject.embedSWF(playerParams.url, placeholder, playerParams.width, playerParams.height, playerParams.version, false, flashvars, params, attributes);
}

function stopPlayer(){
    vp.sendEvent('STOP');
}

function openPlayer(playerEvent, theObject){
    vp.sendEvent(playerEvent, theObject);
}
