﻿//
// Downloaded from http://home5.inet.tele.dk/nyboe/flash/mediaplayer/loadandplay.htm
// We need that to control the player ...
//

var currentItem; var showFlag=false;

function sendEvent(typ,prm) { thisMovie("thePlayerId").sendEvent(typ,prm); };


function getUpdate(typ,pr1,pr2,pid) {
	if(typ == "item") { currentItem = pr1; }
};


// 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 createOldPlayer(thePath,theFile,thePng,go) {
	var s = new SWFObject(thePath,"thePlayerId","300","100","7");
	s.addParam("allowfullscreen","true");
	s.addVariable("file",theFile);
	s.addVariable("width","300");
	s.addVariable("height","100");
	s.addVariable("displayheight","80");
	s.addVariable("overstretch","fit");
	s.addVariable('frontcolor','0xEEEEEE');
	s.addVariable('backcolor','0x333333');
	s.addVariable('lightcolor','0xFF6666');
	
	s.addVariable("showicons","false");
	if (go) { s.addVariable("autostart","true"); }
	s.addVariable('image',thePng);
	
	s.addVariable("enablejs","true");
	s.addVariable("javascriptid","thePlayerId"); 

	s.addVariable("showdigits","total");
	
	s.write("placeholder");
}


function createWindow(adr) { 
  showFlag=true;
  sendEvent("stop");
  document.getElementById("placeholder").style.visibility="hidden";
  var pWin=window.open(adr, "playerWin", "width=300,height=330,left=100,top=200,resizable=yes");
  pWin.focus();
}

function showhide() { 
  if (showFlag) { 
    document.getElementById("placeholder").style.visibility="visible";
  } else { 
    document.getElementById("placeholder").style.visibility="hidden";
  }
  showFlag=!(showFlag);
}

function showPlayer(info) { 
	document.getElementById("placeholder").style.visibility="visible";
	showFlag=true;
	//alert(info);
	//document.getElementById("soundinfo").innerHTML = info;
}
function hidePlayer() { 	
	document.getElementById("placeholder").style.visibility="hidden";
	showFlag=false;
}

// this stuff came from Andrea Feil, Martin Gruber : the guys who
// built the new player for YourSounds
 function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;

  // THIS IS REALLY STRANGE AND I DON'T UNDERSTAND THAT (kejr)
  if(isIE) return document.getElementById(movieName);
  else return document.embeds[movieName];
 }
 
 function createPlayer(thePath,theGifs) {
    var s = new SWFObject(thePath,'MyPlayer','685','180','7');
    s.addParam("allowfullscreen","true");
    s.addVariable("overstretch","fit");
    s.addVariable("enablejs","true");
    s.addVariable("javascriptid","MyPlayer"); 
    s.addVariable("gifFolder",theGifs); 
    s.write("placeholder"); 
}

 
// is the player in the DOM ?
 function PlayerAvailable() {
	 if( !getFlashMovie('MyPlayer') ) {
		 //alert(0);
		 xajax.$('playerswitch').value = 0;
		 return false;
	 } else {
		 //alert(1);
		 xajax.$('playerswitch').value = 1;
		 return true;
	 }
 }
 
 
 function ShowCurve(soundpath,playtime,play,sid) {
	 //alert(soundpath + ' ' + playtime + ' ' + play);
	 //p = document.getElementById('MyPlayer');
	 //alert(p);
	 //alert(getFlashMovie('MyPlayer').name);
	 //p.SetSound(soundpath,playtime,play);

	 getFlashMovie('MyPlayer').SetSound(soundpath,playtime,play);
	 
	 xajax_SoundPlayingNow(sid);
 }
 
// function that will be called when the user changes the selected area...
 function AreaChanged(start,end) {
 	if(start == 0 && end == 0 ) return true;
 	if(start > end) {
 		tmp = start;
 		start = end;
 		end = tmp;
 	}
 	if(start >= 0 && end > 0) {
 		//alert(start+' '+end);
 		xajax_SoundPartSelected(start,end);
 	}
 	else {
 		alert("Start="+start+" End="+end+"\nPlay vorher gedrückt ?\nDid you press the play button before ?");
 	}
	window.status = 'start ' +start +', end ' +end;
 }

 
 //alert(getFlashMovie('MyPlayer').name);
 //alert(document.embeds["MyPlayer"].name);
 //alert(document["MyPlayer"].name);
 //obj = document.embeds["MyPlayer"];
 
