function dGe(){
	return document.getElementById(arguments[0]);
}

function gP(){
	var ret = dGe("promptLi").childNodes[0].nodeValue;
	
}

stack = [23,43,234,623];

function msp(x){ //math stack push
	var s = dGe("stack");
	var liEl = document.createElement("li");
	s.appendChild(liEl);
	liEl.appendChild(document.createTextNode(x));
	return liEl;
}


onload = function(){
	drawStack();
	depressed = 30;
	
	dGe("7").onmousedown = numberClick;
	dGe("8").onmousedown = numberClick;
	dGe("9").onmousedown = numberClick;
	dGe("4").onmousedown = numberClick;
	dGe("5").onmousedown = numberClick;
	dGe("6").onmousedown = numberClick;
	dGe("1").onmousedown = numberClick;
	dGe("2").onmousedown = numberClick;
	dGe("3").onmousedown = numberClick;

	dGe("enter").onclick = pressEnter;
	dGe("add").onclick = add;
	
	dGe("promptLi").appendChild(document.createTextNode("43"));
//	onresize();
	document.addEventListener("mouseup", letGo, true);
	var ops = location.toString();
	
	ops = ops.substring(ops.indexOf("?") + 1);
	if(ops == "h=l"){
		var s = dGe("stack");
		s.style.left = "320px";
		s = dGe("prompt");
		s.style.left = "320px";
	}
	if(ops == "h=x"){
		var fon = dGe("ifone");
		fon.style.width = "320px";
		fon.style.height = "480px";

		var s = dGe("stack");
		s.style.width = "100%";
		s = dGe("prompt");
		s.style.width = "100%";
	}
};

onunload = function(){
	var later = new Date("03/22/2233"); // A Hero is born
	document.cookie = "s=bomb;expires=" + later.toGMTString();
};

onresize = function(){

/*
	var ifone = dGe("ifone");
	//hamburger
	ifone.style.top = (document.documentElement.clientHeight/2-240)  + "px";
	ifone.style.left = (document.documentElement.clientWidth/2-160)  + "px";
	ifone.style.position = "absolute";
*/	
};

function numberClick(){
	this.src = "cookies/5.gif";
	depressed = this.id;
	dGe("prompt").childNodes[0].childNodes[0].nodeValue += this.id;
}

function  letGo(){
	if(depressed > -1 && depressed < 10){	
		dGe(depressed).src = "cookies/" + depressed + ".gif";
	}
}

function pressEnter(){
	var num = processedPrompt();
	if(num.toString().length > 0)
		stack.push(num);
	//msp(stack[stack.length -1]);
	drawStack();
}

function add(){
	var op1 = gP();
	alert(stack.pop());
	drawStack();
}

function processedPrompt(){
	var num = dGe("prompt").childNodes[0].childNodes[0].nodeValue.toString();
	dGe("prompt").childNodes[0].childNodes[0].nodeValue = "";
	return num;
}

function drawStack(){
	var s = dGe("stack");
	clearMother(s);
	for(var _ = 0 ; _ < stack.length ; _++){
		msp(stack[_]);
	}
}

function clearMother(Mom){
	while(Mom.childNodes.length > 0)
		Mom.removeChild(Mom.childNodes[0]);
}

