

function status(toDisplay){
	var status = document.getElementById("status");
	status.innerHTML = toDisplay;
}
var ts = 0

function stopNow(){
	timeID = 0
	ap.Stop()
	playing = false
	
 
}
function stopNow2(){
	timeID = 0
	ap2.stop()
	playing = false
}

function playAt(value){
	//status("Playing " + value);
		//log = log + value + "\r\n";
		if (ts == 0)
			ts = ap.GetTimeScale()
		ap.SetTime(value * ts);
		ap.Play()

}

function playAt2(value){
	if (ts == 0)
		ap2.GetTimeScale()
	ap2.SetTime(value * ts);
	ap2.Play()
		
}
function play(){
	ap.Play()

}

function loaded(){
	/*isMac = navigator.userAgent.indexOf("Mac");
	if (isMac != -1){
		isSafari = navigator.userAgent.indexOf("AppleWebKit");
		if (isSafari != -1 || ie){
			errorMsg = document.getElementById("error_msg")
			if (errorMsg)
				errorMsg.innerHTML = "<div style='text-align: left; margin-bottom: 20px; border: 2px #FFFF00 solid; padding: 5px; background: #FFFF99; width: 550px' >In order to fully take advantage of this site, it is recommended that you use a <a href='http://www.mozilla.org/'>Mozilla browser</a> such as FireFox. Presently,  Safari or the Macintosh Internet Explorer don't allow scripts to communicate with plugin-ins. This is necesary for the interactive sound component of the site.</div>"
		}
	}*/
}

function set() {
try{
	loaded = true;
	if (ie){
			ap  = document.getElementById('player')
			ap2  = document.getElementById('player2')
		}
		else{	
			//ap  = document.getElementById('player')
			ap  = document.embeds[0];//document.player
			ap.Play()
			stopAt(times[0] - .1)
			ap2  = document.player2
		}
	}
	catch(e){
		//checkerid  = window.setInterval("progressUpdate()", 250);
		//alert("hi" + e)
	}
	
}



/*************/


function activateQuizModeSet(){
	activateQuizMode();
}



if (document.all) { 
	docObj = "document.all."
	styleObj = ".style"
	ie =true
}
else
{
	docObj = "document."  
	styleObj = ""
	ie =false
}
var controlKeyDown = false;
var savedHTML;
function keyUp(e){
	if (ie)
		e = window.event
	value = e.keyCode
	if (value == 17){
		controlKeyDown = false
		var pop_up = document.getElementById("popup");
		if (pop_up.style.visibility = "visible"){
			pop_up.innerHTML = savedHTML;
		}
		pop_up.style.background = "#DDDDFF"
	}

}
var log = "";
function keyListener(e){
	if (ie)
		e = window.event
	value = e.keyCode;
	if (value == 81){ // q key
		toggleQuizMode()		
		if (_quizModeOn)
			quiz_button.checked = true;
		else quiz_button.checked = false;
	}
	else if (value == 17){
		if (!controlKeyDown){
			controlKeyDown = true
			var pop_up = document.getElementById("popup");
			if (pop_up.style.visibility = "visible"){
				savedHTML = pop_up.innerHTML;
				pop_up.innerHTML = eval('e' + savedValue);
			}
			pop_up.style.background = "pink";	
		}
	}

}
var ctrldown = false;
var _quizModeOn = false;
var hover_over_array;
function toggleQuizMode(){
	quiz_button = document.getElementById("quiz_button");
	if (quiz_button){
		if (_quizModeOn){
			quiz_button.value = "Quiz Mode";
			deactivateQuizMode();
		}
		else{
			quiz_button.value = "Normal Mode";
			activateQuizMode();
		}
	}

	
}


