﻿// JavaScript Document www.GraphiteDesign.com 2008

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Xm,Ym - Mouse coordinates relative to top left corner of viewport
var Xm = 0
var Ym = 0

// get Mouse coordinates

function getMouseXY(e) {
  if (IE) {
    Xm = event.clientX + document.body.scrollLeft
    Ym = event.clientY + document.body.scrollTop
  } else {
    Xm = e.pageX
    Ym = e.pageY
  }  
  // catch possible negative values in NS4
  if (Xm < 0){Xm = 0}
  if (Ym < 0){Ym = 0}  

  // Geometry for keeping the centre of the mask on the mouse pointer
  
  // Xo,Yo - position of mask div relative to top left corner of viewport
  Xo = findPosX(document.getElementById('mask'));
  Yo = findPosY(document.getElementById('mask'));
  
  // Wo,Ho - width and height of mask div
  // Improvement would be to get these values dynamically
  Wo = 798
  Ho = 456
  
  // Wi,Yi - width and height of mask image (background
  // Improvement would be to get these values dynamically
  Wi = 2000
  Hi = 1200

  
  X = -(Xo-(Xm-Wi/2))
  Y = -(Yo-(Ym-Hi/2))
  
  if (X < Wo-Wi){X = Wo-Wi}
  if (Y < Ho-Hi){Y = Ho-Hi}  

  document.getElementById('mask').style.backgroundPosition = (X)+'px '+(Y)+'px';
  return true
}

	function findPosX(obj)
  {
    var curleft = 10;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}
function test(msg) { //v1.0
  alert(msg);
}
function over(elementID){
document.getElementById(elementID).style.backgroundPosition = "left bottom";
}
function notOver(elementID){
document.getElementById(elementID).style.backgroundPosition = "left top";
}
function playSound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}
function stopSound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Stop();
}

