/***************** Whirlypit.co.uk ********************\
                   David King 2006
 TrainThePainter Javascript deposit, lots of fun stuff
  here! (possibly)
\******************************************************/

// browser detection - use later to give more chrome to IE7 ////
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
/*
    *  Browser name: BrowserDetect.browser
    * Browser version: BrowserDetect.version
    * OS name: BrowserDetect.OS

*/
//alert(BrowserDetect.browser;BrowserDetect.version);
IE7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? true : false;

function view_image (my_size) {
	document.getElementById("full_image").style.display = "block";
	document.getElementById("media_toolbar_object").style.visibility = "hidden";
	if(my_size=="tall"){
		var windowW = 784;
		if (screen.width <= windowW) {
			windowW = screen.width;
		}
		var windowH = 750;
			//IE7 needs more space than others//
		if (IE7==true){
			windowH = 770;
		}
		self.resizeTo(windowW, windowH);
		windowX = (screen.width/2)-(windowW/2);
		windowY = (screen.height/2)-(windowH/2);
		self.moveTo(windowX,windowY);
	}
}




function hide_image () {
	document.getElementById("full_image").style.display = "none";
	document.getElementById("media_toolbar_object").style.visibility = "visible";
	var windowW = 784;
	if (screen.width <= windowW) {
		windowW = screen.width;
	}
	var windowH = 665;
		//IE7 needs more space than others//
	if (IE7==true){
		windowH = 665;
	}
	self.resizeTo(windowW, windowH);
	windowX = (screen.width/2)-(windowW/2);
	windowY = (screen.height/2)-(windowH/2);
	self.moveTo(windowX,windowY);

}
// Toggles a divs visibility
function STYLE_toggle_visiblity (elementID) {
	var elementDisplay = document.getElementById(elementID).style.display;
	elementDisplay = elementDisplay == "block" ?  "none" : "block";
	document.getElementById(elementID).style.display = elementDisplay;
}
// Opens up the training window:
function train_me (el_ref) {
	// Dimensions:
	var windowW = 780;
	if (screen.width <= windowW) {
		windowW = screen.width;
	}
	var windowH = 580;
		//IE7 needs more space than others//
	if (IE7==true){
		windowH = 600;
	}
	if (BrowserDetect.browser=="Chrome"){
		windowH = 655;
	}
	if (screen.height <= windowH) {
		windowH = screen.height;
	}
	windowX = (screen.width/2)-(windowW/2);
	windowY = (screen.height/2)-(windowH/2);
	// PopWin = window.open('./program.php?PROGRAM='+PROGRAM+'&doExam='+doExam+'&doExamUser='+doExamUser+'&doExamID='+doExamID,'myPopUp','width='+windowW+',height='+windowH+',scrollbars=0,status=0,resizeable=true, toolbar=0');
	PopWin = window.open(el_ref.href,'myPopUp','width='+windowW+', height='+windowH+', scrollbars=1, status=0, resizeable=true, toolbar=0');
	PopWin.moveTo(windowX,windowY);
	PopWin.focus();
}
// Opens up the training window:
/*
function train_me (el_ref) {
	// Dimensions:
	alert ("ref= "+el_ef);
	var windowW = 780;
	if (screen.width <= windowW) {
		windowW = screen.width;
	}
	var windowH = 580;
	//IE7 needs more space than others//
	if (IE7==true){
		windowH = 600;
	}
	if (screen.height <= windowH) {
		windowH = screen.height;
	}
	windowX = (screen.width/2)-(windowW/2);
	windowY = (screen.height/2)-(windowH/2);
	// PopWin = window.open('./program.php?PROGRAM='+PROGRAM+'&doExam='+doExam+'&doExamUser='+doExamUser+'&doExamID='+doExamID,'myPopUp','width='+windowW+',height='+windowH+',scrollbars=0,status=0,resizeable=true, toolbar=0');
	PopWin = window.open(el_ref.href,'myPopUp','width='+windowW+', height='+windowH+', scrollbars=1, status=0, resizeable=true, toolbar=0');
	PopWin.moveTo(windowX,windowY);
	PopWin.focus();
}
*/
// Stops the audio on the assessment page (before the popup is created!)
function stop_sounds () {
	// Get the flash element in question:
	var flash = document.getElementById ('voiceover_objective_object');
	// Call the stopsounds frame:
	flash.TCallLabel("/", "stop_sounds");
}

