var lastmenu = '';
var curmenu='';
var posx=0;
var posy=0;
var headerSmall=false;

//*******************************

// set sizes of header div here

var headerMax=150;
var headerMin=110;
var curHeader=headerMax;



// header id

changing='header';

function ShowElementInfo( iElementId )
{
  if( typeof(iElementId) == "string" && iElementId.length > 0 )
  {
   var element = document.getElementById(iElementId);
    if( element )
      alert("name=" + element.name + " - id=" + element.id +' height '+element.style.height);
    else
      alert("ERROR: could not find the requested element");
  }
}

function isMSIE() {
  return '\v' == 'v';
}


var nav=navigator.appName;
//
// find the inner HTML for id
//
function findAll(id)
{
    if(document.layers)
  {
   return document.layers[id];
  }

    if(document.all)
   {
    ob= document.all[id];
    return ob;
   }
  if(document.getElementById)
  {
   ob= document.getElementById(id);
   return ob;
  }

// not recognized
  {  alert('Your browser is not W3C complient -- site will not display properly. Try Chrome, MSIE, Firefox or Safari.');
		return null;
  }
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function getElement(aID)
    {
        return (document.getElementById) ? document.getElementById(aID) :document.all[aID];
    }

    function getIFrameDocument(aID){
        var rv = null;
        var frame=getElement(aID);
        // if contentDocument exists, W3C compliant (e.g. Mozilla)
        if (frame.contentDocument)
            rv = frame.contentDocument;
        else // bad Internet Explorer  ;)
            rv = document.frames[aID].document;
 return rv;
    }

    function adjustHeight(myFrame)
    {   //alert('h: ' + viewPort().height + '\r\nw: ' + viewPort().width);
        var frame = getElement(myFrame);
        var frameDoc = getIFrameDocument(myFrame);
        frame.style.height = 500;//viewPort().height;//frameDoc.body.offsetHeight;

    }


function getDocHeight() {
    var D = answer.document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function setWindow() {
xbody=findElement('abody');//document.getElementById('abody').style;
//alert(xbody);
wbody=900;
  var myWidth = 0, myHeight = 0;
  var w = 900;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;

    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;

    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if(myWidth<wbody)myWidth=wbody;
  m=Math.round((myWidth-wbody)/2);
  if(m<0)m=0;
  xbody.marginLeft=m+'px';

}

function findElement(id)
{
    if(document.layers)
  {
   return document.layers[id].style;
  }

//  if(nav=='Microsoft Internet Explorer')
    if(document.all)
   {
    ob= document.all[id].style;
    return ob;
   }
  if(document.getElementById)
  { // standardised method first
   ob= document.getElementById(id).style;
   return ob;
  }


// not recognized
  {  alert('Your browser is not supported. Use Chrome, MSIE, Firefox or Safari.');
		return null;
  }
}



function changeHeader()
 {
  curHeader=curHeader - 1;
  if(curHeader<=headerMin)
  { ob_header.height=headerMin+'px';
  return;
  }
//doAlert("change header cur = "+curHeader+" min= "+headerMin);
  window.setTimeout("changeHeader()",20);
  ob_header.height=curHeader+'px';
}

// grow up
var headerUpMin=0;
var curHeaderUp=100;

function growHeaderUp()
{
//  var ob= findElement('title');
//  if(curHeaderUp<=headerUpMin) return;
  curHeaderUp=curHeaderUp - 10;
  if(curHeaderUp<=headerUpMin)
  { ob_title.paddingTop=headerUpMin+'px';
  return;
  }
  window.setTimeout("growHeaderUp()",1);
  ob_title.paddingTop=curHeaderUp+'px';
}
// grow down
var headerDownMin=5;
var curHeaderDown=-100;

function growHeaderDown()
{
//  var ob= findElement('title');
//  if(curHeaderDown>=headerDownMin) return;
  curHeaderDown=curHeaderDown +5;
  if(curHeaderDown>=headerDownMin)
  { ob_title.top=headerDownMin+'px';
//    ob=findElement('header');
    ob_header.backgroundPosition='right';
    ob_header.backgroundColor='#FF3333';
  return;
  }
  window.setTimeout("growHeaderDown()",20);
  ob_title.top=curHeaderDown+'px';
}

// grow left

var headerMinPad=0;
var curHeaderPad=1000;

function growHeaderLeft()
{
//  if(isMSIE()){changeHeader();return;}
//  var ob= findElement('title');
//  if(curHeaderPad<=headerMinPad) return;

  curHeaderPad=curHeaderPad - 50;
  if(curHeaderPad<=headerMinPad)
  { ob_title.paddingLeft=headerMinPad+'px';
  return;
  }
  window.setTimeout("growHeaderLeft()",1);
  ob_title.paddingLeft=curHeaderPad+'px';
}

// grow right
var headerRightPad=100;
var curRightPad = 0;
function growHeaderRight()
{

  if((curRightPad+1)>=headerRightPad)
  { ob_title.width=headerRightPad+'%';
  return;
  }
  curRightPad=curRightPad +1;
  window.setTimeout("growHeaderRight()",1);
  ob_title.width=curRightPad+'%';
}

function doAlert(msg)
{
  alert(msg)
}

function setBackImage(at)
{
var img="Images/header_"+at+".jpg";        // note that 4, 5, 6 and 7 are photos

if(at==4 || at==5 || at==6 || at==7)
 {
 x=findAll('title');
 y=x.innerHTML;
 x.innerHTML=y.replace('_','Central American Team');
 }
if(at==0 || at==1 || at==2 || at==3 )
 {
 x=findAll('title');
 y=x.innerHTML;
 x.innerHTML=y.replace('_','');
 }
  if(at==5 || at==4)
  {
   ob_title.color='black';
  } // photos
  if(at==7)
  {
  ob_title.fontSize ='26px';
  ob_title.color='black';
  }
  if(at==6 )
  {
   ob_title.color='white';
  } // photos
  ob_header.backgroundImage="url('"+img+"')";
}

var ob_header,ob_title;

function setHeader()
{ setWindow();
  ob_header=findElement('header');
  ob_title =findElement('title');

  d=new Date();
  at=d.getDay();
//  at=d.getHours();
at=Math.floor(Math.random()*11);     // random number between 0 and 10
if(at>7)at=7;

{
 if(at==4 || at==5 || at==6 || at==7)setBackImage(at);  //photos are 4, 5, 6,7
 if(at==3 || at ==2 || at==1 || at==0)setBackImage(0);

 if(at==0)         changeHeader();                        // works in all browsers
 if(at==1)         growHeaderRight();                     // all
 if(at==2)        {growHeaderRight(); changeHeader();}
 if(at==3)         growHeaderLeft();                      // all  ??
 if(at==4)        {growHeaderLeft(); changeHeader();}     // all
 if(at==5 || at==7)         growHeaderUp();                       // all
 if(at==6)        { growHeaderDown();changeHeader(); }                     //

 if(at!=7)changeHeader();
}
}
//***************************************************

//document.onmouseover=getPos;

 function getPos(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
// alert("position: x= "+posx+" y= "+posy);
}

  function pausecomp(millis)
  {
  var date = new Date();
  var curDate = null;
 do { curDate = new Date(); }
 while(curDate - date < millis);
}

function clearDropped(objID)
{
if (curmenu=='')return;
if(lastmenu=='')return;
if (!document.getElementById) return;
var ob = document.getElementById(lastmenu).style;
ob.display = (ob.display == 'block')?'none': 'block';
//alert(curmenu+' '+lastmenu);
}

function toggleMenu(objID)
{
 lastmenu=curmenu;
 curmenu=objID;
 changeHeader();
 window.clearInterval();
if (!document.getElementById) return;
clearDropped(objID);
var ob = document.getElementById(objID).style;
ob.display = (ob.display == 'block')?'none': 'block';
}

speed=2000;



//setInterval("changeLink('Base Text')", speed);

function changeLinks(newID,newLink)
{document.getElementById(newID).target=newID;
document.getElementById(newID).src=newLink;
// alert (newID+ '  '+newLink+'  '+document.getElementById(newID).target);

}

function changeLink(newText)
{
document.getElementById('text').innerHTML=newText;
document.getElementById('text').href='';
document.getElementById('myAnchor').target="_self";
}

function mouseOn(a_id)
{
document.getElementById(a_id).style.color="red";
document.getElementById(a_id).style.textDecoration="bold";
document.getElementById(a_id).style.fontSize="16";
//borderStyle="inset";

}

function mouseOut(a_id)
{
document.getElementByName(a_id).style.color="black";
document.getElementByName(a_id).style.textDecoration="none";
document.getElementByName(a_id).style.fontSize="15";
}

function calcHeight()
{
if(nav=='Opera') return;
  //find the height of the internal page
   the_height=document.getElementById('answer').contentWindow.document.body.scrollHeight;
   document.getElementById('answer').style.height='1px';
  //change the height of the iframe
if(isMSIE()) { document.getElementById('answer').style.height= 50+the_height+'px'; return;}

  curHeight=1;
  changeAnswer(1);
}

curHeight=1;

function changeAnswer(curHeight)
 { the_obj='answer';

  var minHeight=document.getElementById(the_obj).contentWindow.document.body.scrollHeight;

  if(curHeight>=minHeight) return;
//  if(isMSIE())  g=setTimeout('changeAnswer(curHeight)',-5);
  curHeight=curHeight + 100;
  if(curHeight>=minHeight)
   { document.getElementById(the_obj).style.height=curHeight+'px'; //ob.height=minHeight+'px';
   return;
   }
//  t=window.setTimeout(function(thisObj) { thisObj.changeAnswer(curHeight); },-5,this);

  document.getElementById(the_obj).style.height=curHeight+'px';  //ob.height=curHeight+'px';
  changeAnswer(curHeight);
}

function setHeader_Photos(at)
{
  if(at==0 && parent.document.getElementById('header').style.visibility=='hidden' ) return;
if(at==0) parent.document.getElementById('header').style.visibility='hidden';

if(at>0)
 parent.document.getElementById('header').style.visibility='visible';

  parent.document.getElementById('header').style.height=at+'px';
 //   alert(parent.document.getElementById('header').style.height);
//ob.top='5px';

}
