// JavaScript Document

var arr = [
	   "<div id='row2' class='secondNthird'>people </div>", 
	   "<div id='row2' class='secondNthird'>homes </div>", 
	   "<div id='row2' class='secondNthird'>energy </div>", 
	   "<div id='row2' class='secondNthird'>transport </div>", 
	   "<div id='row2' class='secondNthird'>cycling </div>", 
	   "<div id='reprefix' class='secondNthird'>re </div>", 
	   "<div id='row2' class='secondNthird'>sunlight </div>", 
	   "<div id='row2' class='secondNthird'>energy</div><div id='row3' class='fourth'>saving</div>", 
	   "<div id='row2' class='secondNthird'>nature </div>", 
	   "<div id='row2' class='secondNthird'>wildlife </div>", 
	   "<div id='row2' class='secondNthird'>the earth </div>",
	   "<div id='row2' class='secondNthird'>bvlablabla</div>",
	   "<div id='row1' class='firstView'>Values</div><div id='row2' class='firstView'>money</div><div id='row3' class='firstView'>can't buy</div><div id='banner_longText'>Suddenly we all want to be good, prudent, charitable, green...<br/></div>"
	   ];

/*
animation loaded
1 VALUES MONEY CANT BUY into VALUE PEOPLE
2 VALUE PEOPLE into VALUE HOMES
3 VALUE HOMES into VALUE ENERGY
4 VALUE ENERGY into VALUE HEALTH
5 VALUE CYCLING
6 VALUE CYCLING into VALUE RECYCLING
7 RECYLING into SUNLIGHT
8 SUNLIGHT into ENERGY SAVING
9 ENERGY SAVING into NATURE
10 NATURE into WILDLIFE
11 WILDLIFE into THE WORLD
12 THE WORLD into NOTHING
13 NOTHING into VALUES
animation loaded
*/
var count =12;

function swapText(){
	if(count==0){
		$("div#text").removeClass('firstFrame');
		$("div#text").addClass('nextFrames');
		$("div#text").children().fadeOut('slow');
		$("div#text").html("<div id='row1'>Value </div>");
		$("div#text").append(arr[count]);
		$("div#text").children().css("display", "none");
		//$("div#text").css('top', '50px');
		$("#row1").fadeIn("slow", function(){
			//$("#row2").show("slide", {direction: _style()}, "slow");
			$("#row2").fadeIn("slow");
		});
		count++;
		
	}
	//to add the "re" prefix before "cycling"
	else if(count==5){ 
		//$("div#text").children().fadeOut('slow');
		$("div#text #row2").before(arr[count]);
		$("div#text").children("#reprefix").css("display", "none");
		$("#reprefix").show("slow");
		count++;
		
	}
	else if(count==11){
		$("div#text").children().fadeOut('slow');
		//$("div#text").children().css("display", "none");
		count++;
	}
	//nothing
	//end of arrey
	else if(count==12){ 
		$("div#text").children().fadeOut('slow');
		$("div#text").html(arr[count]);
		$("div#text").children().css("display", "none");
		count++;
	}
	else {
		$("#reprefix").fadeOut('slow');
		$("#row3").fadeOut('slow');
		$("#row2").fadeOut("slow", function(){				
			$("div#row2").replaceWith(arr[count]);
			$("#row2").css("display", "none");
			 //energy saving
			 if(count==7){				 
				//$("div#text").append("<div id='row3' class='secondNthird'>saving</div>");
				//$("#row2").css("display", "none");
				$("#row3").css("display", "none");
				 //$("#row2").show("slide", {direction: "right"}, "slow", function(){
				$("#row2").fadeIn("slow", function(){																   
					$("#row3").fadeIn("slow");
				 });
			}
			else {
				 //$("#row2").css("display", "none");
				 $("div#row2").fadeIn("slow");
			}
			count++;
		});
	}
}

function animationLoaded(){	
	$("div#text").removeClass('nextFrames')
	$("div#text").addClass('firstFrame');
	$("div#text").html((arr[count]));
	$("div#text").children().css("display", "none");
	//$("div#text").css('top', '30px');
	$("#row1").fadeIn(1000, function(){
		$("#row2").fadeIn(1000, function(){
			$("#row3").fadeIn(1000, function(){
				$("#banner_longText").fadeIn(1000, function(){});
			});														
		});
	});
	count=0;
}

$(document).ready(function(){	
	$("#row1").hide();
	$("#row2").hide();
	$("#row3").hide();
	$("#banner_longText").hide();
});

function getFlashMovie(movieName) {   
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];  
}  
function formSend() {   
	var text = document.htmlForm.sendField.value;   
	getFlashMovie("ExternalInterfaceExample").sendTextToFlash(text);     
}    
function getTextFromFlash(str) {   
	document.htmlForm.receivedField.value = "From Flash: " + str;   return str + " received";  
}
