//-------[ Index ] --------------------------------------------------------------------------------//
var path = "assets/images/home_photo_0";
var vidON = 0;
var currentVID;
function Mover(arg){
	var elems = getElementsByClass("bubble");
	for(var i = 0; i < elems.length; i++) getObj("bubble" + i).src = path + i + "_off.jpg";
	for(var j = 0; j < elems.length; j++) getObj("bubbleCall_" + j).style.display = "none";
	getObj("bubble" + arg).src = path + arg + "_on.jpg";
	if(vidON) getObj("bubbleCall_" + arg).style.background = "none";
	else getObj("bubbleCall_" + arg).style.background = "url('assets/images/home_roll_bkgnd.jpg') no-repeat";
	getObj("bubbleCall_" + arg).style.display = "block";
	getObj("bubbleDefault").style.display = "none";
}
function openVidDiv(arg){
	if(vidON) closeVidDiv(currentVID);
	vidON = 1;
	currentVID = arg;
	var flv_name = getChildNodes(getObj("bubbleBlurb_"+arg))[0].innerHTML;
	getObj("bubbleCall_"+arg).style.background = "none";
	//getObj("VIDplaceholder").swapNode(getObj("bubbleVid_"+arg));
	xSwapNode(getObj("VIDplaceholder"), getObj("bubbleVid_"+arg));
	getObj("bubbleVid_"+arg).style.display = "block";
	getObj("bubbleVidDIV").style.display = "block";
	// Start Make swf
		var so = new SWFObject("assets/swf/media_player.swf", "sotester", "200", "170", "8", "#D9E9F8"); //D9E9F8
		so.addVariable("autostart","true");
		so.addVariable("w","200");
		so.addVariable("h","150");
		so.addVariable("img","media_assets/img/" + flv_name.substring(0, flv_name.length-4) + ".jpg");
		so.addVariable("file","media_assets/flv/" + flv_name);
		so.write("vidPlayer_"+arg);
	// Finish making swf
}
function closeVidDiv(arg){
	vidON = 0;
	for(var i = 0; i < 5; i++) getObj("bubbleCall_"+i).style.background = "url('assets/images/home_roll_bkgnd.jpg') no-repeat";
	//getObj("bubbleVid_"+arg).swapNode(getObj("VIDplaceholder"));
	xSwapNode(getObj("bubbleVid_"+arg), getObj("VIDplaceholder"));
	getObj("bubbleVid_"+arg).style.display = "none";
	getObj("bubbleVidDIV").style.display = "none";
}
//-------[ Vision ] -------------------------------------------------------------------------------//
function loadVid(){
	var flv_name = getObj("vidPath").innerHTML;
	var so = new SWFObject("assets/swf/media_player.swf", "sotester", "165", "145", "8", "#F0F0F0"); //F0F0F0
	so.addVariable("autostart","true");
	so.addVariable("w","165");
	so.addVariable("h","125");
	so.addVariable("img","media_assets/img/" + flv_name.substring(0, flv_name.length-4) + ".jpg");
	so.addVariable("file","media_assets/flv/" + flv_name);
	if(!so.write("vidHolder")) getObj("vidHolder").innerHTML = "<img class='alt_noflash' src='assets/swf/media_assets/img/noflash.jpg' width='165' height='125' onclick=\"goLink('getflash')\">";
}
//-------[ Science ] ------------------------------------------------------------------------------//
var visiBox = 1;
function switchBox(arg){
	if(arg != visiBox){
		getObj("Box" + visiBox).style.display = "none";
		getObj("Box" + arg).style.display = "block";
		visiBox = arg;
	}
}
function weirdScience(){
	getObj('introFlash').style.display = "none";
	getObj('bubbleMainHolder').style.display = "block";
}
function replayIntro(){
	getObj("introFlash").style.display = "block";
	var so = new SWFObject("assets/intro.swf", "sotester", "750", "472", "8", "#FFFFFF");
	so.addVariable("autostart","true");
	so.addParam("wmode","opaque");
	so.addVariable("w","750");
	so.addVariable("h","472");
	so.addVariable("file","assets/intro.swf");
	so.write("introFlash");
}
//-------[ Materials ] ----------------------------------------------------------------------------//
function DSslide(arg){
	getObj('ds_overlay').style.display = "block";
	getObj('ds_inside').style.display = "block";
	motion.set(getObj('data_sheet'), 'marginTop', ['0px', '-420px'], 0.6);
	motion.set(getObj('ds_inside'), 'height', ['0px', '420px'], 0.6);
	motion.set(getObj('data_sheet'), 'height', ['0px', '420px'], 0.6);
	motion.set(getObj('ds_iframe'), 'height', ['0px', '420px'], 0.6);
	getObj('ds_iframe').src = "data_" + arg + ".html";
}
function close_ds(){
	getObj('ds_overlay').style.display = "none";
	dso = getObj('ds_inside');
	dso.style.display = "none";
	dso.style.marginTop = "0px";
	dso.style.height = "0px";
	getObj('data_sheet').style.top = "615px";
	getObj('data_sheet').style.marginTop = "0px";
	getObj('ds_iframe').style.height = "0px";
	getObj('ds_inside').style.height = "0px";
	getObj('data_sheet').style.height = "0px";
}
//-------[ General Utilities ] ----------------------------------------------------------------------------//
function getObj(name){
  if(document.getElementById) this.obj = document.getElementById(name);
  else if(document.all) this.obj = document.all[name];
  return this.obj;
}
function getElementsByClass(val){ 
	var all = document.all || document.getElementsByTagName('*');
	var arr = [];
	for(var k = 0; k < all.length; k++)
		if(all[k].className == val) arr[arr.length] = all[k];
	return arr;
}
function goLink(num){
	if (num == 1) {location.href = 'biofuels.html'};
	if (num == 2) {location.href = 'materials.html'};
	if (num == 'getflash') window.open('http://www.adobe.com/go/getflash/','mywindow','toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, copyhistory=no, resizable=yes');
}
function getChildNodes(thisObj) {
	var elementsArray = new Array();
	for(var loop = 0; loop < thisObj.childNodes.length; loop++)
		if (thisObj.childNodes[loop].nodeType == 1)	elementsArray[elementsArray.length++] = thisObj.childNodes[loop];
	return elementsArray;
}
function leftTrim(s){ // trims off whitespaces from a string
	while (s.substring(0,1) == ' ') s = s.substring(1, s.length); return s;
}
function xSwapNode(n1, n2){
	var temp = n2.parentNode;
	var n2 = n1.parentNode.replaceChild(n2, n1);
	var n1 = temp.appendChild(n1);
	temp = null;
	return true;
}
if(window.Node){ //Make swapNode work in Firefox
	Node.prototype.swapNode = function (node) {
		var nextSibling = this.nextSibling;
		var parentNode = this.parentNode;
		node.parentNode.replaceChild(this, node);
		parentNode.insertBefore(node, nextSibling); 
	}
}
//===============[ cookie handling ]================================================//

