// Shorthand
var d=document;

// Preload images
pre_img=new Image(); 
pre_img.src="/phpimg.php?img=mlist-r.gif";

// Reserve space for scrollbar (CSS 3)
d.write('<style type="text/css"> html { overflow-y: scroll; } </style>');

// Protect e-mail addresses from harvester bots
function email(name,domain,subj,cls) {
 var addr=name+'@'+domain;
 var addrt=(subj)?addr+'?subject='+subj:addr;
 cls=(cls=='')?'':'class="'+cls+'" ';
 document.write('<a '+cls+'href="mailto:'+addrt+'">'+addr+'</a>');
}

// Code for moving the ship - windowH() is not used

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a zero (indicating the use of another browser)
{
 var rv=0; // Return value assumes failure
 if(navigator.appName=='Microsoft Internet Explorer')
 {
  var ua=navigator.userAgent;
  var re=new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  if(re.exec(ua)!=null) rv=parseFloat(RegExp.$1);
 }
 return rv;
}

function windowW()
{
 var ww=0;
 if(typeof(window.innerWidth)=='number') ww=window.innerWidth; //Non-IE
 else if(d.documentElement && (d.documentElement.clientWidth || d.documentElement.clientHeight)) ww=d.documentElement.clientWidth; //IE 6+ in 'standards compliant mode'
 else if(d.body && (d.body.clientWidth || d.body.clientHeight)) ww=d.body.clientWidth; //IE 4 compatible
 return ww;
}
function windowH()
{
 var wh=0;
 if(typeof(window.innerWidth)=='number') wh=window.innerHeight; //Non-IE
 else if(d.documentElement && (d.documentElement.clientWidth || d.documentElement.clientHeight)) wh=d.documentElement.clientHeight; //IE 6+ in 'standards compliant mode'
 else if(d.body && (d.body.clientWidth || d.body.clientHeight)) wh=d.body.clientHeight; //IE 4 compatible
 return wh;
}

var defaultw=20; // in case mi.width is undefined, needs to be global
var sb=18; // allow for scrollbar, needs to be global
if(document.all) sb=2; // simple test for IE which doesn't include the scrollbar
var step=1; // pixels per step, needs to be global

function setupship()
{
 var ie=getInternetExplorerVersion();
 if(ie && ie<8) return false;
 if(typeof(defaultw)=='undefined') alert('defaultw is not defined'); // defaultw is setup with the functions
 if(typeof(sb)=='undefined') alert('sb is not defined'); // sb is setup with the functions
 if(typeof(step)=='undefined') alert('step is not defined'); // step is setup with the functions
 var wwidth=windowW()-sb;
 var pwidth=parseInt(d.getElementById('wrapper').style.width);
 if(!pwidth) alert('pwidth is not defined');
 var pmargin=Math.round((wwidth-pwidth)/2);
 var phided=30;
 var randship=Math.round(Math.random())+1;
 var randside=Math.round(Math.random()); // 0 = left, 1 = right
 var randposi=Math.floor(Math.random()*(pmargin+phided));
 var randpos=0;
 if(randside)
 {
  randpos=pmargin+pwidth-phided-defaultw+randposi;
  if(randpos>(pmargin+pwidth)) step=(Math.round(Math.random()))?step:-step;
 } else
 {
  randpos=randposi;
  if(randpos>pmargin) step=-step;
  else step=(Math.round(Math.random()))?step:-step;
 }
// d.write('<a href="javascript:alert(\'nothing here yet\')" onclick="if(this.blur()) this.blur()" id="ship" style="position:absolute;top:243px;left:'+randpos+'px;background:url(/phpimg.php?img=ship'+randship+'.gif) no-repeat;width:20px;height:16px;z-index:2"></a>');
 d.write('<div id="ship" style="position:absolute;top:243px;left:'+randpos+'px;background:url(/phpimg.php?img=ship'+randship+'.gif) no-repeat;width:20px;height:16px;z-index:2"></div>');
}

function moveship(iid)
{
 var ie=getInternetExplorerVersion();
 if(ie && ie<8) return false;
 var mi=d.getElementById(iid);
 movieit(mi)
}

function movieit(mi)
{
 var delay=100+Math.floor(Math.random()*900); // sets the speed
 var xwidth=(typeof(mi.Width)=='undefined')?defaultw:mi.width;
 var wwidth=windowW()-sb;
 var lft=parseInt(mi.style.left);
 var tim=setTimeout(function(){movieit(mi)},delay);
 if(lft>wwidth-xwidth && step>0) step=-step;
 else if(lft<-xwidth && step<0) step=-step;
 lft=lft+step; // move by # pixels
 mi.style.left=lft+"px";
}

// end of code for moving the ship

