var onImg;
var topVal = 0;
var leftVal = 350;

var ivl = false;

function sync(pBtn, pIndex) {
	parent.nav.location.href='navA.html';
	ivl = setInterval("if(top.navA_loaded){parent.nav.buttonIndex=" + pIndex + ";parent.nav.newFwd('"+ pBtn +"');clearInterval(ivl)}",1000);
}

function toggleVis(curElem){
	var dom = document.getElementById ? document.getElementById(curElem) : eval('document.all.' + curElem);
	dom.style.visibility = dom.style.visibility == 'hidden' ? 'visible' : 'hidden';
}

function moveElement(mLeft){
	var dom = document.all ? document.all.slider : document.getElementById('slider');
	dom.style.left = mLeft;
}

function moveTime(mTop,mLeft){
	var dom = document.all ? document.all.timeBox : document.getElementById('timeBox');
	dom.style.top = mTop;
	dom.style.left = mLeft;
}

function getDomEvent(ev){
	topVal = ev.clientY;		
	leftVal = ev.clientX;		
}

function locate(which){
	if (onImg=="1"){
		if (window.event){
			topVal = window.event.y;
			leftVal = window.event.x - 1;
		}
		var curr = which-8;
		currSec = 28800 + curr * 300;
		var hours; var minutes; var seconds;
		hours = Math.floor (currSec / 3600);
		minutes = Math.floor ((currSec - (hours * 3600)) / 60);
		seconds = Math.floor (currSec - (hours * 3600) - (minutes * 60));
		if (minutes<10)	minutes = '0'+minutes;
		if (hours>11) m = " PM";
			else m = " AM";
		if (hours>12) hours = ' '+(hours-12);
			
		if (which<details[6].length-2) {		
			var val = (which*2)-9;
			var chg = (which*2)-8;
			if (details[8][val])
				document.index_form.index_value.value = addCommas(details[8][val]);
			else
				document.index_form.index_value.value = "N/A";
			if (details[8][chg])
				document.index_form.index_change.value = details[8][chg];
			else
				document.index_form.index_change.value = "N/A";
		
			document.index_form.perc_change.value = calculatePercentChange(details[8][val], details[8][chg]);
			
			document.ratio1_form.ratio1_delta.value = rnd(details[6][which]) + '%';
			document.ratio1_form.ratio1_cum.value = rnd(details[4][which]) + '%';
		
			document.ratio2_form.ratio2_delta.value = rnd(details[7][which]) + '%';
			document.ratio2_form.ratio2_cum.value = rnd(details[5][which]) + '%';
		} else {
			document.index_form.index_value.value = "N/A";
			document.index_form.index_change.value = "N/A";
			document.index_form.perc_change.value = "N/A";
			
			document.ratio1_form.ratio1_delta.value = 'N/A';
			document.ratio1_form.ratio1_cum.value = 'N/A';
				
			document.ratio2_form.ratio2_delta.value = 'N/A';
			document.ratio2_form.ratio2_cum.value = 'N/A';
		}						
		document.ratio1_form.ratio1_delta_avg.value = rnd(details[0][which]) + '%';
		document.ratio2_form.ratio2_delta_avg.value = rnd(details[1][which]) + '%';
		moveElement(312+which*3);
		moveTime(topVal+20,(leftVal<530 ? 322 : 222)+which*3);
				
		document.forms[0].time.value = details[8][1] + ' ' + hours + ':' + minutes + m;
	}
}

function doLoad(pIndex) {
	if(details && snapshot){
		which = details[6].length-11;
		document.forms[0].time.value = details[8][1]+" "+time;
		moveElement(336+(which*3))
		if (which<70){
			moveTime(40,346+which*3)
	    } else {
			moveTime(40,346+which*3-82)
		}
		toggleVis('slider');
		toggleVis('timeBox');
		document.index_form.index_value.value = addCommas(snapshot[pIndex][9]);
		document.index_form.index_change.value = snapshot[pIndex][10];
		document.index_form.perc_change.value = calculatePercentChange(snapshot[pIndex][9], snapshot[pIndex][10]);
	    document.ratio1_form.ratio1_delta.value = rnd(snapshot[pIndex][7])+'%';
		document.ratio1_form.ratio1_cum.value = rnd(snapshot[pIndex][5])+'%';
		document.ratio1_form.ratio1_delta_avg.value = rnd(snapshot[pIndex][1])+'%';
		
		document.ratio2_form.ratio2_delta.value = rnd(snapshot[pIndex][8])+'%';
		document.ratio2_form.ratio2_cum.value = rnd(snapshot[pIndex][6])+'%';
		document.ratio2_form.ratio2_delta_avg.value = rnd(snapshot[pIndex][2])+'%';
	}
	if(document.getElementById && !window.event){
		document.getElementById('ctrlLayer').addEventListener("mousemove", getDomEvent, true);
	}
}

function helpWin(){
	newWindow = window.open("help/framesetDet.html","Help",	"toolbar=no,location=no,scrollbars=no,width=600,height=300,left=0,top=0, status=yes");
	newWindow.focus()	
}