function bakeCookie(name, days){ //writes a cookie once the site is viewed
	var date = new Date();
	if(!days) days = 30;
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "expires=" + date.toGMTString();
	document.cookie = name + "=1; " + expires + "; path=/"; // viewed=1 is a parameter flsh looks for to either show an intro or not
}
function eatCookie(name){ // read cookie and return the first parameter it finds, has to be viewed=1 or viewed=0
	
	var ArrCookies = document.cookie.split(';');

	for(var i = 0; i<ArrCookies.length; i++){
	
		if(ArrCookies[i].indexOf(name) != -1){
			ArrCookies[i] = leftTrim(ArrCookies[i]);
			return ArrCookies[i].substring(name.length+1, ArrCookies[i].length);
		}
	}
	return "";
}
function trashCookie(name){	bakeCookie(name,-1); } // deletes the cookie

//-------[ Sub Navigation Scripts ] -----------------------------------------------------------------------//

var menuKillTimer;
var mouseOutLag   = 350;

function getElementDom(targetElement) {
	var elementsArray = new Array();
		for (var contLoop = 0; contLoop < targetElement.childNodes.length; contLoop++) {
			if (targetElement.childNodes[contLoop].nodeType == 1) {
				elementsArray[elementsArray.length++] = targetElement.childNodes[contLoop];
			}
		}
	return elementsArray;
}

function getRelatedDom(obj, upDown, nodesNum) {
// make sure nodesNum is a number and not a string
var nodesNum = parseInt(nodesNum);
	if (upDown == 'up') {
	// here we are moving UP the dom (towards the body tag, to general elements)
		var getParentStr = '.parentNode';
		var getFinalObj = '';
		for (loop = 0; loop <= nodesNum; loop++) { getFinalObj = getFinalObj + getParentStr; }
		var targetElement = eval('obj' + getFinalObj);
	} else {
	// here we are moving DOWN the dom (away from the body tag, to specific elements)
		var targetElement = getElementDom(obj)[nodesNum];
	}
return targetElement;
}

