checkerid = window.setInterval("check()",250)	
function stopNow(){
	timeID = 0
	ap.controls.pause()
	playing = false
}
function stopNow2(){
	timeID2 = 0
	ap2.controls.pause()
	playing = false
	
 
}

function dontgohere(){
	alert('howdy')
	//document.body.style.cursor = 'not-allowed';
}

function playAt(value){
	ap.controls.currentPosition = value;
	ap.controls.play()
	
}
function playAt2(value){
	ap2.controls.currentPosition = value;
	ap2.controls.play()

}

function play(){
	ap.controls.play()

}

function progressUpdate(){

	if (ap.playState == 3){
		loaded = true;
		stopAt(times[0]-.4)
		 window.clearInterval(checkerid );
		document.getElementById('MESSAGE').innerHTML = ""
	}
	else if (ap.playState == 10){
		loaded = true;
		 window.clearInterval(checkerid );
	}
}
function check(){
	ap  = document.getElementById('player')	
	if (ap){
		
		playerChange()
	}
}

var virgin = true;
var checkerid;
function playerChange(){
	if (!virgin){
		if (ap.playState == 3){
			if (toStopAt != -1){
				stopAt(toStopAt)			
			}
		}	
	}
	else{
	
		window.clearInterval(checkerid )
		ap  = document.getElementById('player')	
		ap2  = document.getElementById('player2')
		//alert('ap.playState' + ap.playState)	
		loaded = true;
		virgin = false
		if (ap.playState == 3){
			document.getElementById('MESSAGE').innerHTML = "-"
			loaded = true;
			stopAt(times[0] - .4)
		}
		else if (ap.playState == 10){
			loaded = true;
		}	
		else {
//			document.getElementById('MESSAGE').innerHTML = "loading sound..."
			checkerid  = window.setInterval("progressUpdate()", 250);
		}	
	
	}
}

function set() {
	ap  = document.getElementById('player')	
		ap2  = document.getElementById('player2')
}

/********/

function activateQuizModeSet(){
	activateQuizMode();
}



if (document.all) { 
	docObj = "document.all."
	styleObj = ".style"
	ie =true
}
else
{
	docObj = "document."  
	styleObj = ""
	ie =false
}



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;
	}

}
var ctrldown = false;
var _quizModeOn = false;
var hover_over_array;
function toggleQuizMode(){
	//alert('quiz_button' + quiz_button )
	//quiz_button = document.getElementById("quiz_button");

	if (quiz_button){
		if (_quizModeOn){
			deactivateQuizMode();
		}
		else{
			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 

//headerstring1="<html><head><title>Definition</title><body><center><form method=POST action=\'/servlet/FirstServlet\' name=\'form\' onsubmit=\'return verify();\'><input type=\'hidden\' name=\'text\' value=\'";

//headerstring2="\'><br><input type=\'submit\' value=\'Copy to Account\'></form></center>"; endstring="</body></html>";

//header and footer for definitions
//definitionheader="";
//definitionfooter="<br>";

//creates a popup window when you click on the definition link
function display(value) {
	/*
	dude = eval("t"+value) 
	dude2 = eval("f"+value) 
//def = "<table cellpadding=\\'2\\' cellspacing=\\'2\\' border=\\'0\\' width=\\'100%\\'><tr><td valign=\\'top\\' width=\\'50%\\'><b>"+ dude + "</b></td><td valign=\\'top\\' align=\\'left\\'>" + dude2+ "<br> </td> </tr></table>"
	def = "<b>"+ dude + "</b> -   " + dude2

	message=headerstring1 +def + headerstring2 + def  + endstring
//alert('hi')
	newwindow= window.open('', 'Definition', 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,copyhistory=no,width=350,height=300' );
	

	
	newwindow.document.open()
	newwindow.document.write(message)
	newwindow.focus()*/
}

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('clearTimer()', 100);

    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 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)			
		}
		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)				
			 }
			
		}
	}
}

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 show_popup = true;
var new_form = false;
function move(evt,value) {
	if (show_popup)
			popUp(evt,"A"+value)
	else if (evt.ctrlKey){
		popUp(evt,"A"+value)
	}
}
function play(evt,value) {

	if (evt.ctrlKey){
		alert(ap.settings.volume);
	
	}
	if (!genderMode){
		if (!new_form)
			popUp(evt,"A"+value)
		if (loaded ){

			if (playing){
				if (playingSeg == value){
					return;					
				}
				else{
					window.clearTimeout(timeID)
					stopNow()
				}
			}
			else{
				//window.clearTimeout(timeID)
				//stopNow()
			}
			window.setInterval("playing = false;", 250);
			playingSeg = value
			playing = true
			
			if (value == -1){
				playAt(0)
				stopAt(times[0] - .05 )
			}
			else {	
				toPlay = times[value];
				playAt(toPlay)
				//alert(toPlay);
				//stop = times[value + 1] - toPlay;
				stop = (times[value + 1] - toPlay) - .03;
				//alert(stop);
				stopAt(stop )
			}
		}

	}
	else {
		if (evt.ctrlKey)	{
		popUp(evt,"A"+value)
	}
	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)
		}
       	}
	}




}