// JavaScript Document

var previousAya = "NONE";
var currentAya = "txt1";
var backgroundColor = '#FFF58F'; //'#C4ECBD';

function goThere(){
	//var list=document.select.chapter;
	location="index.php?id="+document.getElementById("chapter").value+"&reciterID="+getReciter()+"&fontID="+getFont();//list.options[list.selectedIndex].id;
}

function selectAndPlayAya(){

	var ayaNumber = document.getElementById("verse").value;
	ayaNumber="txt"+ayaNumber;
	//alert(ayaNumber);
	
	selx(ayaNumber);
	scrollDivDown(ayaNumber);
	loadFile();
}
	
function sel(current){

	previousAya = currentAya;
	currentAya = current.id;
	
	var len = currentAya.length;
	var ayaNum = currentAya.substring(3,len);
	document.getElementById("verse").value = ayaNum;
	
	document.getElementById(currentAya).style.backgroundColor = backgroundColor;
	document.getElementById(previousAya).style.backgroundColor='';
	
	loadFile();
}

function selx(current){

	previousAya = currentAya;
	currentAya = current;
	
	document.getElementById(currentAya).style.backgroundColor=backgroundColor;
	document.getElementById(previousAya).style.backgroundColor='';
	

	//Get object
	//var SupportDiv = document.getElementById(current);
	 
	//Scroll to location of SupportDiv on load
	//window.scroll(findPos(SupportDiv), 0);
	
	var len = current.length;
	var nextElement = current.substring(3,len);
	nextElement = parseInt(nextElement);
	//nextElement++;
	//alert(nextElement);
	//ScrollToElement("txt"+nextElement);
	scrollDivDown("txt"+nextElement);
}

//Finds y value of given object
function ScrollToElement(theElement){

  var selectedPosX = 0;
  var windowHeight = alertSize();
  //alert(windowHeight);
  var selectedPosY = 0;
  
  
              
  while(theElement != null){
    selectedPosX += parseInt(document.getElementById(theElement).offsetLeft);
	//var diff = document.getElementById(theElement).offsetTop+selectedPosY;
    selectedPosY = document.getElementById(theElement).offsetTop+selectedPosY;
    theElement = theElement.offsetParent;
  }
  
 window.scrollTo(selectedPosX,selectedPosY);

}

function scrollDivDown(id){
var positionY = document.getElementById(id).offsetTop;
var w = document.getElementById('changer').selectedIndex;
var fontName = document.getElementById('changer').options[w].text;
if(fontName="Courier")
	document.getElementById("middleFrame").scrollTop=(positionY-80);
else
	document.getElementById("middleFrame").scrollTop=(positionY-30);
//alert(x);
//timerDown=setTimeout("scrollDivDown('scroll')",10);
}


function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return myHeight;
}

function selectedx(x, lenght){

	for(i=1; i<=lenght; i++)
	{
		var elementA = "txt"+i;
			if(x == elementA)
				document.getElementById(elementA).style.backgroundColor=backgroundColor;
			else
				document.getElementById(elementA).style.backgroundColor='';
	}
}

function selectedMover(x){
	x.style.backgroundColor=backgroundColor;
}

function selectedMout(x){
	x.style.backgroundColor='';
}

function getReciter(){
	var reciter = document.getElementById("reciter").value;
	return reciter;
}

function getFont(){
	var reciter = document.getElementById("changer").value;
	return reciter;
}