// some variables to save
var currentPosition;
var currentVolume;
var currentItem;

var theID; 
var p1playing;
var p2playing;
var p3playing;
var p4playing;
var p5playing;
var p6playing;

// these functions are caught by the JavascriptView object of the player.
function sendEvent(thePlayer, typ, prm) { thisMovie(thePlayer).sendEvent(typ,prm); };

function getUpdate(typ,pr1,pr2,pid) {
	if ((pid != "null")&&(typ=="state")&&(pr1==2)) {
		if (pid=="player1") { 
			p1playing=true;
		    if (p2playing) { sendEvent("player2", 'stop');  p2playing=false; }
		    if (p3playing) { sendEvent("player3", 'stop');  p3playing=false; }
		    if (p4playing) { sendEvent("player4", 'stop');  p4playing=false; }
		    if (p5playing) { sendEvent("player5", 'stop');  p5playing=false; }
		    if (p6playing) { sendEvent("player6", 'stop');  p6playing=false; }
        } else if (pid=="player2") { 
			p2playing=true;
			if (p1playing) { sendEvent("player1", 'stop');  p1playing=false; }
		    if (p3playing) { sendEvent("player3", 'stop');  p3playing=false; }
		    if (p4playing) { sendEvent("player4", 'stop');  p4playing=false; }
		    if (p5playing) { sendEvent("player5", 'stop');  p5playing=false; }
		    if (p6playing) { sendEvent("player6", 'stop');  p6playing=false; }            
        } else if (pid=="player3") { 
			p3playing=true;
			if (p1playing) { sendEvent("player1", 'stop');  p1playing=false; }
		    if (p2playing) { sendEvent("player2", 'stop');  p2playing=false; }
		    if (p4playing) { sendEvent("player4", 'stop');  p4playing=false; }
		    if (p5playing) { sendEvent("player5", 'stop');  p5playing=false; }
		    if (p6playing) { sendEvent("player6", 'stop');  p6playing=false; }            
        } else if (pid=="player4") { 
			p4playing=true;
			if (p1playing) { sendEvent("player1", 'stop');  p1playing=false; }
		    if (p2playing) { sendEvent("player2", 'stop');  p2playing=false; }
		    if (p3playing) { sendEvent("player3", 'stop');  p3playing=false; }
		    if (p5playing) { sendEvent("player5", 'stop');  p5playing=false; }
		    if (p6playing) { sendEvent("player6", 'stop');  p6playing=false; }            
        } else if (pid=="player5") { 
			p5playing=true;
			if (p1playing) { sendEvent("player1", 'stop');  p1playing=false; }
		    if (p2playing) { sendEvent("player2", 'stop');  p2playing=false; }
		    if (p3playing) { sendEvent("player3", 'stop');  p3playing=false; }
		    if (p4playing) { sendEvent("player4", 'stop');  p4playing=false; }
		    if (p6playing) { sendEvent("player6", 'stop');  p6playing=false; }            
        } else if (pid=="player6") { 
			p6playing=true;
			if (p1playing) { sendEvent("player1", 'stop');  p1playing=false; }
		    if (p2playing) { sendEvent("player2", 'stop');  p2playing=false; }
		    if (p3playing) { sendEvent("player3", 'stop');  p3playing=false; }
		    if (p4playing) { sendEvent("player4", 'stop');  p4playing=false; }
		    if (p5playing) { sendEvent("player5", 'stop');  p5playing=false; }
		}
	}
};

// 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 createPlayer(thePlace, thePlayer, theFile, theImg, theCap, start, icons) {
	var s1 = new SWFObject("mediaplayer.swf", thePlayer, '350','255','8');
    s1.addParam('allowscriptaccess','always');
    s1.addParam('allowfullscreen','true');
    s1.addVariable("enablejs","true");
    s1.addVariable('height','255');
    s1.addVariable('width','350');
    s1.addVariable('showicons','false');
    s1.addVariable('usecaptions','false');
    s1.addVariable('overstretch', 'true');
	s1.addVariable("file", theFile);
	s1.addVariable("javascriptid",thePlayer);
	if (start) s1.addVariable("autostart", "true");
	if (! icons) s1.addVariable("showicons", "false");
	if (theImg != "") s1.addVariable("image", theImg);
	if (theCap != "") s1.addVariable("captions", theCap);
	s1.write(thePlace);
}
