function windowSize() {
// From http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
//  window.alert( 'Width = ' + myWidth );
//  window.alert( 'Height = ' + myHeight );
  return [myWidth, myHeight];
}

// Test if a pop-up blocker is in effect
// Open a window then close it. If it's not still there to be closed, then it was blocked!
// Optionally specify array winPosc as (left,top) coords of test window (so it can be unobtrusive)
function PopupBlocked(winPos) {
 var winPars = "width=100,height=100";
 try { winPars = winPars + ",left="+winPos[0]+",top="+winPos[1]; } catch(e) {}
 var PUtest = window.open("","",winPars);
 try { PUtest.close(); return false; }
 catch(e) { return true; }
}

// functions for the api calls
// Status methods of ytplayer: getPlayerState(), getVideoBytesLoaded(), getVideoBytesTotal(), getCurrentTime(), getDuration(), getVideoStartBytes(), getVolume();
// Action methods of ytplayer: mute(), unMute(), setVolume(newVolume)
function loadNewVideo(id, startSeconds) {
  if (ytplayer) {
   ytplayer.loadVideoById(id, parseInt(startSeconds));
  } else {
   alert("Can't find player to load id "+id);
  }
  return ytplayer;
}
function cueNewVideo(id, startSeconds) {
  if (ytplayer) {
    ytplayer.cueVideoById(id, startSeconds);
  }
}
function play() {
  if (ytplayer) {
    ytplayer.playVideo();
  }
}
function pause() {
  if (ytplayer) {
    ytplayer.pauseVideo();
  }
}
function stop() {
  if (ytplayer) {
    ytplayer.stopVideo();
  }
 }
function playVideo (id) {
 if (loadNewVideo(id, '0')) {
  play();
 }
}
// Change volume by "amount" - either softer (neg) or louder (pos). Scale is from 0 to 100.
function volumeVideo (amount) {
 if (ytplayer) {
  volume = ytplayer.setVolume(ytplayer.getVolume() + amount);
 }
}
// Add the volume number to the text; actually, add newtext to oldtext as follows:
//  If there's a parenthesized expression in oldtext, replace text inside parens with newtext;
//  else append " (newext)" to oldtext.
function voltext (oldtext,newtext) {
var volpos;
var volend;
var result;
 volpos = oldtext.indexOf('(');
 if (volpos >= 0) {
  volend = oldtext.indexOf(')');
  result = oldtext.substr(0,volpos+1) + newtext + oldtext.substr(volend);
 } else {
  result = oldtext + '(' + newtext + ')';
 }
 return result;
}
// Display the volume in the button (meant as an onmousedown event handler): specify either loud or soft button.
function displayVolVideo (butid) {
 var sbtext;
 if (butid == 'sbloud') {
  sbtext = document.splashcontrol.sbloud.value;
  document.splashcontrol.sbloud.value = voltext(sbtext,ytplayer.getVolume());
 } else if (butid == 'sbsoft') {
  sbtext = document.splashcontrol.sbsoft.value;
  document.splashcontrol.sbsoft.value = voltext(sbtext,ytplayer.getVolume());
 }
 return true;
}
// Wipe the volume number from the button (really just delete first parenthesis & after)
function wipeVolVideo (butid) {
 var sbtext;
 var sbpar;
 if (butid == 'sbloud') {
  sbtext = document.splashcontrol.sbloud.value;
  sbpar = sbtext.indexOf('(');
  if (sbpar > 0) {
   document.splashcontrol.sbloud.value = sbtext.substr(0,sbpar);
  }
 } else if (butid == 'sbsoft') {
  sbtext = document.splashcontrol.sbsoft.value;
  sbpar = sbtext.indexOf('(');
  if (sbpar > 0) {
   document.splashcontrol.sbsoft.value = sbtext.substr(0,sbpar);
  }
 }
 return true;
}

// Pause or continue video - works in connection with button called "sbc" in form "splashcontrol"
// Changes text in button to match next action.
// If last player state was "finished" then loads queued video (if any) and plays; if "paused" then continues; else pauses.
function toggleVideo(myButton,stopmsg,startmsg) {
 if (playerState == 2) {
  myButton.value = stopmsg;
  play();
 } else if (playerState == 1 || playerState == 3) {
  myButton.value = startmsg;
  pause();
 } else if (queuedvideoID) {
  loadNewVideo(queuedvideoID,'0');
  play();
  queuedvideoID = null;
  myButton.value = stopmsg;
 }
}

// Play a sound that has been loaded using the EMBED tag: See http://www.phon.ucl.ac.uk/home/mark/audio/play.htm
// <embed src="success.wav" autostart=false width=0 height=0 name="sound1" enablejavascript="true">
function EvalSound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}