function getWhichParentChild(obj) {
	var parentObj = obj.parentNode;
	var parentChildrenArr = getElementDom(parentObj);
	for (loop = 0; loop < parentChildrenArr.length; loop++) {
		if (obj == parentChildrenArr[loop]) {
			return loop;
		}
	}
}

function showRMNav(thisObj, ovrOut) {
	var thisObj  = (thisObj.parentNode.parentNode.className == 'rm-sub-ul') ? getRelatedDom(thisObj.parentNode.parentNode.parentNode.parentNode, 'dn', 0) : thisObj;
	var listObj  = getRelatedDom(thisObj.parentNode, 'dn', 1);
	switch(ovrOut) {
		case 'ovr':
			clearTimeout(menuKillTimer);
			var allLists = document.getElementsByTagName('div');
			for (var loop = 0; loop < allLists.length; loop++) {
				if (allLists[loop].className == 'rm-sub-div') {
					allLists[loop].style.display = (allLists[loop] == listObj) ? 'block' : 'none';
				}
			}
		break;
		case 'out':
			menuKillTimer = setTimeout('this.killMenu()', (mouseOutLag));
		break;
	}
	this.killMenu = function() {
		if (listObj) { listObj.style.display = 'none'; }
	}
}


	//// BEGIN HEADER ////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////
	////                                                                                          ////
	////    CLIENTAPP CLASS.                                                                      ////
	////                                                                                          ////
	////    Developer: Jose Cao-Garcia.                                                           ////
	////    HELP/INFO/DEVELOPER CONTACT: jose@jcao.com, http://jcao.com                           ////
	////                                                                                          ////
	//////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////
	////                                                                                          ////
	////    THIS SCRIPT HANDLES OBJECT-BASED BROWSER DETECTION AND THE DETECTION OF BROWSER       ////
	////    CAPABILITIES, developed by Jose Cao-Garcia. This is a work in progress. This  a       ////
	////    work in progress. For documentation and more recent, updated versions, please         ////
	////    visit http://jcao.com.                                                                ////
	////                                                                                          ////
	////    ALTHOUGH this script relies upon object-based detection to the greatest extent        ////
	////    possible, you should not use it to block specific browsers. It will send users        ////
	////    to an error handler document in the event that the script catches an error, but       ////
	////    otherwise, I really just use it to write in custom css docs for specific browsers,    ////
	////    in order to overcome their specific CSS quirks. Browser-based blocking is bad.        ////
	////                                                                                          ////
	//////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////
	////                                                                                          ////
	////    You are free to copy, use, and create derivative versions of this script as long      ////
	////    as the following conditions are met:                                                  ////
	////                                                                                          ////
	////    1. Any copy or derivative version of this script must retain this header, and all     ////
	////       the information within it.                                                         ////
	////    2. This header and all the information within it must remain intact, and unedited.    ////
	////    3. If you edit, or create a derivative version of this script, you must clearly       ////
	////       indicate that the script has been edited, by whom, and to what extent below        ////
	////       this header.                                                                       ////
	////    4. You may not attempt to sell, license, or otherwise claim the script as your        ////
	////       own work.                                                                          ////
	////                                                                                          ////
	////    If you find this script useful please let me know. Likewise, if you see ways in       ////
	////    which this script could be improved upon, I would love to hear your ideas.            ////
	////                                                                                          ////
	//////////////////////////////////////////////////////////////////////////////////////////////////
	//// END HEADER //////////////////////////////////////////////////////////////////////////////////




	//// OBJECT CLASS FOR GETTING INFORMATION ABOUT THE USERS BROWSER/ENVIRONMENT
		function clientApp() {
			var classRoot      = this;
			classRoot.errorDoc = function() { window.location.replace('browserError.php'); };
			// get the usual browser identification strings, make the lowercase, and easier to parse.
				classRoot.agent      = navigator.userAgent.toLowerCase();
				classRoot.name       = navigator.appName.toLowerCase();
				classRoot.version    = navigator.appVersion.toLowerCase();
				classRoot.system     = navigator.platform.toLowerCase();
				classRoot.engine     = false;
			try {
			// test for various operating strings via non object-based test
				if (classRoot.system == 'macppc' || classRoot.system == 'intel') { classRoot.os = 'mac';        }
				if (classRoot.system == 'win32' || classRoot.system == 'win64')  { classRoot.os = 'win';        }
				if (classRoot.agent.indexOf(' linux') != -1)                     { classRoot.os = 'linux';      }
				if (!classRoot.os)                                               { classRoot.os = false;        }
			// test for rendering engine (not browser) via object-based test
				try { if (navigator.product.toLowerCase() == 'gecko')            { classRoot.engine = 'gecko';  }} catch (e) {}
				try { if ((document.childNodes) && (!navigator.taintEnabled))    { classRoot.engine = 'webkit'; }} catch (e) {}
				try { if (typeof(window.opera) == 'object')                      { classRoot.engine = 'opera';  }} catch (e) {}
				try { if (typeof(window.ScriptEngine) == 'function')             { classRoot.engine = 'icab';   }} catch (e) {}
				try { if (typeof(ActiveXObject) == 'function')                   { classRoot.engine = 'msie';   }} catch (e) {}
				if (!classRoot.engine)                                           { classRoot.engine = false;                 }
			// get rendering engine revision # agent-based tests, by specific rendering engine
				switch(classRoot.engine){
					case 'webkit' : classRoot.engRev = classRoot.agent.split(' applewebkit/')[1].split(' (khtml')[0];       break;
					case 'gecko'  : classRoot.engRev = classRoot.agent.split(') gecko/')[1].split(' ')[0];                  break;
					case 'opera'  : classRoot.engRev = classRoot.agent.split('opera')[1].substring(1).split(' (')[0];       break;
					case 'icab'   : classRoot.engRev = classRoot.engRev = classRoot.agent.split(' icab ')[1].split(';')[0]; break;
					case 'msie'   : classRoot.engRev = classRoot.engRev = classRoot.agent.split(' msie ')[1].split(';')[0]; break;
					case false    : classRoot.engRev = false;                                                               break;
				}
			// test for browsers via non object-based test
			// mozilla must come first, because 'mozilla/' appears in many other more specific gecko browsers
				if (classRoot.agent.indexOf('mozilla/') != -1)                   { classRoot.app = 'mozilla';    }
				if (classRoot.engine == 'msie')                                  { classRoot.app = 'msie';       }
				if (classRoot.agent.indexOf(' netscape6/') != -1)                { classRoot.app = 'netscape';   }
				if (classRoot.agent.indexOf(' netscape/') != -1)                 { classRoot.app = 'netscape';   }
				if (classRoot.agent.indexOf(' safari/') != -1)                   { classRoot.app = 'safari';     }
				if (classRoot.agent.indexOf('safari) omniweb/') != -1)           { classRoot.app = 'omniweb';    }
				if (classRoot.agent.indexOf(' gecko) shiira') != -1)             { classRoot.app = 'shiira';     }
				if (classRoot.agent.indexOf(' camino/') != -1)                   { classRoot.app = 'camino';     }
				if (classRoot.agent.indexOf('konqueror/') != -1)                 { classRoot.app = 'konqueror';  }
				if (classRoot.agent.indexOf(' firefox/') != -1)                  { classRoot.app = 'firefox';    }
				if (classRoot.agent.indexOf('opera') != -1)                      { classRoot.app = 'opera';      }
				if (classRoot.engine == 'icab')                                  { classRoot.app = 'icab';       }
				if (!classRoot.app)                                              { classRoot.app = false;        }
			// then get browser version, using the best method for this browser.
				switch(classRoot.app){
					case 'mozilla'   : classRoot.appRev = classRoot.agent.split(' rv:')[1].split(') ')[0];                     break;
					case 'msie'      : classRoot.appRev = classRoot.engRev = classRoot.agent.split(' msie ')[1].split(';')[0]; break;
					case 'safari'    : classRoot.appRev = classRoot.agent.split(' safari/')[1];                                break;
					case 'omniweb'   : classRoot.appRev = classRoot.agent.split('omniweb/v')[1];                               break;
					case 'shiira'    : classRoot.appRev = classRoot.agent.split('shiira/')[1].split(' safari')[0];             break;
					case 'camino'    : classRoot.appRev = classRoot.agent.split('camino/')[1];                                 break;
					// netscape's user agent strings are a mess ...
					case 'netscape'  : classRoot.appRev = (classRoot.agent.indexOf(' netscape6/') != -1) ? classRoot.agent.split(' netscape6/')[1] : classRoot.agent.split(' netscape/')[1]; break;
					case 'navigator' : classRoot.appRev = classRoot.agent.split('ozilla/')[1].split(' ')[0].split('-')[0];     break;
					case 'konqueror' : classRoot.appRev = classRoot.agent.split(' konqueror/')[1].split(';')[0].split('-')[0]; break;
					case 'firefox'   : classRoot.appRev = classRoot.agent.split(' firefox/')[1];                               break;
					case 'opera'     : classRoot.appRev = classRoot.engRev;                                                    break;
					case 'icab'      : classRoot.appRev = classRoot.engRev = classRoot.agent.split(' icab ')[1].split(';')[0]; break;
					case false       : classRoot.appRev =  false;                                                              break;
				}
			// some object-based tests for basic DOM support
				classRoot.supportsDom = (
					typeof(document.getElementById)                  != 'undefined' &&
					typeof(document.getElementsByTagName)            != 'undefined' &&
					typeof(document.nextSibling)                     != 'undefined' &&
					typeof(document.previousSibling)                 != 'undefined' &&
					typeof(document.childNodes)                      != 'undefined' &&
					typeof(document.parentNode)                      != 'undefined' &&
					typeof(document.hasChildNodes)                   != 'undefined' &&
					typeof(document.nodeType)                        != 'undefined' &&
					typeof(document.cloneNode)                       != 'undefined' &&
					typeof(document.insertBefore)                    != 'undefined' &&
					typeof(document.appendChild)                     != 'undefined' &&
					typeof(document.removeChild)                     != 'undefined' &&
					typeof(document.replaceChild)                    != 'undefined' &&
					typeof(document.documentElement.tagName)         != 'undefined' &&
					typeof(document.documentElement.getAttribute)    != 'undefined' &&
					typeof(document.documentElement.removeAttribute) != 'undefined' &&
					typeof(document.documentElement.attributes)      != 'undefined'
				) ? true : false;
			// some object-based tests for basic AJAX support
				if (typeof(ActiveXObject) != 'function' && typeof(XMLHttpRequest) != 'undefined') { classRoot.supportsAjax = true; }
				if (!classRoot.supportsAjax) { try { var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); classRoot.supportsAjax = true; } catch(e) { } }
				if (!classRoot.supportsAjax) { try { var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); classRoot.supportsAjax = true; } catch(e) { } }
			// get the viewport* width and height *(the usable interior dimensions of the browser window that does not include any browser chrome);
				classRoot.viewportX     = viewportX();
				classRoot.viewportY     = viewportY();
			// update values on window resize event ...
				window.onresize = function() { classRoot.viewportX  = viewportX();  }
				window.onresize = function() { classRoot.viewportY = viewportY(); }
			// screen resolution (total, including menubar/taskbar etc...)
				classRoot.screenX       = screen.width;
				classRoot.screenY       = screen.height;
			// screen resolution (total available for use)
				classRoot.screenAvailY  = screen.availWidth;
				classRoot.screenAvailX  = screen.availHeight;
			} catch(e) { classRoot.errorDoc(); }
		}




		//// GET VIEWPORT WIDTH
			function viewportX(windowName) {
				try {
					if (!windowName) { windowName = 'self' };
					if (self.innerHeight) {
						var widthProperty = '.innerWidth';
					} else if (document.body) {
						var widthProperty = '.document.body.clientWidth';
					} else if (document.documentElement && document.documentElement.clientHeight) {
						var widthProperty = '.document.documentElement.clientWidth';
					}
					eval('var viewportX = ' + windowName + widthProperty);
				} catch (e) {
					var viewportX = false;
				}
				return viewportX;
			}




		//// GET VIEWPORT HEIGHT
			function viewportY(windowName) {
				try {
					if (!windowName) { windowName = 'self' };
					if (self.innerHeight) {
						var heightProperty = '.innerHeight';
					} else if (document.body) {
						var heightProperty = '.document.body.clientHeight';
					} else if (document.documentElement && document.documentElement.clientHeight) {
						var heightProperty = '.document.documentElement.clientHeight';
					}
					eval('var viewportY = ' + windowName + heightProperty);
				} catch (e) {
					var viewportY = false;
				}
				return viewportY;
			}




		//// GET WINDOW POSITION (X)
			function winPosX(windowName) {
				if (!windowName) { windowName = 'self' };
				if (window.screenLeft) {
					var pos = eval(windowName + '.screenLeft');
				} else if (window.screenX) {
					var pos = eval(windowName + '.screenX');
				} else {
					var pos = false;
				}
				return pos;
			}




		//// GET WINDOW POSITION (Y)
			function winPosY(windowName) {
				if (!windowName) { windowName = 'self' };
				if (window.screenTop) {
					var pos = eval(windowName + '.screenTop');
				} else if (window.screenY) {
					var pos = eval(windowName + '.screenY');
				} else {
					var pos = false;
				}
				return pos;
			}




	//// INITIALIZE THE clientApp OBJECT
		var client = new clientApp();
			//client.errorDoc = function() { window.location.replace('browserError.php'); };