function activateQuizMode() {
	_quizModeOn = true;

	hover_over_array = new Array()
	for (i = 0; i < hoverover_total; i++){
		element = document.getElementById('h' + i);
		hover_over_array.push(element.innerHTML);
		element.innerHTML = "******";
	}

}
function deactivateQuizMode() {
		_quizModeOn = false;
	for (i = 0; i < hoverover_total; i++){
		document.getElementById('h' + i).innerHTML = hover_over_array[i];
	}

}
function hoverOver(evt,value) { 
	hoverOver2(evt, value, value + 1);
}
function hoverOver2(evt,value, hoverIndex) { 
	newid = "h" +  hoverIndex
	if (_quizModeOn & evt.ctrlKey){
		document.getElementById(newid).innerHTML = hover_over_array[hoverIndex];
		ctrldown = true;		
	}
	if (clearid != -1)
		window.clearTimeout(clearid)
	if (id != newid){		
		playSound(evt,value);
		id = newid;
		currentvalue = value;		
	}
	if (ie)
		document.getElementById(newid).style.color = "#9900FF";
}
id = -1;
var currentvalue = -1;
function clearID(){	
	id = -1;
}
var clearid = -1;
function hoverOut(){
	if (ie)
		document.getElementById(id).style.color = "#152588";		
	clearid = setTimeout("clearID()",200);
	
	if (_quizModeOn & ctrldown){
		document.getElementById(id).innerHTML = "******";
		ctrldown = false;
	}
}

var loaded = false
var paused = false
var playing = false

var ap 
var ap2 

function display(value) {
	
}

showtimeID = 0
showtimeID2 = 0
timeID = 0
timeID2 = 0
function startExit(){

if (showtimeID != 0)
	window.clearTimeout(showtimeID)
	showtimeID = setTimeout("noHover()",750);	
}

function startExit2(){
	if (showtimeID2 != 0)
		window.clearTimeout(showtimeID2)
	showtimeID2 = setTimeout("noHover2()",750);	
}

var popDownTables = [''];

function generate(event, idie, launch, finalCountdown) {
        if (showtimeID != 0)
	  window.clearTimeout(showtimeID)

	inBetween = finalCountdown - launch;
        if (inBetween > 24) {
	  if (popDownTables[0].length == 0) {
	    var nextLinkRow = getMoreWords(1, launch + 25, finalCountdown, 'Below');
	    generatePopdown(launch, launch + 24, 24, nextLinkRow, "");          
	    popDownTables[0] = generated;
	  } else {
	    generated = popDownTables[0];
	  }
        } else {
	  if (popDownTables[0].length == 0) {
            generatePopdown(launch,finalCountdown,inBetween, "", "")
            popDownTables[0] = generated;
          } else {
            generated = popDownTables[0];
          }
        }

        dropDown(event, idie)

}

function generateWithIndex(event, launch, finalCountdown, index) {
  if (timeId == 0) {
    timeId = window.setInterval('advanceSlide()', 100);
 window.clearTimeout(showtimeID)

    if (popDownTables.length > index) {
      generated = popDownTables[index];
    } else {
      var previousLinkRow = getMoreWords(index - 1, 0, 0, 'Above');
      inBetween = finalCountdown - launch;
      if (inBetween > 21) {
	var nextLinkRow = getMoreWords(index + 1, launch + 22, finalCountdown, 'Below');
	generatePopdown(launch, launch + 21, 21, nextLinkRow, previousLinkRow);
	popDownTables[index] = generated;
      } else {
	generatePopdown(launch,finalCountdown,inBetween, "", previousLinkRow, true)
      }
    }
    showie.innerHTML = generated
  }
}

var timeId = 0;

function clearTimer() {
  if (timeId != 0) {
    window.clearInterval(timeId);
    timeId = 0;
  }
}

function getMoreWords(index, start, end, type) {
  var js = "generateWithIndex(event, " + start + ", " + end + ", " + index + ")";
  return "<tr  onMouseOver='" + js + "'><td colspan=2 align=center><a href='javascript:" + js + "'>View Words " + type + "&nbsp;&nbsp;<img border=no src='/images/" + type + "arrow.gif'></a></td></tr>";
}

function generatePopdown(launch, finalCountdown, inBetween, nextLinkRow, previousLinkRow, isFullSize){
  generatePopDown(launch, finalCountdown, inBetween, nextLinkRow, previousLinkRow, false);
}

