var BackgroundTimerID = null, ScrollPosY = -578, scroll_side = true, side_scroll_amount = 1

var Container_Height
var Content_Height
var Relative_Location
var Leeway
var New_Top

var True = true
var False = false

function Create_String(character, repeat){
 var result = "", counter = 0
 while(counter++ < parseInt(repeat))
  result += character
 return result
}

function scroll_sidebar(){
 if(scroll_side){
   ScrollPosY > 698 ? ScrollPosY = 0 : ScrollPosY += side_scroll_amount
   document.getElementById("CSU_SideBar_OBJ").style.backgroundPosition = "0px " + ScrollPosY + "px"
 }
}

function Search_Active_IN(){
 scroll_side = false
}

function Search_Active_OUT(){
 scroll_side = true
}


function toggle_sidebar_scroll(){
 scroll_side = !scroll_side
}

function sidebar_scroll_on_off(){
 side_scroll_amount == 1 ? side_scroll_amount = 0 : side_scroll_amount = 1
}


function TH(num){
  num = parseInt(num)
  if(num >= 0){
    var one_digit = num % 10
    var two_digit = num % 100

    if((two_digit > 10 && two_digit < 14) ||  !(one_digit > 0 && one_digit < 4))
      return "th"
    else
      if(one_digit == 1)
        return "st"
      else
        if(one_digit == 2)
          return "nd"
        else
          if(one_digit == 3)
            return "rd"
  }else
     return ""
}

function TH_SPAN(num){
  num = parseInt(num)
  if(num >= 0){
    var one_digit = num % 10
    var two_digit = num % 100

    if((two_digit > 10 && two_digit < 14) ||  !(one_digit > 0 && one_digit < 4))
      return "th"
    else
      if(one_digit == 1)
        return "<span class = TH_CLASS>st</span>"
      else
        if(one_digit == 2)
          return "<span class = TH_CLASS>nd</span>"
        else
          if(one_digit == 3)
            return "<span class = TH_CLASS>rd</span>"
  }else
     return ""
}



function dig2it(n){
 var padding
 n > 9 ? padding = "" : padding = "0"
 return padding + n
}

function dig2it_reverse(n){
 var results
 if(n.slice(0,1) == "0")
   results = parseInt(n.slice(1,2))
 else
   results = parseInt(n)
 return results
}

function Pad_Num(n, pad){
 if(n > 1){
   var Num = Math.pow(n, 3)
   var Num_Digits = (Math.log(Num)/Math.log(1000))
   return Create_String("0", pad - Num_Digits) + n
 }else if(n == 1)
   return Create_String("0", pad - 1) + n
 else if(n == 0)
   return Create_String("0", pad)
 else
   return "invalid input"
}


function MouseX(e){
  return (window.event?(window.event.clientX-IE_Mouse_Offset):(window.captureEvents?e.clientX:0))
}

function MouseY(e){
  return (window.event?(window.event.clientY-IE_Mouse_Offset):(window.captureEvents?e.clientY:0))
}


function Initialize_Content_Area(obj){
/*
 var theY, theX, theMaxY = 400
 theY = (180 + (document.body.offsetHeight/2) - 89)/1.3
 if(theY > theMaxY)
   theY = theMaxY
 theX = Math.sqrt(250000 - theY*theY)
 obj.style.left = parseInt(730 - theX) + "px"
*/

 var theY, theX, theMaxY = 425, theTopY = 125
 theY = (180 + (document.body.offsetHeight/2) - theTopY)/1.3
 if(theY > theMaxY)
   theY = theMaxY
 theX = Math.sqrt(250000 - theY*theY)
 obj.style.left = parseInt(730 - theX) + "px"


}

function Initialize_Menu(obj){
 Container_Height = obj.offsetHeight
 Content_Height = obj.childNodes[0].offsetHeight
 Leeway = Content_Height - Container_Height
 if(Leeway < 0)
   obj.childNodes[0].style.top = (Leeway / -2) + "px"
 else
   obj.childNodes[0].style.top = "0px"
}

function Scroll_Menu(e){
 Container_Height = this.offsetHeight
 Content_Height = this.childNodes[0].offsetHeight
 Relative_Location = MouseY(e) - 88
 Leeway = Content_Height - Container_Height
 if(Leeway > 0){
   New_Top = -1 * Relative_Location * (Leeway/Container_Height)
   this.childNodes[0].style.top = New_Top + "px"
 }else{
   this.childNodes[0].style.top = (Leeway / -2) + "px"
 }
}


function g_mod(base, val){
  return ((val%base) <= 0 ? (base+(val%base)):(val%base))
}
function Prep_FLASH(){
 if (navigator.appName == "Microsoft Internet Explorer") {
    var arrElements = new Array(3);
    arrElements[0] = "object";
    arrElements[1] = "embed";
    arrElements[2] = "applet";
    for (n = 0; n < arrElements.length; n++) {
	//set object for brevity
	replaceObj = document.getElementsByTagName(arrElements[n]);
	//loop over element objects returned
	for (i = 0; i < replaceObj.length; i++ ) {
	//set parent object for brevity
				parentObj = replaceObj[i].parentNode;
				
				//grab the html inside of the element before removing it from the DOM
				newHTML = parentObj.innerHTML;
				
				//remove element from the DOM
				parentObj.removeChild(replaceObj[i]);
				
				//stick the element right back in, but as a new object
				parentObj.innerHTML = newHTML;
				}
			}
		}
}

function Prep_Various(){
  Prep_FLASH()
  document.getElementById("CSU_SideBar_OBJ").onmouseover = sidebar_scroll_on_off
  document.getElementById("CSU_SideBar_OBJ").onmouseout = sidebar_scroll_on_off
  document.getElementById("Search_Text_OBJECT").onfocus = Search_Active_IN
  document.getElementById("Search_Text_OBJECT").onblur = Search_Active_OUT

  Initialize_Menu(document.getElementById("Menu_Container_OBJECT"))
  Initialize_Content_Area(document.getElementById("Content_Container_OBJECT"))
  document.getElementById("Menu_Container_OBJECT").style.visibility = "visible"
  document.getElementById("Content_Container_OBJECT").style.visibility = "visible"
  document.getElementById("Menu_Container_OBJECT").onmousemove = Scroll_Menu
  document.getElementById("Menu_Container_OBJECT").onmouseover = sidebar_scroll_on_off
  document.getElementById("Menu_Container_OBJECT").onmouseout = sidebar_scroll_on_off
  BackgroundTimerID = setInterval("scroll_sidebar();", 85)
}

function Page_Resized(){
 Initialize_Menu(document.getElementById("Menu_Container_OBJECT"))
 Initialize_Content_Area(document.getElementById("Content_Container_OBJECT"))
}


function setCookie(name, value, expire) {
   document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}//Adapted from: DevEdge Online Documentation http://developer.netscape.com
function getCookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         end = document.cookie.indexOf(";", offset) 
         if (end == -1) 
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      } 
   }
}//Adapted from: DevEdge Online Documentation http://developer.netscape.com