

function DivExpander(oLink,oText,sticky,oWidth,oHeight,nWidth,nHeight,offsetWidth,offsetHeight)
{
       // alert(DivExpander);
	// store thumbnail image and overwrite its onclick handler.
	 if (this == currentBox){
           return false;
         }
        currentBox = this;
        this.bText = false;
        this.oText = document.getElementById(oText).innerHTML;
	this.oLink = document.getElementById(oLink);
	this.sticky = sticky?true:false;
	this.oLink.expander = this;
	//this.oLink.onclick = function() {this.expander.expand(); }

        if (this.sticky){
          this.originX = mouseX;
          this.originY = mouseY;
        }

        //window.setTimeout(function(){this.expand();},10);
        //this.oLink.onload = function(){this.expander.onload();}

	 //this.oLink.style.visibility='hidden';
	// record original size
	this.smallWidth = oWidth;   //small width;
	this.smallHeight =oHeight;  //small height;
	this.bigWidth = nWidth;     //target width
	this.bigHeight = nHeight;   //target height
	this.offsetWidth = offsetWidth;   //offset Width
	this.offsetHeight = offsetHeight; //offset Height

	this.bExpand = false; //true;
	this.bTicks = false;
        //this.oLink.style.visibility='hidden';
 	this.oLink.expander.onload();

	// self organized list
	if ( !window.aDivExpanders )
	{
		window.aDivExpanders = new Array();
	}
	window.aDivExpanders.push(this);

	// create the full sized image.
	//this.oImg = new Image();
	//this.oImg.expander = this;
	//this.oLink.onload = function(){this.expander.onload();}
	//this.oImg.src = sImgSrc;
//	this.oPDiv = document.createElement("div");
//	this.oPDiv.expander = this;
	//document.body.appendChild(this.oPDiv);
//	this.oPDiv.onload = function(){alert('test');this.expander.onload();}
	//this.expander.onload();
	this.oLink.expander.expand();
}