function generatePopdown(launch, finalCountdown, inBetween, nextLinkRow, previousLinkRow, isFullSize){
	generated = ""
	generated += "<table bgcolor='#FFFFCC' cellspacing=0 cellpadding=0 width=600 border=0 ><tbody>" + previousLinkRow + "<tr><td valign='top' ><table cellpadding='2' cellspacing='2' border='0' width='100%'><tbody><tr><td valign='top'>"
	half = inBetween / 2
	num = Math.floor(half )
	if (num < half)
		num ++
	num = num + launch
	var rows = 0;
	for(i=launch; i < num ; i++){
		value = eval('t'+ i)
		valueToCheck = eval('f'+ i)
		
		if (valueToCheck == "X" || value == "X" ){
			valueToCheck = ""
			value = ""
			subtractBy++
		}
		if (value == "<br>"){

			subtractBy++
		}
		if (secondSound)	{

			generated += "<tr><td><a href='javascript:display(" + i + ")'   onmouseover='playSound(event," +  (i -subtractBy) +", true)'>" + value +"</a></td><td><i>" + valueToCheck +"</i></td>"
		}
		else{
			generated += "<tr><td><b>" + value + "</b></td><td><i>" + valueToCheck + "</i></td>"
		}
		rows++;
	

	}
	if (isFullSize) {
	  addRows(rows);
	}
	rows = 0;

	generated += "</td></tr></tbody></table></td><td valign='top'><table cellpadding='2' cellspacing='2' border='0' width='100%'><tbody><tr><td valign='top'>"
	for(i=num; i <  finalCountdown; i++){
		value = eval('t'+ i)
		valueToCheck = eval('f'+ i)
		
		if (valueToCheck == "X" || value == "X" ){
			valueToCheck = ""
			value = ""			
			subtractBy++
		}
		if (value == "<br>"){

			subtractBy++
		}

		if (secondSound)	{
			generated += "<tr><td><a href='javascript:display(" + i + ")'   onmouseover='playSound(event," + (i -subtractBy) +", true)'>" + value  +"</a></td><td><i>" + valueToCheck +"</i></td>"
		}
		else{
			generated += "<tr><td><b>" + value  +"</b></td><td><i>" + valueToCheck +"</i></td>"
		}
	  	rows++;
	

	}
	if (isFullSize) {
	  addRows(rows);
	}
	
	generated += "</td></tr> </tbody></table></td></tr><tr><td valign='top' colspan='2'>"
	if (note != "X"){
		generated += "<tr><td colspan='2'><div align='center'>" + note  + subtractBy+"</div></td></tr>"
	}

	generated += "</td></tr>" + nextLinkRow + "</tbody></table>"
}

function addRows(rows) {
  while (rows < 12) {
    rows++;
    generated += "<tr><td>&nbsp;</td></tr>";
  }
}

var subtractBy = 0

function stopAt(value) {
	if (timeID != 0)
		window.clearTimeout(timeID)
	timeID = setTimeout("stopNow()",value *1000);		
}

function stopAt2(value) {
	if (timeID2 != 0)
		window.clearTimeout(timeID2)
	timeID2 = setTimeout("stopNow2()",value *1000);	
	
}

function play(evt, ggg, gen) { 

	if (genderMode){		
		if (gen == 'm'){
			popUp(evt, 'ab')	
		}
 		else{
          		popUp(evt, 'ac')
		}
	}
	else{
          	play(evt, ggg)
	}
}

function popUp(evt, ggg) { 
	id = ggg
	if (ie){
		
		if (document.body.clientWidth < evt.x + 151){
			xc = parseInt(evt.x) - 150
		}
		else xc = parseInt(evt.x)
		if (document.body.clientHeight < evt.y + 60){
			xy = parseInt(evt.y) - 60
		}
		else xy = parseInt(evt.y)
		popUpWin = eval(docObj + ggg + styleObj)
		 popUpWin.top = xy + 20 + document.body.scrollTop
  	 	popUpWin.left = Math.max(2, xc) +20 
		popUpWin.visibility = "visible"  
		popUpWin.status = ""
	}
   else{
   		if (window.innerWidth < evt.pageX + 150){
			xc = evt.pageX - 150

	}
	else xc = evt.pageX + 10

	if (window.innerHeight  + window.pageYOffset < evt.pageY + 80){
		xy = evt.pageY - 80

	}
	else xy = evt.pageY  + 20

	document.getElementById(id).style.top = xy;
	document.getElementById(id).style.left = xc +3; 

          document.getElementById(id).style.visibility = 'visible'

	}


}


