/*
var myLink = document.getElementById("myLink");
var classAttr = myLink.getAttributeNode("class");
if (classAttr) classAttr.nodeValue += " clickable";
else { 
  var newAttr = document.createAttribute("class");
  newAttr.nodeValue = "clickable";
  myLink.setAttributeNode(newAttr);
  }
*/



function showVideo() {
	/*
	This function shows or hides the video div
		the video's unique YouTube id is cheekily hidden in the video div's 'name' tag
	*/
	var oldDiv = document.getElementById('video');
	var videoText = oldDiv.getAttribute("name");
	var hostDiv = oldDiv.parentNode;
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id', 'video');
	newDiv.setAttribute('name', videoText);
	if(oldDiv.style.display == 'none') {
		var videoPlayer = '<object width="425" height="373"><param name="movie" '+
			'value="http://www.youtube.com/v/'+ videoText +
			'&rel=0&color1=0x5d1719&color2=0xcd311b&border=1"></param>'+
			'<param name="wmode" value="transparent"></param>'+
			'<embed src="http://www.youtube.com/v/'+ videoText +
			'&rel=0&color1=0x5d1719&color2=0xcd311b&border=1" '+
			'type="application/x-shockwave-flash" wmode="transparent" '+
			'width="425" height="373"></embed></object>';

		newDiv.innerHTML = videoPlayer;
		newDiv.style.display = 'block';
		hostDiv.replaceChild(newDiv, oldDiv);
		}
	else {
		newDiv.style.display = 'none';
		hostDiv.replaceChild(newDiv, oldDiv);
		}
	changeVideoLink();
	}

function changeVideoLink() {
	/*
	This function changes the video link
		the on/off flag is hidden in the span's 'name' tag
	*/
	var oldSpan = document.getElementById('videolink');
	var spanState = oldSpan.getAttribute('name');
	var hostDiv = oldSpan.parentNode;
	var newSpan = document.createElement('span');
	newSpan.setAttribute('id', 'videolink');
	if(newSpan.addEventListener) {newSpan.addEventListener('click',showVideo,false);}
	else if(newSpan.attachEvent) {newSpan.attachEvent('onclick',showVideo);}
	else if (newSpan.onclick) {newSpan.onclick=showVideo;}
	if(spanState == 'off') {
		var spanText = 'Switch Rik off!';
		newSpan.innerHTML = spanText;
		newSpan.setAttribute('name', 'on');
		hostDiv.replaceChild(newSpan, oldSpan);
		}
	else {
		var spanText = 'Watch Rik read the poem';
		newSpan.innerHTML = spanText;
		newSpan.setAttribute('name', 'off');
		hostDiv.replaceChild(newSpan, oldSpan);
		}
	}

function showAudio() {
	/*
	This function shows or hides the audio div
		the audio file name is cheekily hidden in the audio div's 'name' tag
	*/
	var oldDiv = document.getElementById('audio');
	var audioText = oldDiv.getAttribute("name");
	var hostDiv = oldDiv.parentNode;
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id', 'audio');
	newDiv.setAttribute('name', audioText);
	if(oldDiv.style.display == 'none') {
		var audioPlayer = '<object id="MediaPlayer1" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" '+
			'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab# '+
			'Version=5,1,52,701" standby="Loading Microsoft Windows® Media Player components..." '+
			'type="application/x-oleobject" width="280" height="46">'+
			'<param name="fileName" value="sounds/' + audioText + '">'+
			'<param name="animationatStart" value="true">'+
			'<param name="transparentatStart" value="true">'+
			'<param name="autoStart" value="false">'+
			'<param name="showControls" value="true">'+
			'<param name="Volume" value="-300">'+
			'<embed type="application/x-mplayer2" '+
			'pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" '+
			'src="sounds/' + audioText + '" name="MediaPlayer1" width=280 height=46 '+
			'autostart=0 showcontrols=1 volume=-300></object>';
	
		newDiv.innerHTML = audioPlayer;
		newDiv.style.display = 'block';
		hostDiv.replaceChild(newDiv, oldDiv);
		}
	else {
		newDiv.style.display = 'none';
		hostDiv.replaceChild(newDiv, oldDiv);
		}
	changeAudioLink();
	}

function changeAudioLink() {
	/*
	This function changes the audio link
		the on/off flag is hidden in the span's 'name' tag
	*/
	var oldSpan = document.getElementById('audiolink');
	var spanState = oldSpan.getAttribute('name');
	var hostDiv = oldSpan.parentNode;
	var newSpan = document.createElement('span');
	newSpan.setAttribute('id', 'audiolink');
	if(newSpan.addEventListener) {newSpan.addEventListener('click',showAudio,false);}
	else if(newSpan.attachEvent) {newSpan.attachEvent('onclick',showAudio);}
	else if (newSpan.onclick) {newSpan.onclick=showAudio;}
	if(spanState == 'off') {
		var spanText = 'Make Rik stop talking!';
		newSpan.innerHTML = spanText;
		newSpan.setAttribute('name', 'on');
		hostDiv.replaceChild(newSpan, oldSpan);
		}
	else {
		var spanText = 'Hear Rik read the poem';
		newSpan.innerHTML = spanText;
		newSpan.setAttribute('name', 'off');
		hostDiv.replaceChild(newSpan, oldSpan);
		}
	}

//the following code is used by the Snowdrop poems to open a new window with extra, hidden information ...
//	eg: <span class="snow" onclick="snote('christiani')">christiani</span>
function snote(myNote) {
	var noteString = 'directories=no, '+
		'height=400, '+
		'width=600, '+
		'top=200, '+
		'left=400, '+
		'menubar=no, '+
		'toolbar=no, '+
		'location=no, '+
		'status=no, '+
		'resizable=yes, '+
		'scrollbars=yes';
	window.open('notes/'+myNote+'.php','_blank',noteString);
	}
