/* 
Flash\JS speech controls Version 1.0
 Basic controls for starting and stopping speech play back
 (c) Joe Chidzik 2008
 */
toggleState = 'on';

// Browser check. Returns 1 if IE
var browserCheck = (document.all) ? 1 : 0;

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

// Communicates with speak.swf via exposed function: startSpeaking
function startSpeaking(id) {
	if (browserCheck == 1) id += "IE"; // if IE, append IE to id value
	getFlashMovie(id).startSpeaking();
	//alert(id);
}

// Communicates with speak.swf via exposed function: startSpeaking	
function stopSpeaking(id) {
	if (browserCheck == 1) id += "IE"; // if IE, append IE to id value
	getFlashMovie(id).stopSpeaking();
}
	
function toggleSpeech(id, state) {
	identity = document.getElementById(id);
	//var speakID = (browserCheck == 1) ? "speakIE" : "speak";
	if (state == 'over') {
		identity.src = (identity.alt == "Start speaking") ? identity.src = "images/speak_focus.gif" : identity.src = "images/mute_focus.gif";
	}
	if (state == 'out') {
		identity.src = (identity.alt == "Start speaking") ? identity.src = "images/speak.gif" : identity.src = "images/mute.gif";
	}
	if (state == 'on') {
		if (identity.alt == "Start speaking") {
		identity.src = "images/mute_focus.gif";
		identity.alt = "Stop speaking";
		startSpeaking('speak');
	} else {
		identity.src = "images/speak_focus.gif";
		identity.alt = "Start speaking";
		stopSpeaking('speak');
		}
	}
}
	
function resetSpeechButton(id) {
	var identity = document.getElementById(id);
	identity.src = "images/speak.gif";
	identity.alt = "Start speaking";
}

function writeSpeechButton() {
speechButtonString = '<input type="image"  src="images/speak.gif" alt="Start speaking" id="speechButton" style="border-width: 0" width="100" height="100" '+
'onmouseover="toggleSpeech(\'speechButton\', \'over\')" '+
'onmouseout="toggleSpeech(\'speechButton\', \'out\')" '+
'onfocus="toggleSpeech(\'speechButton\', \'over\')" '+
'onblur="toggleSpeech(\'speechButton\', \'out\')" '+
'onclick="toggleSpeech(\'speechButton\', \'on\')" />';
document.write(speechButtonString);
}

function speakOnload() {
	setTimeout('toggleSpeech(\'speechButton\', \'on\')', 300);
}

// function activate
// Overlays current image selection with higlight image (150_highlight.gif)
// If speech is turned on, speaks current selection as well
function activate(id) {
	var identity = document.getElementById(id);
	identity.src = "images/150_highlight.gif";
	if (speakAutomatically == true && readyToSpeak == true) {
		speechCode = id.toUpperCase();
		speakString = "speak" + speechCode;
		startSpeaking(speakString);
	}
}

// function deactivate
// Removes highlight image set in function activate
// stops speech
function deactivate(id) {
	var identity = document.getElementById(id);
	identity.src = "images/150_blank.gif";
	if (speakAutomatically == true) {
		speechCode = id.toUpperCase();
		speakString = "speak" + speechCode;
		stopSpeaking(speakString);
	}
}