// string-to-array converter tool, good for cookies and query strings
function _String_read(delineators){
	var myArr=this.split(delineators[0]);
	if(delineators.length>1)
		for(var i=0;i<myArr.length;i++)
			myArr[i]=myArr[i].read(delineators.slice(1));
	return myArr;
}
String.prototype.read=_String_read;

// a cookie getter.
function getCookieVal(key){
	var c=document.cookie.read([/;\s*/,"="]);
	var i=0;
	var res;
	while(i<c.length && c[i][0]!=key)
		i++;
	if(i<c.length)
		res=c[i][1];
	return res;
}

// Flash detector (3 and up, so this leaves out WebTV (as of 2000) and all other Flash 2-or-less folks)
// requires browser sniffer above
// after this script runs lvlFlash will contain the integer indicating the highest currently enabled Flash plug-in version
// therefore, if you need Flash 5 for instance, you can just use if(lvlFlash >=5) and be good to go.
// var lvlFlash=0; // (integer; can be used as Boolean): what level of Flash does the user have installed (detects level 3-5)? also can be used as Boolean (does the user have any flash plugin--3 to 5--installed?). 
lvlFlash=parseInt(getCookieVal("lvlFlash"));
if(isNaN(lvlFlash)){
	lvlFlash=0;
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ) {
		var plugin=navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
		if (plugin)lvlFlash=parseInt(plugin.description.substring(plugin.description.indexOf(".")-1));
	} else if (G_.win && G_.ie && !G_.win31) document.write('<scr' + 'ipt language="VBScript"> \non error resume next \nFor J=3 To 5 \nDim result \nresult=false \nresult=(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash."&CStr(J)))) \nIf result Then lvlFlash=J \nNext \n</scr' + 'ipt\> \n');
}

// this function tries to set a cookie (currently only for the present browser session) that 
// remembers if the user has specifically requested the presence or absence of Flash.
function forceFlash(lvl){
	document.cookie="lvlFlash="+lvl;
	if(getCookieVal("lvlFlash")!=lvl.toString())
		alert("Unable to remember your choice.  Are browser cookies disabled?\nTry changing browser preferences to allow cookies.");
	else location.reload();
}

// almost all of the code below times the movie loads with each other and with the page load.
// desired order:
// 1. page loads, including ribbon initial state (no movies) and gallery initial state plus review XML
// 2. ribbon loads movies
// 3. gallery loads pictures
// this should occur as desired on (Win?) NS4 and Win IE4+.
// Eventually it may work in NS6 as well (this is a browser issue, not mine).
// Otherwise, step 1 has fifteen seconds on its own, and then steps two and three start about simultaneously (probably step 2 first).  I may reduce fifteen seconds to ten (controlled in the Flash movies via the variables listed in the functions below; code is usually in first frame of top level of movie).
//
// The catch_mouse function and the ribbonCoord provide the only other functionality below.
// in Win IE4+ and (Win?) NS4 this code should inform the ribbon movie
// when the user's mouse is over the page, not the movie (the movie can get confused easily;
// this is a Flash issue).  This should provide better-timed disappearance of the rotating movies.
// Notice the rotating movies disappear after only a few seconds of no mouse motion on the movie as well.
// This is to try to deal with browsers who don't have the JS-to-Flash communication lines open as we need them.
// Eventually it may work in NS6 as well (this is a browser issue, not mine).
function LL_setup_first(){
	if(G_.pageLoaded && G_.ribbonLoaded && !G_.setup1Done){
		G_.R=document.ribbon;
		if(G_.R){
			G_.ribbonCoord=[0,18,500,60]; // better to get these dynamically
			G_.R.SetVariable("countDownFrames","0");
			document.onmousemove=catch_mouse;
		}
		G_.setup1Done=true;
	}
}

function LL_setup_second(){
	if(G_.ribbonComponentsLoaded && G_.galleryLoaded && !G_.setup2Done){
		G_.G=document.gallery;
		if(G_.G)
			G_.G.SetVariable("bandwidthOpen","0");
		G_.setup2Done=true;
	}
}

function flash_ribbon_call_first(){
	G_.ribbonLoaded=true;
	LL_setup_first();
}
function flash_ribbon_call_second(){
	G_.ribbonComponentsLoaded=true;
	LL_setup_second();
}
function flash_gallery_call(){
	G_.galleryLoaded=true;
	LL_setup_second();
}
function page_onload(){
	G_.pageLoaded=true;
	LL_setup_first();
}
function catch_mouse(ev){
	if(!ev)ev=event;
	x=ev.clientX?ev.clientX+(window.pageXOffset?window.pageXOffset:document.body.scrollLeft):ev.pageX;
	y=ev.clientY?ev.clientY+(window.pageYOffset?window.pageYOffset:document.body.scrollTop):ev.pageY;
	if (x<G_.ribbonCoord[0]||y<G_.ribbonCoord[1]||x>G_.ribbonCoord[2]||y>G_.ribbonCoord[3])
		G_.R.SetVariable("outOfFrame","1");
	//var tx=document.createTextNode("X:"+x+" ev.clientX:"+ev.clientX+" window.pageXOffset:"+window.pageXOffset+" Y:"+y+" ev.clientY:"+ev.clientY+" window.pageYOffset:"+window.pageYOffset+" eval:"+(x<G_.ribbonCoord[0]||y<G_.ribbonCoord[1]||x>G_.ribbonCoord[2]||y>G_.ribbonCoord[3]));
	//var el=document.getElementById("changeMe");
	//elf=el.firstChild;
	//if(elf)el.replaceChild(tx,elf);
	//else el.appendChild(tx);//replaceChild(el.firstChild,tx);
}
/*
if(G_.nav4){
	window.captureEvents(Event.LOAD&Event.MOUSEMOVE);
	window.onLoad=page_onload;
} else if(G_.major>=5||G_.ie&&(G_.mac&&G_.ieMajor>=5||G_.win&&G_.ieMajor>=4)){
	window.onload=page_onload;
}
*/
