// Flash Media Player functions

// some variables to save
var currentPosition;
var currentVolume;
var currentItem;
var currentLink;

// these functions are caught by the JavascriptView object of the player.
function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };
function getUpdate(typ,pr1,pr2,pid) {
    if((typ == "state") && (pr1 == 3) && (currentLink != null)) { 
        window.open(currentLink);
        loadFile({file:gsBaseURL + 'flv/ylw_satellites_intro.flv',image:gsBaseURL + 'images/player_splash.jpg'});
    }
    if(typ == "time") { currentPosition = pr1; }
    else if(typ == "volume") { currentVolume = pr1; }
    else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }
    /* var id = document.getElementById(typ);
    id.innerHTML = typ+ ": "+Math.round(pr1);
    pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
    if(pid != "null") {
        document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
    }*/
};

// These functions are caught by the feeder object of the player.
function loadFile(obj) { thisMovie("mpl").loadFile(obj); };
function addItem(obj,idx) { thisMovie("mpl").addItem(obj,idx); }
function removeItem(idx) { thisMovie("mpl").removeItem(idx); }
function getItemData(idx) {  
    try {
	    var obj = thisMovie("mpl").itemData(idx);
	    if((obj['link'] == undefined) || (obj['link'] == null)) {
	        currentLink = null;
	    } else {
	        currentLink = obj['link'];
	    }
	} catch(err) {
		currentLink = null;
	}
};

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
};

function playVideo(file,oLink) {
    loadFile({file:gsBaseURL + 'flv/' + file,title:oLink.title,link:oLink.href,id:'1'});
    sendEvent('playpause');
    return false;
}