var debug = "false";  // set this at bottom of initialization function


var initialParameters = [];
initialParameters['theFile'] = "";
initialParameters['theClip'] = "";
initialParameters['theDebug'] = "";
var aOffset = 0;
var slidedelay=5000;
var    theImage = "";
var thePanel = "";
var intervalHandle = "";
var imageArray = [];
var imageArrayLength = 0;
var imageArrayIndex = 0;
var clipArray = [];
var clipArrayLength = 0;
var clipArrayIndex = 0;
var ipadFlag = "false";
var theCount = 0;

var reloaded = false;
var loc=""+document.location;
loc = loc.indexOf("?reloaded=")!=-1?loc.substring(loc.indexOf("?reloaded=")+10,loc.length):"";
loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
reloaded = loc!=""?(loc=="true"):reloaded;

function initialization_main() {

    var query = window.location.search.substring(1);
	//if ( BrowserDetect.browser == "Explorer" && BrowserDetect.version == "7" ) {
        //location.href = "index_expl7.html";
	//}



	if ( query != "" ) {
        var parms = query.split('&');
	    var currentDate = new Date();
	    var time1 = currentDate.getSeconds();
        for (var i=0; i<parms.length; i++) {
            var pos = parms[i].indexOf('=');
            if (pos > 0) {
                var key = parms[i].substring(0,pos);
                var val = parms[i].substring(pos+1);
                initialParameters[key] = val;
            }
        }
	}
    theFile = initialParameters['theFile'];
    theClip = initialParameters['theClip'];

	if ( theFile != "" && theFile.indexOf('.html') == -1 ) {
		theFile = theFile + ".html";
	}
	if ( theFile == "testPanel.html" || theFile == "testpanel.html" ) {
		debug = "true";
	} 

	if ( debug  == "true" ) {
	    //document.getElementById('debugText').style.visibility = 'visible';
	    //document.getElementById('debug').style.visibility = 'visible';
	    document.getElementById('debugText').style.display = 'block';
	    document.getElementById('debug').style.display = 'block';
	    document.getElementById('body').style.marginLeft = "0px";
	} else {
	    //document.getElementById('debugText').style.visibility = 'hidden';
	    //document.getElementById('debug').style.visibility = 'hidden';
	    //document.getElementById('debugText').style.width = 0 + 'px';
	    //document.getElementById('debug').style.width = 0 + 'px';
	    document.getElementById('debugText').style.display = 'none';
	    document.getElementById('debug').style.display = 'none';
	    document.getElementById('body').style.marginLeft = "auto";
	}
	initDebug();
        BrowserDetect.init();
	addDebug( BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' + BrowserDetect.OS);
	addDebug("initialization   ==="  + query + "===");
    
	if ( theClip != "" ) {
        theClip = theClip.replace(/%20/g," ");
		theFile = theClip;
	}
	
	if ( theFile != "" ) {
        theFile = theFile.replace(/%20/g," ");
	    //document.getElementById('finishPanel').style.visibility = 'hidden';
	    document.getElementById('storyFrame').style.visibility = 'hidden';
	    storyPanelOffsetHeight = 0;
	} else {
	    //document.getElementById('finishPanel').style.visibility = 'hidden';
	    document.getElementById('storyFrame').style.visibility = 'visible';
	    storyPanelOffsetHeight = 180 + 'px';
	    buildStoryPanel();
		//buildFinishPanel("","");
	}
	
	addDebug("theFile = " + theFile);

    theDebug = initialParameters['theDebug'];
	if ( theDebug != "" ) {
        theDebug = theDebug.replace(/%20/g," ");
	}
	if ( theDebug == "true" || theDebug == "false") {
		debug = theDebug;
	}

	if ( theFile == "" ) {
	    buildMainPanel("frontPage.html");

        copyRightString = 
		    "<table width=100%>" +
			"<tr>" +
			"<td><a href=\"?theFile=wercStatus.html\"><span class=\"size8 blue\">" + theCount + "</span></a></td>" +
            "<td><center><span class=\"brown size9\">&copy; 2005 W.E.R.C- All rights reserved.</span>" +
            " <span class=\"Black size10\">" +
            "(408) 779-9372 " +
		    "</span>" + 
		    "- <a href=\"http://www.werc-ca.org\" ><span class=\"Black size10\">www.werc-ca.org</span></a> " +
		    "- <a href=\"mailto:werc\@werc-ca.org\"><span class=\"Black size10\">email W.E.R.C.</span>" +
		    "- <span class=\"Black size9\">501(c)(3) non-profit organization</span>" +
			"</center><td>" +
			"</tr>" +
			"</table>";

	        //"<td><span class=\"blue size8\">[" + BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' + BrowserDetect.OS + "]</span></td>" +


        document.getElementById( 'footer' ).innerHTML = copyRightString;
	} else if ( theFile == "testPanel.html" || theFile == "testpanel.html" ) {
		buildTestPanel("testPanel.html");
	} else if ( theFile == "statusPanel.html" || theFile == "statuspanel.html" ) {
		buildStatusPanel("statusPanel.html");
    } else if ( theFile == "animalStory_archive.html" ) {
	    buildMainProcessAnimalStoryArchive(theFile);
    } else if ( theFile == "wercStatus.html" ) {
	    buildMainProcessStatus(theFile);
    } else if ( theFile == "wercStatusMore.html" ) {
	    buildMainProcessStatus(theFile);
    } else if ( theFile == "wercStatusOther.html" ) {
	    buildMainProcessStatus(theFile);
    } else if ( theFile == "wercStatusToday.html" ) {
	    buildMainProcessStatus(theFile);
	} else {
	    buildMainPanel(theFile);
	}

	if ( BrowserDetect.OS == "iPad" ) {
		// un comment next line if the other menu style required
        //ipadFlag = "true";
	}

	slidePanelOffsetHeight = document.getElementById( 'slidePanel' ).offsetHeight;
	menuPanelOffsetHeight = document.getElementById( 'menuPanel' ).clientHeight ;
	mainPanelOffsetHeight = document.getElementById( 'mainPanel' ).offsetHeight ;
	if ( theFile == "" ) {
	    storyPanelOffsetHeight = document.getElementById( 'storyFrame' ).offsetHeight + 10;
	    //finishPanelOffsetHeight = document.getElementById( 'finishPanel' ).offsetHeight + 10;
		document.getElementById( 'mainPanel' ).style.width = 800 + 'px';
	} else {
	    storyPanelOffsetHeight = 0;
	    //finishPanelOffsetHeight = 0;
		document.getElementById( 'mainPanel' ).style.width = 800 + 'px';
	}
	if ( theClip != "" ) {
	    slidePanelOffsetHeight =  0;
	    menuPanelOffsetHeight =  0;
	    document.getElementById('menuPanel').style.visibility = 'hidden';
	}

    menuPanelTop = slidePanelOffsetHeight + 5;
	document.getElementById( "menuPanel" ).style.top = menuPanelTop + 'px';
	//document.getElementById( 'menuFrame' ).style.top = menuPanelTop + 'px';

    mainPanelTop = slidePanelOffsetHeight + menuPanelOffsetHeight ;
    //centerPanelTop = slidePanelOffsetHeight + menuPanelOffsetHeight ;
	document.getElementById( 'mainPanel' ).style.top = mainPanelTop + 'px';

    //if ( mainPanelOffsetHeight > finishPanelOffsetHeight ) {
	    //centerPanelOffsetHeight = mainPanelOffsetHeight ;
	//} else {
	    //centerPanelOffsetHeight = finishPanelOffsetHeight ;
	//}
	    
	addDebug("height: slidePanel = " + slidePanelOffsetHeight + " |height: menu = " + menuPanelOffsetHeight +
	         " |height: main = " + mainPanelOffsetHeight + 
	         " |height: story = " + storyPanelOffsetHeight );
	//addDebug("height: slidePanel = " + slidePanelOffsetHeight + " |height: menu = " + menuPanelOffsetHeight +
	         //" |height: main = " + mainPanelOffsetHeight + " |height: center = " + centerPanelOffsetHeight +
	         //" |height: story = " + storyPanelOffsetHeight + " |height: finish = " + finishPanelOffsetHeight );

	storyPanelTop =  slidePanelOffsetHeight + menuPanelOffsetHeight + mainPanelOffsetHeight  ;
	document.getElementById( 'storyFrame' ).style.top = storyPanelTop + 'px';
    
	//finishPanelTop =  slidePanelOffsetHeight + menuPanelOffsetHeight;

	if ( theFile == "" ) {
	    totalOffsetHeight = slidePanelOffsetHeight + menuPanelOffsetHeight + mainPanelOffsetHeight +   
	                   storyPanelOffsetHeight + aOffset - 40;
	} else {
	    totalOffsetHeight = slidePanelOffsetHeight + menuPanelOffsetHeight + mainPanelOffsetHeight +   
	                   + aOffset;
	}

	addDebug("top: menuPanel = " + menuPanelTop + " |top: mainPanel = " + mainPanelTop +
	         " |top: storyPanel = " + storyPanelTop );
	//addDebug("top: menuPanel = " + menuPanelTop + " |top: mainPanel = " + mainPanelTop +
	         //" |top: centerPanel = " + centerPanelTop + " |top: storyPanel = " + storyPanelTop +
	         //" |top: finishPanel = " + finishPanelTop );
	addDebug("height: totalOffsetHeight = " + totalOffsetHeight);

	document.getElementById( 'body' ).style.height = totalOffsetHeight + 'px';
	document.getElementById( 'footer' ).style.top = totalOffsetHeight + 'px';
	bodyOffset = document.getElementById( 'body' ).offsetLeft;

	if ( theFile == "" || theClip != "" ) {
	    document.getElementById('footerPrev').style.visibility = 'hidden';
	}


	//addDebug("body: left = " + bodyOffset );

	//document.getElementById( 'menuPanel' ).style.left = bodyOffset + 'px';

	if ( theFile == "educationalAnimalGallery.html" ) {
		galleryDescriptionPanelHeight = document.getElementById( 'galleryDescriptionPanel').offsetHeight;
		gallerySlidePanelHeight = document.getElementById( 'gallerySlidePanel').offsetHeight;
		galleryDescriptionPanelTop = mainPanelTop;
		gallerySlidePanelTop = galleryDescriptionPanelHeight;
	    document.getElementById( 'gallerySlidePanel' ).style.top = gallerySlidePanelTop + 'px';
	    galleryTextPanelTop = gallerySlidePanelTop + gallerySlidePanelHeight + 20;
	    document.getElementById( 'galleryTextPanel' ).style.top = galleryTextPanelTop + 'px';
		buildGalleryPanel();
	}

	if ( theClip == "" ) {
	    buildSlideshow();
	    buildMenu();
	}

	initializeToggle();
	initializeShadowbox();

}
// End of the initialization

function tester() {
    alert("hi there");
}

function reloadOnceOnly() {
    if (!reloaded) 
        window.location.replace(window.location+"?reloaded=true");
}


function shadowboxClose() {
	//alert("================");
    Shadowbox.close(); 
}

function initializeToggle() {
    $(document).ready(function(){
	    $("h2.trigger").click(function(){
	        $(".toggle_container").hide();
		    $(this).toggleClass("active").next().slideToggle("slow");
	    });
    });
	$(".toggle_container").hide();
}

function initializeShadowbox() {
	Shadowbox.init({ 
		players:  "iFrame", 
	});
}

function showAll() {
	$(".toggle_container").show();
}

function hideAll() {
	//addDebug("here");
	$(".toggle_container").hide();
}

function getXMLHttpRequest() 
{
	var httpRequest;
    if (window.XMLHttpRequest) {
        httpRequest =  new window.XMLHttpRequest;
    }
    else {
        try {
            httpRequest =  new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch(ex) {
            return null;
        }
    }

    if (httpRequest != null) {
		return httpRequest
    } else {
        window.alert("AJAX (XMLHTTP) not supported.");
    }

}

function subPage(theHtml) {
    XMLHttp_storyClip = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug + "&theFile=" + theHtml ;
    XMLHttp_storyClip.open("GET", "../cgi-bin/indexBuildStoryClipsPanel.cgi" + queryString, false);
    XMLHttp_storyClip.send(null);
    var returnString = XMLHttp_storyClip.responseText;
    //document.getElementById("slidePanel").innerHTML = returnString; 

    printDebugPanel ( {indexString: "buildStoryClipsPanel", returnString: returnString}, "","none");

    //theHtmlTitle = theHtml.split('.');
    Shadowbox.open({
        //content:    '<div id="welcome-msg">Welcome to my website!</div>',
		title: "Click outside frame to dismiss (or select \"Esc\" key)",
        content:    "/?theClip=" + theHtml ,
        player:     "iframe",
    });
		//height: 600,
		//width: 820
        //content:    "/html_main/temp_" + theHtml ,
}

function buildSlideshow() {
    XMLHttp_slide = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug;
    XMLHttp_slide.open("GET", "../cgi-bin/indexBuildSlideshow.cgi" + queryString, false);
    XMLHttp_slide.send(null);
    var returnString = XMLHttp_slide.responseText;
    //document.getElementById("slidePanel").innerHTML = returnString; 

    printDebugPanel ( {indexString: "buildSlideshow", returnString: returnString}, "slidePanel","none");
	$(".slidePanel-jcarousellite").jCarouselLite({
		vertical: false,
		hoverPause:true,
		visible: 1,
		auto:3000,
		speed:4000
	});
}

function buildStoryPanel() {
    XMLHttp_story = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug;
    XMLHttp_story.open("GET", "../cgi-bin/indexBuildStoryPanel.cgi" + queryString, false);
    XMLHttp_story.send(null);
    var returnString = XMLHttp_story.responseText;

    //document.getElementById( 'storyPanel' ).innerHTML = returnString;
    printDebugPanel ( {indexString: "buildStoryPanel", returnString: returnString}, "storyPanel", "none");

	$(".storyPanel-jcarousellite").jCarouselLite({
		vertical: false,
		hoverPause:true,
		visible: 3,
		auto:3000,
		speed:2000
	});
}

function getGalleryText(writeup) {
	addDebug(writeup);
    buildGalleryTextPanel(writeup);
}

function buildMenu() {
    XMLHttp_menu = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug + "&ipad=" + ipadFlag;
    XMLHttp_menu.open("GET", "../cgi-bin/indexBuildMenu.cgi" + queryString, false);
    XMLHttp_menu.send(null);
    var returnString = XMLHttp_menu.responseText;
	//addDebug(returnString);

    //document.getElementById( 'menuPanel' ).innerHTML = returnString;
    printDebugPanel ( {indexString: "buildMenu", returnString: returnString}, "menuPanel", "none");
}


function buildGalleryPanel() {
    XMLHttp_gallery = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug + "&theFile=" + theFile;
    XMLHttp_gallery.open("GET", "../cgi-bin/indexBuildGallerySlidePanel.cgi" + queryString, false);
    XMLHttp_gallery.send(null);
    var returnString = XMLHttp_gallery.responseText;
	//addDebug(returnString);

    //document.getElementById( 'mainPanel' ).innerHTML = returnString;
    printDebugPanel ( {indexString: "buildMainPanel", returnString: returnString, thePanel: thePanel, theFile: theFile }, "gallerySlidePanel","none");
	$(".gallerySlidePanel-jcarousellite").jCarouselLite({
		vertical: false,
		hoverPause:true,
		visible: 6,
		auto:3000,
		speed:2000
	});
}

function buildMainProcessStatus(theFile) {
    XMLHttp_status = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug + "&theFile=" + theFile;
    XMLHttp_status.open("GET", "../cgi-bin/indexBuildProcessStatus.cgi" + queryString, false);
    XMLHttp_status.send(null);
    var returnString = XMLHttp_status.responseText;

    var pos = returnString.indexOf("<input type=\"hidden\"");

    var hiddenString = returnString.substring(pos);
	var debugs = hiddenString.split('@');
	var newString = debugs[0];
    var pos =  newString.indexOf("theCount=");
	theCount = newString.substring(pos + 9);
	
	//alert(theCount);

    //document.getElementById( 'mainPanel' ).innerHTML = returnString;
    printDebugPanel ( {indexString: "buildStatus", returnString: returnString, thePanel: thePanel, theFile: theFile }, "mainPanel","none");
}

function buildMainProcessAnimalStoryArchive(theFile) {
    XMLHttp_animalStory = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug + "&theFile=" + theFile;
    XMLHttp_animalStory.open("GET", "../cgi-bin/indexBuildProcessAnimalStoryArchive.cgi" + queryString, false);
    XMLHttp_animalStory.send(null);
    var returnString = XMLHttp_animalStory.responseText;

    var pos = returnString.indexOf("<input type=\"hidden\"");

    var hiddenString = returnString.substring(pos);
	var debugs = hiddenString.split('@');
	var newString = debugs[0];
    var pos =  newString.indexOf("theCount=");
	theCount = newString.substring(pos + 9);
	
	//alert(theCount);

    //document.getElementById( 'mainPanel' ).innerHTML = returnString;
    printDebugPanel ( {indexString: "buildAnimalStoryArchive", returnString: returnString, thePanel: thePanel, theFile: theFile }, "mainPanel","none");
}

function buildMainPanel(theFile) {
    XMLHttp_main = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug + "&theFile=" + theFile;
    XMLHttp_main.open("GET", "../cgi-bin/indexBuildMainPanel.cgi" + queryString, false);
    XMLHttp_main.send(null);
    var returnString = XMLHttp_main.responseText;

    var pos = returnString.indexOf("<input type=\"hidden\"");

    var hiddenString = returnString.substring(pos);
	var debugs = hiddenString.split('@');
	var newString = debugs[0];
    var pos =  newString.indexOf("theCount=");
	theCount = newString.substring(pos + 9);
	
	//alert(theCount);

    //document.getElementById( 'mainPanel' ).innerHTML = returnString;
    printDebugPanel ( {indexString: "buildMainPanel", returnString: returnString, thePanel: thePanel, theFile: theFile }, "mainPanel","none");
}

function buildTestPanel(theFile) {
    XMLHttp_testPanel = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug + "&theFile=" + theFile;
    XMLHttp_testPanel.open("GET", "../cgi-bin/indexBuildTestPanel.cgi" + queryString, false);
    XMLHttp_testPanel.send(null);
    var returnString = XMLHttp_testPanel.responseText;

    var pos = returnString.indexOf("<input type=\"hidden\"");

    var hiddenString = returnString.substring(pos);
	var debugs = hiddenString.split('@');
	var newString = debugs[0];
    var pos =  newString.indexOf("theCount=");
	theCount = newString.substring(pos + 9);
	
	addDebug(theCount);

    //document.getElementById( 'mainPanel' ).innerHTML = returnString;
    printDebugPanel ( {indexString: "buildTestPanel", returnString: returnString, thePanel: thePanel, theFile: theFile }, "mainPanel","all");
}

function buildStatusPanel(theFile) {
    XMLHttp_statusTest = new XMLHttpRequest();
	var theUserAgent = navigator.userAgent;
	theUserAgent = theUserAgent.replace(";"," ");
    //addDebug ("theUserAgent=" + theUserAgent );
    var queryString = "?theDebug=" + debug + "&theFile=" + theFile
    + "&theGeoLoc=" + navigator.geolocation
    + "&theCookie=" + navigator.cookieEnabled
    + "&theLanguage=" + navigator.language
    + "&theProductSub=" + navigator.productSub
    + "&theProduct=" + navigator.product
    + "&theAppCodeName=" + navigator.appCodeName
    + "&theMime=" + navigator.mimeTypes
    + "&theVendprSub=" + navigator.vendorSub
    + "&theVendor=" + navigator.vendor
    + "&thePlatform=" + navigator.platform
    + "&theAppName=" + navigator.appName
    + "&theAppVersion=" + navigator.appVersion
    + "&theUserAgent=" + theUserAgent
    + "&thePlugins=" + navigator.plugins
    + "&theOnline=" + navigator.onLine
    + "&theJava=" + navigator.javaEnabled;
    XMLHttp_statusTest.open("GET", "../cgi-bin/indexBuildStatusPanel.cgi" + queryString, false);
    XMLHttp_statusTest.send(null);
    var returnString = XMLHttp_statusTest.responseText;

    var pos = returnString.indexOf("<input type=\"hidden\"");

    var hiddenString = returnString.substring(pos);
	var debugs = hiddenString.split('@');
	var newString = debugs[0];
    var pos =  newString.indexOf("theCount=");
	theCount = newString.substring(pos + 9);
	
	addDebug(theCount);

    //document.getElementById( 'mainPanel' ).innerHTML = returnString;
    printDebugPanel ( {indexString: "buildTestPanel", returnString: returnString, thePanel: thePanel, theFile: theFile }, "mainPanel","none");
}

function buildGalleryTextPanel(theFile) {
    XMLHttp_galleryText = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug + "&theFile=" + theFile;
    XMLHttp_galleryText.open("GET", "../cgi-bin/indexBuildGalleryTextPanel.cgi" + queryString, false);
    XMLHttp_galleryText.send(null);
    var returnString = XMLHttp_galleryText.responseText;
	//addDebug(returnString);
    //document.getElementById( 'mainPanel' ).innerHTML = returnString;

    //document.getElementById( 'mainPanel' ).innerHTML = returnString;
    printDebugPanel ( {indexString: "buildMainPanel", returnString: returnString, thePanel: thePanel, theFile: theFile }, "galleryTextPanel","none");
}

function buildFinishPanel() {
    XMLHttp_finish = new XMLHttpRequest();
    var queryString = "?theDebug=" + debug;
    XMLHttp_finish.open("GET", "../cgi-bin/indexBuildFinishPanel.cgi" + queryString, false);
    XMLHttp_finish.send(null);
    var returnString = XMLHttp_finish.responseText;
	//addDebug(returnString);

    //document.getElementById( 'finishPanel' ).innerHTML = returnString;
    printDebugPanel ( {indexString: "buildFinishPanel", returnString: returnString}, "finishPanel", "none");
}

function printDebugPanel (obj,aPanel, type) {
	//if ( debug == "true" ) {
		var returnString = "";
		var indexString = "";
        if(!obj) return;
        for(var key in obj) {
			if ( key == "returnString" ) {
				returnString = obj[key];
			} else if ( key == "indexString" ) {
				indexString = obj[key];
				addPanel("=== " + indexString + " ====== ");
			} else {
				//addPanel("    " + key + "= " + obj[key]);
			}
        }
        var pos = returnString.indexOf("<input type=\"hidden\"");
		//addDebug(pos);
        var mainString = returnString.substring(0,pos);
		if( type == "all" || type == "return") {
		    addDebug(mainString);
		}
		if ( aPanel != "" ) {
            document.getElementById( aPanel ).innerHTML = mainString;
		}
        var hiddenString = returnString.substring(pos);
	    var debugs = hiddenString.split('@');
	    for (var j=0; j < debugs.length -1; j++ ) {
		    if ( debugs[j] != "" ) {
				if ( type == "all" || type == "debug") {
		            addPanel("    " + debugs[j]);
				}
		    }
	    }
		addPanel("=== " + indexString + " ====== ");
	//}
}

function SwitchMenu(obj){
	if(document.getElementById){
		if ( obj == "sub0" ) {
	        var ar = document.getElementById("cont").getElementsByTagName("DIV");
			for (var i=0; i<ar.length; i++){
				ar[i].style.display = "none";
			}
		} else {
	        var el = document.getElementById(obj);
	        var ar = document.getElementById("cont").getElementsByTagName("DIV");
		    if(el.style.display == "none"){
			    for (var i=0; i<ar.length; i++){
				    ar[i].style.display = "none";
			    }
			    el.style.display = "block";
		    }else{
			    el.style.display = "none";
		    }
	    }
	}
}

function clearBlock(obj) {
	var ar = document.getElementById("cont").getElementsByTagName("DIV");
	for (var i=0; i<ar.length; i++){
		ar[i].style.display = "none";
	}
}
function undisplayBlock2(obj) {
}
function undisplayBlock(obj) {
	//var el = document.getElementById(obj);
	//el.style.display = "none";
	var ar = document.getElementById("cont").getElementsByTagName("DIV");
	if ( ipadFlag == "true" ) {
	    for (var i=0; i<ar.length; i++){
		    ar[i].style.display = "none";
	    }
	}
}

function displayBlock(obj) {
	var ar = document.getElementById("cont").getElementsByTagName("DIV");
	for (var i=0; i<ar.length; i++){
		ar[i].style.display = "none";
	}
	var el = document.getElementById(obj);
	el.style.display = "block";
}

function ChangeClass(menu, newClass) { 
	 if (document.getElementById) { 
	 	document.getElementById(menu).className = newClass;
	 } 
} 


function goLocation(newLocation) {
    //window.open( newLocation);
    location.href = newLocation;
}

function goHome() {
    location.href = "index.html";
}

var baseopacity=0;

function showtext(theText){
//alert(theText);
var newText = "<span class=maroon>" + theText + "</span>";
document.getElementById("statusText").innerHTML=newText;

}

function hidetext(){
document.getElementById("statusText").innerHTML="";
//cleartimer()
//instantset(baseopacity)
}

function setDebug(status) {
	if ( status == "on" ) {
        debug = "true";  // set this HERE
	} else {
        debug = "false";  // set this HERE
	}
    document.getElementById( 'submitForm' ).theDebug.value = debug;
    document.getElementById( 'inputText' ).value = "";
    document.getElementById( 'debugText' ).value =  "";
	buildMainPanel("");
	//window.location.search = [];
	initialization2();
}

function addPanel (text) {
	if ( debug == "false" ) {
		return;
	}
	//debugArray.push(text);
    document.getElementById( 'debugText' ).value +=  text;
    document.getElementById( 'debugText' ).value +=  "\n";
}

function initDebug () {
	if ( debug == "false" ) {
		return;
	}
    document.getElementById( 'debugText' ).value =  "";
}

function addDebug (text) {
	if ( debug == "false" ) {
		return;
	}
	text = "||  " + text;
	/* These need to be removed normally  */
    document.getElementById( 'debugText' ).value +=  text;
    document.getElementById( 'debugText' ).value +=  "\n";
	/*   This is the end of what is  need to be removed normally  */
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";




	},
	searchString: function (data) {
addDebug("length " + data.length);
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
addDebug( dataString + " " + dataProp + " " + data[i].versionSearch + " " + data[i].identity);
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

//window.onload = initialization;
/*
window.onresize = function(event) {
	bodyOffset = document.getElementById( 'body' ).offsetLeft;
    //addDebug(bodyOffset);
	document.getElementById( 'menuPanel' ).offsetLeft = bodyOffset + 'px';
}
*/

