	var currentWidth = 0;	
	var isiPhone = false;
	if(navigator.platform.indexOf("iPhone") != -1 || navigator.platform.indexOf("iPod") != -1){
		isiPhone = true;
	}
	addEventListener("load", function()
	{
	    if(isiPhone){
			setTimeout(updateLayout, 0);
		} else {
			initNon();
		}
	}, false);
	function initNon(){
		document.getElementById('CB').onclick = crackCookie;
		document.getElementById('CA').onclick = createCookie;
		var div = document.createElement('DIV');
		div.style.color = "red";
		var txt = document.createTextNode('No iPhone? That\'s ok, click on the cookie to see your fortune!');
		div.appendChild(txt);
		document.getElementById('instructions').appendChild(div);
	}
	function get_random(arrayLength)
	{
	    var ranNum= Math.floor(Math.random()*arrayLength);
	    return ranNum;
	}
	function updateLayout()
	{
	    if (window.innerWidth != currentWidth && isiPhone)
	    {
	        currentWidth = window.innerWidth;
	        var orient = currentWidth == 320 ? "profile" : "landscape";
	        document.body.setAttribute("orient", orient);
				if(orient == "landscape"){
					crackCookie();
				} else {
					createCookie();
				}
	        setTimeout(function()
	        {
	            window.scrollTo(0, 1);
	        }, 100);            
	    }
	}
	function luckyNumbers(){
		var numStr = '';
			for(var i=0;i<5;i++){
				numStr = numStr + get_random(100);
				if(i<4){
					numStr = numStr + '&nbsp;-&nbsp;';
				}
			}
		return numStr;
	}
	function crackCookie(){
		var theme = document.getElementById('theme').value;
		var output = '';
		if(theme == "numbers"){
			output = luckyNumbers();
		} else {
			var whichQuote = get_random(fortuneArray[theme].length);
			output = fortuneArray[theme][whichQuote];
		}
		document.getElementById('fortuneTXT').innerHTML = output;				
		document.getElementById('CB').style.visibility = "hidden";
		document.getElementById('CA').style.visibility = "visible";
		document.getElementById('instructions').style.visibility = "hidden";
	}
	function createCookie(){
		document.getElementById('CA').style.visibility = "hidden";
		document.getElementById('instructions').style.visibility = "visible";
		document.getElementById('CB').style.visibility = "visible";
	}
	setInterval(updateLayout, 1400);