// JavaScript Document
/* This master JS file detects browsers, detects screen size, places flash, createsAJAXrequest, moves divs...*/

//ajax function to create a request
  var request = null;
function createRequest() 
  {try {
    request = new XMLHttpRequest();
  } catch (trymicrosoft) {
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        request = null;
      }
    }
  }

  if (request == null) {
    alert("Error creating request object!");
  } 
}




//incomplete function to return the browser
function findbrowser()
{
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
}




//creates getElementsByClassName
/*Written by Jonathan Snook, http://www.snook.ca/jonathan
Add-ons by Robert Nyman, http://www.robertnyman.com*/
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements);
}






//play sounds on the website
var ver=parseInt(navigator.appVersion);
var ie4=(ver>3  && navigator.appName!="Netscape")?1:0;
var ns4=(ver>3  && navigator.appName=="Netscape")?1:0;
var ns3=(ver==3 && navigator.appName=="Netscape")?1:0;

function playSound(source) {
 if (ie4) document.all['BGSOUND_ID'].src=source;
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-midi']
  && self.document.sound.IsReady()
 )
 {
  self.document.sound.play();
 }
}
//use stopSound() to stop it
//place lines below on the html page
<!--<BGSOUND id="BGSOUND_ID" LOOP=1 SRC="jsilence.mid"><EMBED NAME="sound" SRC="soundfile.mid" LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>
//<form name=myform>
//<input type=button value="Play Sound" onClick="playSound('soundfile.mid')">
//<input type=button value="Stop Sound" onClick="stopSound()">
//</form>



//decides if the highres page or lowres page should be displayed.  will need two web pages when used (highres one and lowres one)
function screensize(highres_source, lowres_source)
{
if ((screen.width>=1024) && (screen.height>=768))
{
 window.location=highres_source;
}
else
{
  window.location=lowres_source;
}
}





//incomplete function to display flash depending on url, width, height
function setflash(hurl, hdivID,hwidth,hheight)
{
	var url = hurl;
	var width = hwidth;
	var height = hheight;
	var divID = hdivID;
	
	var dot = url.indexOf(".");
	var smallerURL = url.substring(0,dot);

	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0',
			'movie', smallerURL,
			'width', width,
			'height', height,
			'src', smallerURL,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'bgcolor', '#333333',
			'name', divID,
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'salign', ''
			); //end AC code
	}
}
//place the code below in the header
//<script language="javascript">AC_FL_RunContent = 0;</script
//<script src="Scripts/AC_RunActiveContent.js" language="javascript"></script
//place the code below on the webpage
//<script type="text/javascript">setflash('flash/robot1.swf','robot1','100','163');</script
//<noscript>
//<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="100" height="163" id="flash1" align="middle">
  // <param name="allowScriptAccess" value="sameDomain" />
  // <param name="movie" value="flash/robot1.swf" />
  // <param name="quality" value="high" />
  // <param name="bgcolor" value="#333333" />
//<embed src="flash/robot1.swf" quality="high" bgcolor="#ffffff" width="100" height="163" name="flash1" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
//</object>
//</noscript>






//stops sounds on the website
function stopSound() {
 if (ie4) document.all['BGSOUND_ID'].src='images/jsilence.mid';
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-midi']
 )
 {
  self.document.sound.stop();
 }
}






//moves div from point a to point b to a to b
//script pulled from apple website.  I book marked it; there is more there.
//need to change it before it becomes master - used on hoboditty about page
var the_timeout;
var the_timeoutSTART;
var direction="down";
var change="no";
function moveDiv()
{
  // get the stylesheet
  //
  var new_bottom;
  var the_style = getStyleObject("myDivSTART");
  if (the_style)
  {
    // get the current coordinate and add 5
    //
    var current_bottom = parseInt(the_style.bottom);
	//alert(current_bottom + "ONE");
	if (direction == "up")
    {
      new_bottom = current_bottom + 3;
	  //alert("TWO - pt1: " + new_bottom);
    } 
    else 
    {
      new_bottom = current_bottom - 5;
	  //alert("TWO - pt2: " + new_bottom);
	}
	
	if (new_bottom > 0)
    {
      direction = "down";
	  clearTimeout(the_timeout); 
	  return false;
	  //alert("THREE - pt1: " + direction);
      //window.document.bee.src = "bee_left.gif";
    }

    if (new_bottom < -300)
    {
      direction = "up";
	  change = "yes";
    }
    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
    if (document.layers) 
    {
      the_style.bottom = new_bottom;
	  //alert("FOUR - pt1: " + new_bottom);
    }
    else 
    {  
      the_style.bottom = new_bottom + "px";
	  //alert("FOUR - pt2: " + new_bottom);
    }
    
    // if we haven't gone to far, call moveDiv() again in a bit
    // 
	//alert("FIVE: " + new_bottom);
	if(change=="yes")
	{
    	change="no";
		new_bottom = new_bottom + 20;
		the_timeoutSTART = setTimeout('moveDiv2();' ,1000);
	}
	else
	{
		the_timeout = setTimeout('moveDiv();',10);
	}
  }
}
function moveDiv2()
{
  // get the stylesheet
  //
  var new_bottom;
  var the_style = getStyleObject("myDiv");
  if (the_style)
  {
    // get the current coordinate and add 5
    //
    var current_bottom = parseInt(the_style.bottom);
	//alert(current_bottom + "TWO");
	if (direction == "up")
    {
      new_bottom = current_bottom + 4;
	  //alert("TWO - pt1: " + new_bottom);
    } 
    else 
    {
      new_bottom = current_bottom - 5;
	  //alert("TWO - pt2: " + new_bottom);
	}
	
	if (new_bottom > 0)
    {
      direction = "down";
	  change="yes";
	  //alert("THREE - pt1: " + direction);
      //window.document.bee.src = "bee_left.gif";
    }

    if (new_bottom < -800)
    {
      //direction = "up";
	  clearTimeout(the_timeoutSTART); 
	  return false;
	  //moveDiv();
	  //alert("THREE - pt2: " + direction);
      //window.document.bee.src = "bee_right.gif";
    }
    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
    if (document.layers) 
    {
      the_style.bottom = new_bottom;
	  //alert("FOUR - pt1: " + new_bottom);
    }
    else 
    {  
      the_style.bottom = new_bottom + "px";
	  //alert("FOUR - pt2: " + new_bottom);
    }
    
    // if we haven't gone to far, call moveDiv() again in a bit
    // 
	//alert("FIVE: " + new_bottom);
	if(change=="yes")
	{
    	change="no";
		the_timeout = setTimeout('moveDiv2();',4000);
		<!--document.write("<embed src='images/whatrulookinat.mp3'> ");document.write('<noembed>');document.write("<bgsound src='images/whatrulookinat.mp3'>");document.write('</noembed>');-->
		//playSound();
	}
	else
	{
		the_timeout = setTimeout('moveDiv2();',10);
	}
  }
}
//<a href="#" onClick="clearTimeout(the_timeout); return false;">stop wandering</a>
//test for browser - called from function above - need to change for it to be master
function getStyleObject(objectId) 
{
    // cross-browser function to get an object's style object given its
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	//alert("w3c" + objectId);
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	//alert("ms4");
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	//alert("nn4");
	return document.layers[objectId];
    } else {
	//alert("blah");
	return false;
    }
} // getStyleObject



