function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		cookieButton_01_over = newImage("fortuneCookie/images/cookieButton_01-over.gif");
		flipCookieButton_01_over = newImage("fortuneCookie/images/flipCookieButton_01-over.gif");
		flipCookieButton_01_out = newImage("fortuneCookie/images/flipCookieButton_01-out.gif");
		closeButton_01_over = newImage("fortuneCookie/images/closeButton_01-over.gif");
		closeButton_01_out = newImage("fortuneCookie/images/closeButton_01-out.gif");
		preloadFlag = true;
	}
}

// -->

/////////////////////////////////BEGIN (my fortune cookie code)
/////////////////////////////////
/////////////////////////////////
/////////////////////////////////
/////////////////////////////////


var browserVersion = navigator.appVersion;
var re = /macintosh/gi;
var result = re.test(browserVersion);//(for use in the showFortuneIE function)
/* FOR TESTING----------------------------
alert (result);
alert (browserVersion);
if (result == true){
  alert('Ha. You are working on a macintosh.');
}else{
  alert('You are the light of the world!');
  }
*/

function showFortune() {
//alert('showFortune has been called.');
//This function is not used in IE because it won't seem to hear a function call from the onclick 
//attribute of an embed or object element.
//This 'var ignoreMe' line is here to supposedly affect the way safari handles the 'onload' command, 
//forcing it to do more before it executes the rest of this function. 
  var ignoreMe = document.body.offsetWidth;
  document.getElementById("bgCookie").style.visibility = "visible";
  document.getElementById("theFortune").style.visibility = "visible";
//this if statement is here so the following will only happen the first time the function is called.
if (flipDisplay==0){
	  var t=setTimeout("document.getElementById('close').style.display = 'block'",3000);
	  var t=setTimeout("document.getElementById('closeImage').src = 'fortuneCookie/images/closeButton_01.gif'",3000);
      var t=setTimeout("document.getElementById('switch').style.display = 'block'",3000);
      var t=setTimeout("document.getElementById('switchImage').src = 'fortuneCookie/images/flipCookieButton_01.gif'",3000);
	  flipDisplay=1;
	  }
//  alert ("function has worked");
}

/////////////////////////////////my function for dealing with the way internet explorer won't hear a function call 
/////////////////////////////////from onclick of an embed or object element. This function is called from the "callTimeOut" function.
/////////////////////////////////It also is called into play for a macintosh environment (the result==true part) which for some reason also was not hearing the 'showFortune' call.
function showFortuneIE(){
if (((navigator.appName == "Microsoft Internet Explorer")||(result == true))&&(delayFortuneAppearFlag==0)){
//  alert('showFortuneIE has been called.');
  document.getElementById('bgCookie').style.visibility = 'visible';
  document.getElementById('theFortune').style.visibility = 'visible';
//this if statement is here so the following will only happen the first time the function is called.
if (flipDisplay==0){
	  var t=setTimeout("document.getElementById('close').style.display = 'block'",1000);
	  var t=setTimeout("document.getElementById('closeImage').src = 'fortuneCookie/images/closeButton_01.gif'",1000);
	  var t=setTimeout("document.getElementById('switch').style.display = 'block'",1000);
	  var t=setTimeout("document.getElementById('switchImage').src = 'fortuneCookie/images/flipCookieButton_01.gif'",1000);  
	  flipDisplay=1;
	  }
//  alert ("function has worked");
delayFortuneAppearFlag = 1;
 }
}

/////////////////////////////////my timed call. Ideally I will organize a way for IE to make the fortune text visible only after
/////////////////////////////////the movie has loaded completely. This is an awkward workaround for the moment, setting a delay 
/////////////////////////////////of 5 seconds before IE sets the fortune text to "visible".
function callTimeOut(){
var t=setTimeout("showFortuneIE()",3000);
}

/////////////////////my baking animation timing
function detectWhenLoaded(){
 if (clickedOnceFlag == 0){
  var t=setTimeout("document.getElementById('pureDeadBrilliantFortuneCookie').style.visibility = 'visible'; document.getElementById('baking').style.visibility = 'hidden';",5000);
  clickedOnceFlag = 1;
  }else{
	  document.getElementById('pureDeadBrilliantFortuneCookie').style.visibility = 'visible';
  }
}

function flip(){
  if (flipFlag == 0){
	document.getElementById("fortuneBack").style.display = "block";
	document.getElementById("theHulai").style.display = "block";
	document.getElementById("theFortune").style.display = "none";
	flipFlag = 1;
	}else{
    document.getElementById("fortuneBack").style.display = "none";
	document.getElementById("theHulai").style.display = "none";
	document.getElementById("theFortune").style.display = "block";
	flipFlag = 0;
  }
}
var flipFlag = 0;
var flipDisplay = 0;
var bakingFlag = 0;
var fortuneFlag = 0;
var clickedOnceFlag = 0;
var delayFortuneAppearFlag = 0;

/////////////////////////////////
/////////////////////////////////
/////////////////////////////////
/////////////////////////////////
/////////////////////////////////END (my fortune cookie code)


/////////////////////////////////my function for revealing/hiding the fortune cookie
function toggleCookie(){
  if (cookieFlag == 0){
	document.getElementById("fortuneCookieExtravaganza").style.visibility = "visible";
	document.getElementById("blueSky").style.visibility = "visible";
    if(bakingFlag == 0){document.getElementById("baking").style.visibility = "visible"; bakingFlag=1;}
	if(fortuneFlag != 0){document.getElementById("theFortune").style.visibility = "visible";
						 document.getElementById("bgCookie").style.visibility = "visible";}
	cookieFlag = 1;
	fortuneFlag=1;
	}else{
    document.getElementById("fortuneCookieExtravaganza").style.visibility = "hidden";
	document.getElementById("blueSky").style.visibility = "hidden";
	document.getElementById("pureDeadBrilliantFortuneCookie").style.visibility = "hidden";
	document.getElementById("theFortune").style.visibility = "hidden";
	document.getElementById("bgCookie").style.visibility = "hidden";
	cookieFlag = 0;
  }
}

//this little function was added when integrating the fortune cookie onto the play-fortuneCookie page. The trouble was that the div was covering the cookie button and so you could not click it open.
function revealFortuneDiv(arg){
if(arg==true){
document.getElementById("bigCookieDiv").style.display = 'block';
}else{
document.getElementById("bigCookieDiv").style.display = 'none';
}
}

///// my functions for sizing the text in the fortune
function sizeFortuneText(){
var stringLength = document.getElementById("fortuneSpan").innerHTML.length;
//alert (stringLength);
if (stringLength <= 18){var x=20;}
else if (stringLength <= 25){var x=18;}
else if (stringLength <= 45){var x=15;}
else if (stringLength <= 65){var x=12;}
else if (stringLength <= 80){var x=11;}
else{var x=9;}
document.getElementById("fortuneSpan").style.fontSize = x;
//alert("Text has been successfully sized.");
}

function sizeHulaiText(){
var stringLength1 = document.getElementById("hulaiSpan").innerHTML.length;
var stringLength2 = document.getElementById("englishSpan").innerHTML.length;
var stringLengthT = stringLength1+stringLength2;
//alert (stringLengthT);
if (stringLengthT <= 13){var x=20;}
else if (stringLengthT <= 21){var x=18;}
else if (stringLengthT <= 27){var x=15;}
else if (stringLengthT <= 44){var x=12;}
else{var x=9;}
document.getElementById("hulaiAndEnglish").style.fontSize = x;
//alert("Text has been successfully sized.");
}

var cookieFlag = 0;