var compatible = (document.getElementsByTagName && document.createElement);

/* Page heading pictures sliding */

// Constants
var totalWidth  = 781;
var maxWidth    = 285;
var minWidth    = 124;
var absMaxWidth = maxWidth - minWidth;
var timerTime   = 15; // Milliseconds

// Varables
var isFirstTime = true;
var lands       = Array(5);
var landpics    = Array(5);
var siteLand    = null;
var currLand    = null;
var landsIn     = 0;
var Timer       = null;

function land_over(over, site)
{
  if (!compatible) return;
  landsIn++;
  currLand = over;
  if (isFirstTime) land_init(site);
  if (!Timer) Timer = setInterval('land_slide()', timerTime)
}
function land_out()
{
  if (!compatible) return;
  landsIn--;
  if (landsIn < 0) landsIn = 0;
  if (!landsIn) currLand = siteLand;
}
function land_init(site)
{
  isFirstTime = false;
  siteLand    = site;
  for (var i=0; i < 5; i++){
    lands[i]    = document.getElementById('landcell'+i);
    landpics[i] = document.getElementById('landpic' +i);
  }
  // Background pictures flickering solution by Dan Popa (Mister Pixel), an undocumented IE command
  if (navigator.appName == 'Microsoft Internet Explorer') document.execCommand('BackgroundImageCache', false, true);
}
function land_slide()
{
  var inter = 0; // Number of lands with intermediate widths
  var curr  = currLand; // Current (widening) land
  var incr  = null;
  var w     = null;
  
  w = parseInt(lands[curr].width);
  if (w != maxWidth){  
    var absCurrWidth = w - minWidth;
    if (absCurrWidth <= absMaxWidth / 2) incr = parseInt(Math.sqrt(absCurrWidth)); 
    else incr = parseInt(Math.sqrt(Math.abs(absCurrWidth - absMaxWidth)));
    if (incr <= 0) incr = 1;
    w += incr;
    if (w > maxWidth) w = maxWidth;
    lands[curr].width = w;
    landpics[curr].width = w - 3;
  }
  for (var i=0; i < 5; i++){   
    if (i != curr){
      if (lands[i].width == minWidth) continue;
      var otherWidths = 0;
      for (var j=0; j < 5; j++){
        if (i != j) otherWidths += parseInt(lands[j].width);
      } 
      w = parseInt(totalWidth - otherWidths);
      if (w < minWidth) w = minWidth;
      if (w != maxWidth && w != minWidth) inter++;
      lands[i].width = w;
      landpics[i].width = w - 3;
    }
  }
  if (!inter && curr == siteLand && lands[curr].width == maxWidth){
    clearInterval(Timer);
    Timer = null;
  } 
/**
var n = 0;
for (var i=0; i < 5; i++) n += parseInt(lands[i].width);
window.status = '['+isFirstTime+'] ['+n+'] ['+incr+']';
/**/
}

/* Suckerfish Menu by Patrick Griffiths and Dan Webb */
/* http://www.htmldog.com/ http://www.danwebb.net/ */

if (compatible)	document.write('<link rel="stylesheet" type="text/css" href="/navstyles.css">');

sfHover = function(){
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
