
// loadMeUp = '';
// startMeUp = ''




function showTrailer() {
	// document.getElementById('earthlings_movie').innerHTML = "<embed id=VideoPlayback src=http://www.earthlings.com/mambots/content/plugin_jw_allvideos/jw_allvideos_player.swf?file=http://www.earthlings.com/images/stories/videos/Unrated-Trailer(Shaun).flv&showdigits=true&autostart=true style=width:100%;height:100% allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash></embed>";
	document.getElementById('earthlings_movie').innerHTML = "<embed id=VideoPlayback src=/swf/preview-earthlings.swf?NE=1&autoPlay=1 style=width:100%;height:100% allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash></embed>";
}

function showFilm() {
  winH = getWindowHeight();
	document.getElementById("earthlings_movie").innerHTML = "<div id='intro_text' style='text-align:center;padding-top:" + ((winH > minWinHeight) ? 260 : 150) + "px;'><img style='filter:alpha(opacity=40);opacity: 0.40;-moz-opacity: 0.40;' src='images/blue-wait.gif' /></div>";
	execAfterAjaxCall = "initImageSwap('earthlings_movie');";
	ajaxCall("a-message-from-the-makers-of-earthlings.inc.php","earthlings_movie");
}

function startFilm() {
	// document.getElementById('earthlings_movie').innerHTML = "<embed id=VideoPlayback src=http://video.google.com.au/googleplayer.swf?docid=6361872964130308142&hl=en&fs=true&autoplay=1&hd=1&cc_load_policy=0 style=width:100%;height:100% allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash></embed>";
	document.getElementById('earthlings_movie').innerHTML = "<embed src='http://vimeo.com/moogaloop.swf?clip_id=15563502&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=1&amp;loop=0' style='width:100%;height:100%;' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='100%' height='100%'></embed>";
}



function embedVideo() {
	// display embed code
	alert("embed function goes here");
}




///////////// PRELOAD IMAGES ////////////////

preloadArray = new Array();
function addPreload(imgSrc) { preloadArray[preloadArray.length] = imgSrc; }
var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		for (i=0; i<preloadArray.length; i++) eval("preloadImage"+i+" = newImage('"+preloadArray[i]+"');");
		preloadFlag = true;
	}
}
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}







addPreload('images/wait.gif');
addPreload('images/blue-wait.gif');
addPreload('images/what-others-are-saying-about-earthlings-upper.gif');
addPreload('images/images/video-bg-sml.jpg');
function submitF2F() {
	f = document.getElementById('share_form');
	if (checkForm(f,1)) {
		params = 'ajax=1';
		for (ff=0;ff<f.length;ff++) {
			fEl = f[ff];
			fieldValue = escape(f[ff].value);
			if (fEl.type=='checkbox') fieldValue = (fEl.checked) ? 'on' : '';
			params += "&" + f[ff].name + "=" + fieldValue;
		}
		requestURL = 'sharer.inc.php';
		elId = 'form_contents';
		document.getElementById(elId).innerHTML = "<div style='text-align:center;padding-top:52px;padding-right:35px;'><img src='images/wait.gif' /></div>";
		// display wait symbol
		ajaxResponse = ajaxCall(requestURL,elId,false,params);
	}
}

function showF2F() {
	f = document.getElementById('share_form');
	if (checkForm(f,1)) {
		params = 'ajax=1';
		for (ff=0;ff<f.length;ff++) {
			fEl = f[ff];
			fieldValue = escape(f[ff].value);
			if (fEl.type=='checkbox') fieldValue = (fEl.checked) ? 'on' : '';
			params += "&" + f[ff].name + "=" + fieldValue;
		}
		requestURL = 'f2f-form.inc.php';
		elId = 'form_contents';
		// display wait symbol
		document.getElementById(elId).innerHTML = "<div style='text-align:center;padding-top:52px;padding-right:35px;'><img src='images/wait.gif' /></div>";
		execAfterAjaxCall = "initImageSwap('form_contents');";
		ajaxResponse = ajaxCall(requestURL,elId,false,params);
	}
}



function getWindowHeight() {
 var myWidth = 0, myHeight = 0;
 if( typeof( window.innerWidth ) == 'number' ) {
   //Non-IE
   myHeight = window.innerHeight;
 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
   //IE 6+ in 'standards compliant mode'
   myHeight = document.documentElement.clientHeight;
 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
   //IE 4 compatible
   myHeight = document.body.clientHeight;
 }
 return(myHeight);
}