// Set-up to use getMouseXY function onMouseMove
// document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
	if (document.captureEvents) {
		tempX = e.pageX;
		tempY = e.pageY;
	} else if (window.event.clientX) {
		tempX = window.event.clientX+document.documentElement.scrollLeft;
		tempY = window.event.clientY+document.documentElement.scrollTop;
	}
	// catch possible negative values in NS4
	tempX < 0 ? tempX = 0 : false;
	tempY < 0 ? tempY = 0 : false;
	// Ensure that the box is within the viewing area:
	if (document.body && (document.body.clientWidth !=0)) {
		winW=document.body.clientWidth;
		winH=document.body.clientHeight;
	}
	// Not else if, I want an inline if:
	if (document.documentElement && (document.documentElement.clientWidth!=0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) {
		winW=document.documentElement.clientWidth;
		winH=document.documentElement.clientHeight;
	}  
	// Bounding (only X):
	(tempX + 312 > winW) ? (tempX = winW - 312) : false;
	// Set the position of the div:
	document.getElementById("tooltip").style.left = tempX + "px";
	document.getElementById("tooltip").style.top = (tempY + 20) + "px";
	return true;
}

// Displays the block:
function showtip (el_ref, img) {
	// Grab its title:
	title = el_ref.firstChild.nodeValue;
	document.getElementById("tooltip_title").innerHTML = title;
	// Grab its definition (strip off the brackets):
	tip = el_ref.childNodes[1].innerHTML;
	tip = tip.substring(2, (tip.length-1));
	document.getElementById("tooltip_div").innerHTML = tip;
	// Set the img (if passed one):
	if (img) {
		document.getElementById("tooltip_img").src = img;
		document.getElementById("tooltip_img").style.display = "block";
	} else {
		document.getElementById("tooltip_img").style.display = "none";
	}
	// Display it:
	document.getElementById("tooltip").style.display = "block";
}

// Hides the tooltip:
function hidetip () {
	document.getElementById("tooltip").style.display = "none";
}

//////CK addition as ie6 is being a reet pain asking to activate every time and other method failed///

function injectFlashMediaToolbar (flash_vol, flash_audio, flash_w, flash_h, is_USB) {
	
document.write('<object id="voiceover_objective_object" type="application/x-shockwave-flash" data="flash/Media_toolbar.swf?myVolume='+flash_vol+'&audioPath='+flash_audio+'&isUSB='+is_USB+'&isVoiceOver=true" width="'+flash_w+'" height="'+flash_h+'">\n');
document.write('<param name="movie" value="flash/Media_toolbar.swf?myVolume='+flash_vol+'&audioPath='+flash_audio+'&isUSB='+is_USB+'&isVoiceOver=true" />\n');
document.write('</object>\n');
}

function injectFlashSlideShowToolbar (flash_vol, flash_audio, flash_w, flash_h, is_USB, media_id) {
	
document.write('<object id="media_toolbar_object" type="application/x-shockwave-flash" data="flash/Media_toolbar.swf?myVolume='+flash_vol+'&myID='+media_id+'&audioPath='+flash_audio+'&isUSB='+is_USB+'&isVoiceOver=true" width="'+flash_w+'" height="'+flash_h+'">\n');
document.write('<param name="movie" value="flash/Media_toolbar.swf?myVolume='+flash_vol+'&myID='+media_id+'&audioPath='+flash_audio+'&isUSB='+is_USB+'&isVoiceOver=true" />\n');
document.write('<param name="wmode" value="transparent">');
document.write('</object>\n');
}