function popDown() {
	 document.getElementById(id).style.visibility =  "hidden"
	//playingSeg = -1
	
}

function hover(){
	if (showtimeID != 0)
		window.clearTimeout(showtimeID)
	if (showtimeID2 != 0)
		window.clearTimeout(showtimeID2)
	hovering = true;
}

function 	noHover(){
 document.getElementById( 'Show').style.visibility =  "hidden"

}
function 	noHover2(){
 document.getElementById( 'Show2').style.visibility =  "hidden"

}
function showPopup(evt,value) {

		popUp(evt,value)
		
}


function showComment(evt,value) {
	var comment = document.getElementById('comments')
	comment.innerHTML = "" + eval(value);
	popUp(evt,'comments');
}

function showPopupDisplay(evt, value) {
	id = value;
	var comment = document.getElementById('popup')
	comment.innerHTML = "" + eval(value);
	popUp(evt,'popup');
}


function show(evt,value) {
		popUp(evt,"A"+value)
		
	}

function playSound(evt,value) {
	playSound(evt,value,false) 
}

var toStopAt = -1;
function playSound(evt,value,secondTimes) {
	if (loaded ){
		playingSeg = value
		if (value == -1){
			playing = true
			toStopAt = times[0] -.1;
			playAt(0)
			stopAt(toStopAt)			
		}
		else {	
			if (secondTimes){
				playing = true
				toPlay = times2[value];
				playAt2(toPlay)
				stop = times2[value + 1] - toPlay;
				stopAt2(stop )
			}
			else{				
				if (playing){
					window.clearTimeout(timeID)
					stopNow();
				}
				playing = true
				toPlay = times[value];
				toStopAt = times[value + 1] - toPlay;
				playAt(toPlay)
				stopAt(toStopAt - .05)
			 }
			
		}
	}
}

function startTimer(){
	popDown('')
}
function dropDown(evt, ggg) { 
	showie = document.getElementById(ggg);
	showie.innerHTML = generated
	id = ggg
	if (ie){
		
		popUpWin = eval(docObj + ggg + styleObj)
		popUpWin.top = document.body.scrollTop + 75;
  	 	popUpWin.left = 70;
		popUpWin.visibility = "visible"  
		popUpWin.status = ""
	}    
	else{
		document.getElementById(id).style.top = 50;
		document.getElementById(id).style.left = 70; 
		document.getElementById(id).style.visibility = 'visible'
	}
}

var playingSeg 
var timeID
var id;
var showPopups = true;
var new_form = false;
var englishPopupOn = false;
var newForm = false;
function move(evt,value) {
	if (showPopups){
		if (newForm){
			if (controlKeyDown)
				showPopupDisplay(evt,"e"+ value)
			else showPopupDisplay(evt,"a"+ value)
		}
		else popUp(evt,"A"+value)
	}

}

var savedValue
function play(evt,value) {

	if (!genderMode){
		if (showPopups){
			if (newForm){
				savedValue = value;
				if (controlKeyDown)
					showPopupDisplay(evt,"e"+ value)
				else showPopupDisplay(evt,"a"+ value)
			}
			else popUp(evt,"A"+value)
		}	
		if (loaded ){
			if (timeID != 0){
				//if (playingSeg == value)
				//	return	
				//status("Stopping " + value);
				window.clearTimeout(timeID)
				//alert("hi");
				//stopNow()
			}
			playingSeg = value
			playing = true
			if (value == -1){
				playAt(0)
				stopAt(times[0] - .1 )
			}
			else {	
				toPlay = times[value];
				playAt(toPlay)
				//alert(toPlay);
				//stop = times[value + 1] - toPlay;
				stop = times[value + 1] - toPlay;
				//alert(stop);
				stopAt(stop  - .1)
			}
		}

	}
	else{

		here = eval("g" + value )

		if (here == "m"){
			popUp(evt,"MASC")
			playAt(0)
			
			stopAt(2)
		}
		else if (here == "f"){

			popUp(evt,"FEM")
			playAt(2)
			
			stopAt(4)
		}
		else if (here == "mp"){
			popUp(evt,"MP")
			playAt(4)
			
			stopAt(6)
		}
		else {	
			popUp(evt,"FP")
		

			playAt(6)
			
			stopAt(8)
		}
	}

}