scaleCount = 0;
scaleTimer = null;
function autoScaleVid() {
	scaleCount = 0;
	scaleTimer = setTimeout("resizeVidHtml();",1);
}
minWinHeight = 900;
function resizeVidHtml() {
	scaleCount++
	if (scaleCount==25) {
   winH = getWindowHeight();
	 oldVidHolderHeight = document.getElementById('video_holder').style.height;
	 newVidHolderHeight = (winH > minWinHeight) ? "676px" : "476px";
	 if (oldVidHolderHeight!=newVidHolderHeight) {
		 document.getElementById('video_holder').style.height = newVidHolderHeight;
		 document.getElementById('earthlings_movie').style.width = document.getElementById('video_holder').style.width;
		 document.getElementById('earthlings_movie').style.height = document.getElementById('video_holder').style.height;
		 document.getElementById('video_frame').style.background = (winH > minWinHeight) ? "url(images/video-bg.jpg) no-repeat" : "url(images/video-bg-sml.jpg) no-repeat";
		 document.getElementById('video_frame').style.height = (winH > minWinHeight) ? "676px" : "476px";
		 if (document.getElementById('intro_text')) {
			 displayIntroScreen();
		 }
	 }
	} else {
		clearTimeout(scaleTimer);
		scaleTimer = setTimeout("resizeVidHtml();",5);
	}
}
window.onresize = autoScaleVid;
loadMeUp += "autoScaleVid();"; 

function displayIntroScreen() {
  winH = getWindowHeight();
	introTextSource = (winH > minWinHeight) ? "intro-text-large.inc.php" : "intro-text-small.inc.php";
	document.getElementById("earthlings_movie").innerHTML = "<div id='intro_text' style='text-align:center;padding-top:" + ((winH > minWinHeight) ? 260 : 150) + "px;'><img style='filter:alpha(opacity=40);opacity: 0.40;-moz-opacity: 0.40;' src='images/blue-wait.gif' /></div>";
	execAfterAjaxCall = "initImageSwap('earthlings_movie');";
	ajaxCall(introTextSource,"earthlings_movie");
}




////////////// QUOTES ///////////////
 

 
selectedQuote = 1;
function showQuote(f,userInput) {
	if (userInput) fadeStepInt = 2;
	quoteNum = document.getElementById('quoteContainer').getElementsByTagName('P').length;
	// fade out selected Quote
	fadeOut('quote'+selectedQuote,'fadeInRequestedQuote();');
	if (f > quoteNum) f = 1;
	if (f < 1) f = quoteNum;
	if (userInput) clearInterval(quoteRotator);
	selectedQuote = f;
}
function fadeInRequestedQuote() {
	quoteNum = document.getElementById('quoteContainer').getElementsByTagName('P').length;
	for (i=1;i<=quoteNum;i++) {
		document.getElementById('quote'+i).className = (selectedQuote==i) ? 'selected' : '';
	}
	fadeIn('quote'+selectedQuote);
}
function nextQuote(userInput) {
	showQuote((selectedQuote+1),userInput);
}
function prevQuote() {
	showQuote((selectedQuote-1),1);
}
loadMeUp += "quoteRotator = setInterval('nextQuote();',10000);";
 
 
 













function toggleMoreInfo() {
	if (document.getElementById('readMore').innerHTML.indexOf('More')!=-1) {
		document.getElementById('textMore').style.display='block';
		document.getElementById('readMore').innerHTML = '&laquo; Read Less';
	} else {
		document.getElementById('textMore').style.display='none';
		document.getElementById('readMore').innerHTML = 'Read More &raquo;';
	}
}




////////////////// FADE IN & OUT ////////////////////

fadeStepInt = 35;
randFadeId = Math.ceil(Math.random()*1000);
function fadeOut(elId,execAfter,el) {
	if (el) {
		if (!el.id) el.setAttribute('id','fadeEl'+randFadeId++);
		elId = el.id;
	} else {
		el = document.getElementById(elId);
	}
	fadeEl = el;
	fadeEl.elId = elId;
	if (execAfter) fadeOutExecAfter = execAfter;
	fadeEl.alpha = 100;
	setOpacity(fadeEl.id,fadeEl.alpha);
	setTimeout(fadeOutStep,fadeStepInt);
}

fadeOutExecAfter = fadeInExecAfter = '';
function fadeOutStep() {
	fadeEl.alpha -= 2;
	setOpacity(fadeEl.id,fadeEl.alpha);
	if (fadeEl.alpha <= 0) {
		if (fadeOutExecAfter) {
			eval(fadeOutExecAfter);
			fadeOutExecAfter = '';
		}
	} else setTimeout(fadeOutStep,fadeStepInt);
}

function fadeIn(elId,execAfter,el) {
	if (elId) {
		el = document.getElementById(elId);
	} else {
		if (!el.id) el.id = 'fadeEl'+randFadeId++;
		elId = el.id;
	}
	fadeEl = el;
	fadeEl.elId = elId;
	if (execAfter) fadeInExecAfter = execAfter;
	fadeEl.alpha = 0;
	setOpacity(fadeEl.id,fadeEl.alpha);
	setTimeout(fadeInStep,fadeStepInt);
}

function fadeInStep() {
	fadeEl.alpha += 2;
	setOpacity(fadeEl.id,fadeEl.alpha);
	if (fadeEl.alpha >= 100) {
		if (fadeInExecAfter) {
			eval(fadeInExecAfter);
			fadeInExecAfter = '';
		}
	} else setTimeout(fadeInStep,fadeStepInt);
}

function setOpacity(elId,alpha,el) {
	if (!el) el = document.getElementById(elId);
	if (document.all) el.style.filter = 'alpha(opacity=' + alpha + ')';	
	else el.style.opacity = (alpha)/100;
}