DivExpander.prototype.onload = function()
{      

	this.oDiv = document.createElement("div");
//	this.oDiX = document.createElement("div");
	document.body.appendChild(this.oDiv);
	//this.oDiv.appendChild(this.oImg);

	this.oDiv.style.position = "absolute";
	this.oDiv.style.background = "#cccccc";
	this.oDiv.style.width = this.bigWidth;
	this.oDiv.style.height = this.bigHeight;

//	this.oDivX.style.width = "20";
//	this.oDivX.style.height = "20";
	this.oDiv.style.background = "#aaaaaa";
//	this.oDiv.style.float = "right"
//	this.oDiv.appendChild(this.oDivX);

	this.oDiv.expander = this;
        //this.oDiv.innerHTML = 'onload';
	//this.oDiv.onclick = function() {this.expander.toggle();};
	//this.oDiv.onload = function(){this.expander.onload();}

        //this.oHtml = document.getElementById('a'+ this.oText +'desc').innerHTML;

        //this.oDiv.innerHTML = '<span style="font-family:arial;font-size:12pt;text-align:center;">loading...</span>';

        //this.oDivX = document.getElementById('ax'+ this.oText);
	//this.oDivX.expander = this;
        this.oDiv.onclick = function() {this.expander.reduce(); }
	//this.oDiv.onmouseout = function() {this.expander.reduce(); }

        //this.oImg.title = "Click to reduce.";
	this.oDiv.expander.expand();
        //alert(document.getElementById('a'+ this.oText +'desc').style.height);
	//this.bigWidth = 200;//this.oImg.width;
	//this.bigHeight = 100;//document.getElementById('a'+ this.oText +'desc').style.height;//20;//this.oImg.height;
	
	if ( this.bExpand )
	{
		this.expand();

	}
	else
	{
	//	this.oDiv.style.visibility = "hidden";
		//this.oImg.style.visibility = "hidden";

	}
}
DivExpander.prototype.toggle = function()
{


	this.bExpand = !this.bExpand;
	if ( this.bExpand )
	{
         	this.oDiv.innerHTML = ' ';
		for ( var i in window.aDivExpanders )
			if ( window.aDivExpanders[i] !== this ){
				window.aDivExpanders[i].reduce();

			}
	}else {
         	this.oDiv.innerHTML = '&nbsp;';          
        }
}
DivExpander.prototype.expand = function()
{
       //  this.oDiv.innerHTML = 'expand: ' + this.bExpand;
       if (!this.bExpand){

        //alert('expand');
	// set direction of expansion.
	this.bExpand = true;
        this.bTicks = false;

	// set all other images to reduce
	for ( var i in window.aDivExpanders ){
		if ( window.aDivExpanders[i] !== this ){
		  try {window.aDivExpanders[i].reduce()}
		  catch (e){//nothing
                  }
                     //	window.aDivExpanders[i].reduce();
		      //window.aDivExpanders[i].oDiv.innerHTML = '';

                }
        }
	// if not loaded, don't continue just yet
	//if ( !this.oDiv ) return;
	
	// hide the thumbnail
	//this.oThumb.style.visibility = "hidden";
        //imgAction(false);
	
	// calculate initial dimensions
	var coords = findPos(this.oLink);
	//alert(coords);
	if (this.sticky){
          coords[0]=this.originX-3;
          coords[1]=this.originY-3;
         }
	this.x = coords[0]+ this.offsetWidth;; //this.oThumb.offsetLeft;
	this.y = coords[1]+ this.offsetHeight;; //this.oThumb.offsetTop;

	this.w = this.smallWidth;//this.oThumb.clientWidth;
	this.h = this.smallHeight;//this.oThumb.clientHeight;
        //this.oLink.style.visibility='visible';
	this.oDiv.style.background = "#F6F6F8";
	this.oDiv.style.left = this.x + "px";
	this.oDiv.style.top = this.y + "px";
	this.oDiv.style.width = this.w + "px";
	this.oDiv.style.height = this.h + "px";
	this.oDiv.style.visibility = "visible";
	this.oDiv.style.zIndex=10;
	this.oDiv.className="infoBox";
	this.oDiv.style.border='1px #B4B4B9 solid';
	//this.oDiv.className = 'descBox';
	this.oDiv.innerHTML = ' ';
	//this.oImg.style.visibility = "visible";
    }
	// start the animation engine.
	if ( !this.bTicks )
	{
		this.bTicks = true;
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},20);
	}

}
DivExpander.prototype.reduce = function()
{
	// set direction of expansion.
	this.bExpand = false;
	this.bTicks = true;
	this.bText = false;
	this.oDiv.style.zIndex=9;
	this.oDiv.style.background = "#DADAE0";
	this.oDiv.style.border='1px #B4B4B9 solid';
	this.oDiv.innerHTML = '&nbsp;';

}
DivExpander.prototype.tick = function()
{
        //var obj = document.getElementById('imgBox');
	// calculate screen dimensions
	var cw = document.body.clientWidth;
	var ch = document.body.clientHeight;
	//var coords = findPos(obj);
	var coords = findPos(this.oLink);
	 if (this.sticky){
          coords[0]=this.originX-3;
          coords[1]=this.originY-3;
         }
         //alert((coords[0]+this.bigWidth)+':'+coords[1]);
         //alert(cw+'x'+ch);
         if ((coords[0]+this.bigWidth) > cw){
          coords[0] =cw - this.bigWidth;
         }
	var cx = coords[0] + (this.bigWidth / 2)+ this.offsetWidth;//document.body.scrollLeft + cw / 2;//coords[0] + cw / 2; //
	//if (ch > 75){changeh = 35;}else{changeh=0;}
	var cy = coords[1]+ (this.bigHeight / 2)+ this.offsetHeight;//document.body.scrollTop + (ch / 2);//(coords[1]-50) + cw / 2; //

	// calculate target
	var tw,th,tx,ty;
	if ( this.bExpand )
	{


		tw = this.bigWidth;
		th = this.bigHeight;
		if ( tw > cw )
		{
			th *= cw / tw;
			tw = cw;
		}	
		if ( th > ch )
		{
			tw *= ch / th;
			th = ch;
		}
		tx = cx - tw / 2;
		ty = cy - th / 2; 
	}
	else
	{
		tw = this.smallWidth;
		th = this.smallHeight;

                //var coords = findPos(this.oLink);
	        tx = coords[0]; //this.oThumb.offsetLeft;
	        ty = coords[1]; //this.oThumb.offsetTop;
		//tx = this.oThumb.offsetLeft;
		//ty = this.oThumb.offsetTop;
	}	
	// move 5% closer to target
	var nHit = 0;
	var fMove = function(n,tn) 
	{
		var dn = tn - n;
		if ( Math.abs(dn) < 3 )
		{
			nHit++;
			return tn;
		}
		else
		{
			return n + dn / 3;
		}
	}
	this.x = fMove(this.x, tx);
	this.y = fMove(this.y, ty);
	this.w = fMove(this.w, tw);
	this.h = fMove(this.h, th);



	this.oDiv.style.left = this.x + "px";
	this.oDiv.style.top = this.y + "px";
	this.oDiv.style.width = this.w + "px";
	this.oDiv.style.height = this.h + "px";

	// if reducing and size/position is a match, stop the tick
       if ( !this.bExpand )
       {
                  //  this.oDiv.innerHTML = nHit;
	//this.oDiv.style.height = this.h + "px";
      }

	if ( !this.bExpand && (nHit > 1) )
	{
		//this.oImg.style.visibility = "hidden";
		this.oDiv.style.visibility = "hidden";
		    //    this.oLink.style.visibility='visible';
		//this.oThumb.style.visibility = "visible";
		//imgAction(true);

		this.bTicks = false;


	} else if ( this.bExpand && (nHit == 4) && !this.bText ) {
        //alert('expantion done');
            this.bText = true;
    	  //  this.oDiv.style.height = document.getElementById('a'+ this.oText +'desc').style.height; //"200px";
            //this.bigHeight = parseInt(this.oDiv.style.height);
            this.oDiv.innerHTML = this.oText;

    	    //if (this.oHtml.length < 200){
            //  this.oDiv.style.height = 100 + "px";
            //}
          //this.bExpand = false;
          //this.bTicks = false;
        }
	
	if ( this.bTicks )
	{
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},20);
	} else {
          //alert(this.oText + ' done');
        }
}




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];
}
//--------------------------------------------
//--------------------------------------------
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var mouseX = 0
var mouseY = 0

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.body.scrollLeft
    mouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX
    mouseY = e.pageY
  }
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}
  return true
}