var calculation = "";
var resultDone = false;

keyFrame = 0;
		divVisible = 0;
		count = 1;
		keyFrameBack = 0;

		movingObjLeft = new Array(1);
		movingObjTop = new Array(1);
		movingObjLeftBack = new Array(1);
		movingObjTopBack = new Array(1);

		movingObjLeft[0] = new Array(-150,-140,-120,-100,-80,-60,-40,-20,0);
		movingObjTop[0] = new Array(0,0,0,0,0,0,0,0,0,0);
		movingObjLeftBack[0] = new Array(0,-20,-40,-60,-80,-100,-120,-140,-150);
		movingObjTopBack[0] = new  Array(0,0,0,0,0,0,0,0,0,0);
		function init()
		{
			divVisible = 0;
			count = 1;
			var theMenu= document.getElementById("menu");
			var thedivSlide= document.getElementById("divslide");
			var theWrapper= document.getElementById("wrapper");
			
			if (is_gecko || is_nav4up)
			{	
				if (!divVisible)
				{				
				theMenu.style.left = theWrapper.offsetLeft + theWrapper.offsetWidth+10+"px";
				}
				else
				{
				theMenu.style.left = theWrapper.offsetLeft + theWrapper.offsetWidth+10+"px";				
				}
				thedivSlide.style.left = parseInt(theMenu.style.left)+150+"px" ;
				thedivSlide.style.top = parseInt(theMenu.style.top)+"px";
			}
			else if (is_ie5up) //if IE 4+
			{
				document.all.menu.style.zIndex =-1;
				if (!divVisible)
				{theMenu.style.posLeft = theWrapper.offsetLeft + theWrapper.offsetWidth-150+10;}
				else
				{theMenu.style.posLeft = theWrapper.offsetLeft + theWrapper.offsetWidth+10;}
				
				thedivSlide.style.posLeft = theMenu.style.posLeft+150;
				thedivSlide.style.posTop = theMenu.style.posTop;
			}			
			//Default goto page (NOT NS 4+ and NOT IE 4+)posLeft
			else
			{
				document.all.menu.style.zIndex =-1;
				if (!divVisible)
				{theMenu.style.posLeft = theWrapper.offsetLeft + theWrapper.offsetWidth-150+10;}
				else
				{theMenu.style.posLeft = theWrapper.offsetLeft + theWrapper.offsetWidth+10;}
				
				thedivSlide.style.posLeft = theMenu.style.posLeft+150;
				thedivSlide.style.posTop = theMenu.style.posTop;
			}	
			theMenu.style.display ="block";
			
		}

		function slide() 
		{
			var whichOne;
			whichOne = document.all.menu.style;
			if (!divVisible)
			{			
			//theCalc.style.display ="block";
			setTimeout("slideTheObject()", 50);			
			
			keyFrameBack = 0;
			divVisible = 1;
			}	 
			else
			{
			setTimeout("slideTheObjectBack()",50);
			keyFrame = 0;
			divVisible = 0;
			
			}
		}
		
		function slideTheObject()  
		{
			var whichOne;
			whichOne = document.all.menu.style;
			var thedivSlide= document.getElementById("divslide");
			if (count<=15){
				if (is_gecko || is_nav4up)
				{
				whichOne.left = parseInt(whichOne.left)+10;
				thedivSlide.style.left = parseInt(whichOne.left)+150+"px"
				thedivSlide.style.top = parseInt(whichOne.top)+"px"
				}
				else if (is_ie5up) //if IE 4+
				{
				whichOne.posLeft += 10;
				thedivSlide.style.posLeft = whichOne.posLeft+150;
				thedivSlide.style.posTop = whichOne.posTop;}
									
				count = count+1;
				setTimeout("slideTheObject()",50);			
			}
			if (count==15)
			whichOne.zIndex = 99;
		}

		function slideTheObjectBack()  
		{
			var whichOne;	 
			whichOne = document.all.menu.style;
			var thedivSlide= document.getElementById("divslide");
			
			if (count!=1)
			{
				if (is_gecko || is_nav4up)
				{
				whichOne.left = parseInt(whichOne.left)-10;
				thedivSlide.style.left = parseInt(whichOne.left)+150+"px"
				thedivSlide.style.top = parseInt(whichOne.top)+"px"}
				else if (is_ie5up) //if IE 4+
				{whichOne.posLeft -= 10;
				thedivSlide.style.posLeft = whichOne.posLeft+150;
				thedivSlide.style.posTop = whichOne.posTop;}
				
				count = count-1;
				setTimeout("slideTheObjectBack()",50);
			}
			if (count==15)
			whichOne.zIndex = 10;
		}
		
function addToCalc(val)
{
	if(isNaN(val) && isNaN(calculation.substring(calculation.length-1, calculation.length)))
		return false;
		
	if(!isNaN(val) && resultDone)
	{
		resetCalc();
		resultDone = false;
	}
	else if(isNaN(val) && resultDone)
	{
		resultDone = false;
	}
	calculation += val;
	showResult();
}
function addToCalcDirect(val)
{
	calculation = val;
}
function resetCalc()
{
	calculation = "";
	showResult();
}
function positiveNegative()
{
	if(calculation.substring(0, 1) == "-")
		calculation = calculation.substring(1, calculation.length);
	else
		calculation = "-" + calculation;
	showResult();
}
function calculate()
{
	if(calculation != "")
	{
		try
		{
			calculation = eval(calculation);
		}
		catch(e)
		{ 
			reportError("Error!");
		}
		resultDone = true;
		showResult();
	}
	else
		return false;	
}
function percentage()
{
	try
	{
		calculation = eval(calculation) / 100;
	}
	catch(e)
	{
		reportError("Error!");
	}
  	resultDone = true;
	showResult();
}
function squareRoot()
{
	try
	{
		calculation = Math.sqrt(eval(calculation));
	}
	catch(e)
	{ 
		reportError("Error!");
	}
	resultDone = true;
	showResult();
}
function showResult()
{
	calculation = calculation.toString();
	if(calculation == "NaN")
	{
		reportError("Error!");
	}
	else
	{
		document.getElementById("result").value = calculation;
	}
}
function reportError(msg)
{
	calculation = msg;
	document.getElementById("result").value = msg;
}
function closeCalculator()
{
	document.getElementById("calculator").style.display = "none";
}
function about()
{
	msg = "Calculator\n=============\n\n";
	alert(msg);
}
var ie = document.all;
var ns6 = document.getElementById && !document.all;
var dragapproved=false;
var z, x, y;

function move(e)
{
	if (dragapproved)
	{
		z.style.left=ns6? temp1+e.clientX-x: temp1+event.clientX-x;
		z.style.top=ns6? temp2+e.clientY-y : temp2+event.clientY-y;
		return false;
	}
}

function drags(e)
{
	if (!ie&&!ns6)
	return;
	var firedobj = ns6? e.target : event.srcElement;
	var topelement = ns6? "HTML" : "BODY";
	while (firedobj.tagName != topelement&&firedobj.className != "drag")
	{
		firedobj = ns6? firedobj.parentNode : firedobj.parentElement;
	}
	if (firedobj.className == "drag")
	{
		dragapproved = true;
		z = firedobj;
		temp1 = parseInt(z.style.left+0);
		temp2 = parseInt(z.style.top+0);
		x = ns6? e.clientX: event.clientX;
		y = ns6? e.clientY: event.clientY;
		document.onmousemove=move;
		return false;
	}
}
document.onmousedown=drags;
document.onmouseup=new Function("dragapproved=false");
window.onload=init;
window.onresize=init;
