var strike_v_image_old;
var strike_v_image;
var strike_v;
var strike_vr;
var strike_vl;
var burn_v;
var black_v;
var which_v;
var next_r = 1;
var next_l = 1;
var meadows;
function goDestination() {
	var eagleName = window.document.eagle.src
	if (eagleName.substring(eagleName.length - 15, eagleName.length) !== "transparent.gif") {
		alert("Wow! Your sixth clue: generosity.");
		window.location = "../bats/bat01.htm";
	}
}

function drawLandscape(){
	next_r = 1;
	next_l = 1;
    v_columns = new Array (8);
	for (count=1;count<=8;count++) {
     if (count !== 4) {
	  var which_t = "t" + count;
	  var which_v = "v" + count;
	  which_t = document[which_t].src;
	  which_t = which_t.substring(which_t.length - 5, which_t.length - 4);
	  v_columns[count] = which_t;
	  if (which_t == 1) document[which_v].src = "../../images/fire_effects/fem_act/grass.gif";
	  if (which_t == 2) document[which_v].src = "../../images/fire_effects/fem_act/pipo1.gif";
	  if (which_t == 3) document[which_v].src = "../../images/fire_effects/fem_act/pipo2.gif";
	  if (which_t == 5) document[which_v].src = "../../images/fire_effects/fem_act/psme1.gif";
	  if (which_t == 6) document[which_v].src = "../../images/fire_effects/fem_act/psme2.gif";
	  if (which_t == 7) document[which_v].src = "../../images/fire_effects/fem_act/snag1.gif";
     }
	 v_columns[4] = 4;
	 document.v4.src = "../../images/fire_effects/fem_act/cabin.gif";
	}
  document.lightning.src = "../../images/fire_effects/fem_act/lightning.gif";
  determineFactors();
}

function determineFactors() {
	meadows = 0;
	var snags = 0;
	var poles = 0;
	var psme2 = 0;
	var overstories = 0;
	for (count=1;count<=8;count++) {
		if (v_columns[count] == 1) meadows ++;
		if (v_columns[count] == 7) snags ++;
		if (v_columns[count] == 2 || v_columns[count] == 5) poles ++;
		if (v_columns[count] == 6) psme2 ++;
		if (v_columns[count] == 3 || v_columns[count] == 6) overstories ++;
	}
	var begin_text = Math.round(Math.random() * 3) + 1;
	if (begin_text == 1) var description = "You have created an interesting landscape. ";
	if (begin_text == 2) var description = "Have you considered how John feels about your landscape modifications? ";
	if (begin_text == 3) var description = "John likes your landscape. ";
	if (begin_text == 4) var description = "Your landscape is interesting. ";
	//eco-factor
	e_f = 0
	if (meadows == 1) {
		e_f ++;
		description = description + "First, your meadow will allow light to reach young seedlings. Deer and elk will appreciate the open meadows. ";
	}
	if (meadows == 0) {
		e_f --;
		description = description + "First, the birds will not have meadows to enjoy. Deer and elk will not have the best locations to browse. ";
	}
	if (meadows > 1)  {
		e_f = (e_f + 3);
		description = description + "Abundant meadows will give light to young seedlings. Wildflowers and wildlife will appreciate the open landscape. ";
	}
	if (overstories == 1) {
		e_f ++;
		description = description + "There are few over-story trees on your landscape. Old trees usually have few branches near to the ground, which makes them quite fire-resistant. ";
	}
	if (overstories == 0) {
		e_f --;
		description = description + "There are no old-growth trees on your landscape. Old, tall trees help to seed the landscape with new trees and are quite fire-resistant since their branches are high above the ground. ";
	}
	if (overstories > 1) {
		e_f = (e_f + 3);
		description = description + "You have many over-story trees on your landscape. Although old trees are essential for seeding the landscape, too many overstory trees may shade-out seedlings, making it difficult for young seedlings to mature. ";
	}
	if (snags > 0) {
		e_f = e_f + 2;
		description = description + "Your snags are great habitat for wildlife. ";
	}
	if (snags = 0) {
		e_f --;
		description = description + "Sadly, birds and small mammals won't have snags for places to hide from predators and for shelter from inclement weather. ";
	}
	if (poles == 1) {
		e_f ++;
		description = description + "Your young pole-size tree may one day grow to great size and seed the landscape. ";
	}
	if (poles > 1) {
		e_f = (e_f + 2);
		description = description + "Your young pole-size tree may one day grow to great size and seed the landscape. ";
	}
	document.form1.eco_factor.value = e_f;
	//fire potential
	description = description + "And what about John's cabin? See for yourself by clicking the lightning bolt.";
	f_p = 10;
	if (v_columns[3] == 1) {
		f_p = (f_p - 4);
	}
	if (v_columns[5] == 1) {
		f_p = (f_p - 5);
	}
	if (v_columns[3] == 3) {
		f_p = (f_p - 4);
	}
	if (v_columns[5] == 3) {
		f_p = (f_p - 4);
	}
	if (v_columns[3] == 7) {
		f_p = (f_p - 4);
	}
	if (v_columns[5] == 7) {
		f_p = (f_p - 4);
	}
	if (v_columns[3] == 6) {
		f_p = (f_p - 3);
	}
	if (v_columns[5] == 6) {
		f_p = (f_p - 3);
	}
	if (v_columns[3] == 2) {
		f_p = (f_p - 1);
	}
	if (v_columns[5] == 2) {
		f_p = (f_p - 1);
	}
	if (meadows == 7) f_p = 7;
	document.form1.fire_potential.value = f_p;
	document.form1.textfield.value = description;
}

