//
//	common.js -- common javascipt functions used throughout the website
//	Written by Jon Burney (e4education)
//	Copyright 2007 Bluestone New Media Ltd (e4education)
//


//  function:  addLoadEvent
//  arguments:  func - the name of the function to attach
//  return: none
// desc: Attaches a function to the onload event while preserving existing onload functions
//  Credit to Simon Willison (see http://simonwillison.net/2004/May/26/addLoadEvent/ for more details)
function addLoadEvent(func) {

	var oldonload = window.onload;
	
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		
		window.onload = function() {
		
			if (oldonload) {
				oldonload();
			}
		
			func();
		}
	}
}

function playPodcast(strFileName, strFileTitle) {

	var elmMediaContainer = document.getElementById("mediaplayer");
	
	if (elmMediaContainer.childNodes.length >= 1) {	
	
		while (elmMediaContainer.firstChild) {
			elmMediaContainer.removeChild(elmMediaContainer.firstChild);
		}
	}
		
	strSRC = "/_includes/swf/audio/fmp3.swf?mp3="+strFileName+"&action=play&title="+strFileTitle+"&color=E6E9FB&vol=60&loop=no&lma=yes&textcolor=033066";
	
	var elmFlashObject = document.createElement("object");
	elmFlashObject.setAttribute("classid", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000");
	elmFlashObject.setAttribute("codebase","http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0");
	elmFlashObject.width = "250"
	elmFlashObject.height = "60"
	elmFlashObject.id = "fmp3player"
	
	var elmMovieParam = document.createElement("param");
	elmMovieParam.name = "movie";
	elmMovieParam.value = strSRC;
	
	var elmQualityParam = document.createElement("param");
	elmQualityParam.name = "quality";
	elmQualityParam.value = "high";
	
	var elmBGParam = document.createElement("param");
	elmBGParam.name = "bgcolor";
	elmBGParam.value = "#ffffff";

	var elmEmbed = document.createElement("embed");
	elmEmbed.setAttribute("src",strSRC);
	elmEmbed.setAttribute("quality","high");
	elmEmbed.setAttribute("bgcolor","#ffffff");
	elmEmbed.setAttribute("width","250");
	elmEmbed.setAttribute("height","60");
	elmEmbed.setAttribute("align","middle");
	elmEmbed.setAttribute("name","fmp3player");
	elmEmbed.setAttribute("allowScriptAccess","sameDomain");
	elmEmbed.setAttribute("type","application/x-shockwave-flash");
	elmEmbed.setAttribute("pluginspage","http://www.macromedia.com/go/getflashplayer");
	

	var s = navigator.userAgent.toLowerCase();

	var IsIE		= s.indexOf('msie')!=-1;
	var IsIE7		= s.indexOf('msie 7')!=-1;
	var IsGecko		= s.indexOf('gecko/')!=-1;
	var IsSafari	= s.indexOf('safari')!=-1;
	var IsOpera		= s.indexOf('opera')!=-1;
	var IsMac		= s.indexOf('macintosh')!=-1;

	if (IsIE) {
		elmMediaContainer.innerHTML = "<object width=\"250\" height=\"60\" align=\"middle\" data=\"" + strSRC + "\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\">" + elmMovieParam.outerHTML+elmQualityParam.outerHTML+elmBGParam.outerHTML+elmEmbed.elmEmbed + "</object>";
	} else {
		elmMediaContainer.appendChild( elmFlashObject );
		elmFlashObject.appendChild( elmMovieParam );
		elmFlashObject.appendChild( elmQualityParam );
		elmFlashObject.appendChild( elmBGParam );
		elmFlashObject.appendChild( elmEmbed );
	}
	
}
