//-----------------------------------------------------------------
// Copyright 1998-2003 Doug Bates
// All rights reserved.  http://darkwaters.org/copyright 
//
// All content including code, text, and media are my own original
// works unless otherwise noted.  Together this represents hundreds
// of hours of personal research, development, and testing over the
// past five years.
//
// Simply contact me first for permission to make use of or derive
// new work from this.  I very much support the exchange of
// technology / information and am generally happy to share. I am
// usually online and can be reached immediately.  All I tend to ask
// is that I retain credit for my creativity and knowledge of its
// dissemination.
//
//   - Doug Bates, Technical Consultant
//-----------------------------------------------------------------


var liveList= new Array();	// list of live objects
var mx, my;	// mouse X, Y
var lmx, lmy;	// last mouse X, Y


function initLB(){
	for(i= 0; i < document.all.length; i++)	// for every element in the document
		if(document.all(i).className == "livebutton")	addLB(document.all(i));	// add any 'livebutton's
	document.onmousemove= updateAll;
}

function addLB(obj){
	obj.cX= new Number();
	obj.cY= new Number();
//	obj.activeDist= new Number(obj.activeDist);
//	obj.normScale= new Number(obj.normScale);
//	obj.nearScale= new Number(obj.nearScale);

//	if (String(width)  =="undefined") var width= "100%";
//	if (typeof width == 'undefined') var width= "200";
//	if (formVal == "" || formVal == "undefined") {	formVal = emptyVal;	}
	
	// Assign default values (if not already defined in tag)
	if(typeof obj.activeDist == 'undefined') obj.activeDist= 200;
	if(typeof obj.normScale == 'undefined') obj.normScale= 0.50;
	if(typeof obj.nearScale == 'undefined') obj.nearScale= 1.5;
	obj.curScale= new Number(obj.normScale);

//	alert("aDist "+obj.activeDist+", normSc "+obj.normScale+", nearSc "+obj.nearScale);
//	alert("oWidth "+obj.width+", oHeight "+obj.height);

  if(obj.style.width > 0)	 obj.initWidth= parseInt(obj.style.width); else obj.initWidth= obj.scrollWidth;
  if(obj.style.height > 0)		obj.initHeight= parseInt(obj.style.height); else obj.initHeight= obj.scrollHeight;
	obj.lWidth= new Number(obj.initWidth);
	obj.lHeight= new Number(obj.initHeight);
	
//	alert("Width "+obj.style.width+", Height "+obj.style.height);

//	alert("iWidth "+obj.initWidth+", iHeight "+obj.initHeight);
	obj.updateLive= updateLiveF;
	liveList[liveList.length]= obj;
}

function updateLiveF(){ with(this){
//	alert("Width "+style.width+", Height "+style.height);
	cX= offsetParent.offsetLeft+offsetLeft+Math.floor(curScale*initWidth/2);
	cY= offsetParent.offsetTop+offsetTop+Math.floor(curScale*initHeight/2);

	var dx= mx-cX;
	var dy= my-cY;
	var dist= Math.sqrt(dx*dx+dy*dy);

//	alert("aDist "+activeDist+", normSc "+normScale+", nearSc "+nearScale+", Dist "+dist);

	if (dist >= activeDist) curScale= normScale; else 
	  curScale= (nearScale-normScale)*(activeDist-dist)/activeDist+normScale;

	var newWidth= curScale*initWidth;
	var newHeight= curScale*initHeight;
	if((newWidth != lWidth)||(newHeight != lHeight)){		// If noticable impact
// IE 5.5+ only!!!  ...slower, but much smoother rendering (antialiasing) and scales EVERYTHING
		style.filter= "progid:DXImageTransform.Microsoft.Alpha(opacity="+curScale*100+")";
//		style.zoom= curScale;		// Blacks out portions of PNG alpha channel!
//		style.marginRight= Math.ceil(initWidth*curScale*(1-curScale));	// Corrects for bug when using both alpha and zoom

	  style.width=curScale*initWidth;		// More compatible, lass attractive (anti-aliasing)
  	style.height=curScale*initHeight;
		lWidth= newWidth;
		lHeaght= newHeight;
	}
}}

function mouseMoved(e)	{	// Tests if mouse actually moved
	lmx=mx;
	lmy=my;
	mx=event.clientX;
	my=event.clientY;
	return (mx != lmx)||(my != lmy)
}

function updateAll(){
	if(mouseMoved(event))  {
		for(i= 0; i < liveList.length; i++)	liveList[i].updateLive();  // Update each

//		document.title= "Mouse: "+mx+", "+my+"  Element: "+event.srcElement.curScale+" "+event.srcElement.style.width;
//		navBar.style.left=(document.body.clientWidth-navBar.offsetWidth)/2;
	}
}