function swapLightning() {
	var lightning = window.document.lightning.src
	if (lightning.substring(lightning.length - 15, lightning.length) !== "transparent.gif") {
		if (lightning.substring(lightning.length - 13, lightning.length) !== "lightning.gif") {
			document.lightning.src = "../../images/fire_effects/fem_act/lightning2.gif";
		}
		else {
			document.lightning.src = "../../images/fire_effects/fem_act/lightning.gif"
		}
	}
}

function swapText(text_name) {
	var which_text = window.document[text_name].src;
	which_text = which_text.substring(which_text.length - 5, which_text.length - 4);
	which_text ++;
	if (which_text == 4) which_text++;
	if (which_text == 8) which_text = 1;
	window.document[text_name].src = "../../images/fire_effects/fem_act/txt" + which_text + ".jpg";
}

function burnForest() {
	var lightning = window.document.lightning.src
	if (lightning.substring(lightning.length - 15, lightning.length) !== "transparent.gif") {
		//strike first vspace
		strike_v = 4;
		var no_grass = 0;
		if (meadows !== 7) {
		  while (strike_v == 4 || no_grass == 0) {
			no_grass = 0
			strike_v = Math.round(Math.random() * 7) + 1;
			strike_v_image = "v" + strike_v;
			strike_v_image_old = window.document[strike_v_image].src
			if (strike_v_image_old.substring(strike_v_image_old.length - 9, strike_v_image_old.length - 4) !== "grass") no_grass = 1
		  }
		}
		else {
		    strike_v = 4;
		    strike_v_image = "v4";
			strike_v_image_old = window.document[strike_v_image].src
		}
		window.document[strike_v_image].src = "../../images/fire_effects/fem_act/lightninglg.gif";
		the_timeout = setTimeout("continueBurn();", 900);
	}
}

function burnTree(burn_v) {
	burn_v = "v" + burn_v;
	which_v = document[burn_v].src;
	if (which_v.substring(which_v.length - 5, which_v.length) !== "x.gif" && which_v.substring(which_v.length - 13, which_v.length) !== "lightning.gif" ) {
		which_v = which_v.substring(which_v.length - 9, which_v.length - 4)
		document[burn_v].src = "../../images/fire_effects/fem_act/" + which_v + "f.gif";
	}
}

function fireOut() {
	var check4fires = 0;
	for (count=1;count<=8;count++) {
	  burn_v = "v" + count;
	  which_v = document[burn_v].src;
	  if (which_v.substring(which_v.length - 5, which_v.length) == "f.gif") {
	  	check4fires++;
	  }
	}
	if (check4fires > 0) {
		burn_v = "v" + (Math.round(Math.random() * 7) + 1);
		which_v = document[burn_v].src;
		if (which_v.substring(which_v.length - 5, which_v.length) == "f.gif") {
			which_v = which_v.substring(which_v.length - 10, which_v.length - 5);
	    	document[burn_v].src = "../../images/fire_effects/fem_act/" + which_v + "x.gif";
	  	}	
		the_timeout = setTimeout("fireOut();", 350);
	}
}

function continueBurn() {
	window.document[strike_v_image].src = strike_v_image_old;
	burnTree(strike_v);
	burnRight();
	burnLeft();
	the_timeout = setTimeout("fireOut();", 350);
	document.lightning.src = "../../elements/transparent.gif";
	if (f_p <= 2 && e_f >=8) document.eagle.src = "../../elements/eagle_btn_ani.gif";
}

function burnRight() {
	//start burn right it if it's a tree
	var old_r = next_r;
	strike_vr = (strike_v + next_r);
	if (strike_vr < 9) {
		if (v_columns[strike_vr] == 2 || v_columns[strike_vr] == 4 || v_columns[strike_vr] == 5 || v_columns[strike_vr] == 6){
			burnTree(strike_vr);
			next_r ++;
		}
	}
	if (old_r !== next_r) burnRight();
}
function burnLeft() {
	//start burn right it if it's a tree
	var old_l = next_l;
	strike_vl = (strike_v - next_l);
	if (strike_vl > 0) {
		if (v_columns[strike_vl] == 2 || v_columns[strike_vl] == 4 || v_columns[strike_vl] == 5 || v_columns[strike_vl] == 6){
			burnTree(strike_vl);
			next_l ++;
		}
	}
	if (old_l !== next_l) burnLeft();
}