
// Internal
var headso=null, head1=null, head2=null;


// Browser detection

// Global variables
var browserversion=0.0;
var browsertype=0; // 0: unknown; 1:MSIE; 2:NN

// Return true if MSIE or NN detected
function browserdetect() {
  var agt= navigator.userAgent.toLowerCase();
  var appVer= navigator.appVersion.toLowerCase();
  browserversion= parseFloat(appVer);
  var iePos= appVer.indexOf('msie');
  if (iePos!=-1) browserversion= parseFloat(appVer.substring(iePos+5, appVer.indexOf(';',iePos)));
  var nav6Pos = agt.indexOf('netscape6');
  if (nav6Pos!=-1) browserversion= parseFloat(agt.substring(nav6Pos+10))
  browsertype= (iePos!=-1) ? 1 : (agt.indexOf('mozilla')!=-1) ? 2 : 0;
  return(browsertype>0);
}

browserdetect();



// General utils

// Find object by name or id
function headsobj(id) {
  var i, x;
  x= document[id];
  if (!x && document.all) x= document.all[id];
  for (i=0; !x && i<document.forms.length; i++) x= document.forms[i][id];
  if (!x && document.getElementById) x= document.getElementById(id);
  return(x);
}


// track mouseA
function headsmove(x, y) {
  var ex, ey, dx, dy;
  /*if (headso && head1 && head2 && headso.style) {
    ex=headso.offsetLeft+46; ey=headso.offsetTop+58;
    dx=x-ex; dy=y-ey;
    r=(dx*dx/49+dy*dy/289<1) ? 1 : Math.sqrt(49*289/(dx*dx*289+dy*dy*49));
    head1.style.left= r*dx+36.5; head1.style.top= r*dy+44;
    ex+=56; dx-=56;
    r=(dx*dx/49+dy*dy/289<1) ? 1 : Math.sqrt(49*289/(dx*dx*289+dy*dy*49));
    head2.style.left= r*dx+92.5; head2.style.top= r*dy+44;
  }*/
  SendDataToFlashMovie(x,y);
  
}



// Main
function heads() {
//  var img;
  var x, y, a=false;

  if (arguments.length==2) {
    x= arguments[0];
    y= arguments[1];
    a= true;
  }

  if (browsertype>0 && browserversion>=5) {
  
    headso=headsobj('headslayer');
    head1=headsobj('head1');
    head2=headsobj('head2');

    switch (browsertype) {
      case 1:
        document.onmousemove=headsmousemoveIE;
	break;
      case 2:
        document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove=headsmousemoveNS;
	break;
    }
  }
}


// Mouse move events
function headsmousemoveNS(e) {
  headsmove(e.pageX, e.pageY);
  //return(false);
}
function headsmousemoveIE() {
  headsmove(event.clientX+document.body.scrollLeft, event.clientY+document.body.scrollTop);
  //return(false);
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


heads();
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function SendDataToFlashMovie(x,y)
{
	var flashMovie=getFlashMovieObject("300x250_Rich_Dog");
	flashMovie.SetVariable("_root.javascriptXMouse", x - findPos(flashMovie)[0]);
	flashMovie.SetVariable("_root.javascriptYMouse", y - findPos(flashMovie)[1]);
	flashMovie.SetVariable("_root.insideFlash", false);
}