function debug (str)
{	 var db = document.getElementById("debug");
	 if(db) db.innerHTML +=  str + '<br>';
}

var xMoz= (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
var xSaf= navigator.userAgent.toLowerCase().indexOf("safari") != -1;
var fIE = !xMoz && !xSaf;

function attach(o, evt, fnc)
{  if (!fIE)
 { if (evt.substr(0,2).toLowerCase() == "on") evt = evt.substr(2);
  o.addEventListener(evt, fnc, false); // Hook the actual event  
 }
 else o.attachEvent(evt, fnc);
}

function init_anim()
{	 var hl = document.getElementById("seccal");
	 if(hl)
	 {	 var spans = hl.getElementsByTagName("span");
		 for(var i = 0; i < spans.length; i++)
		 {	var span = spans[i];
			if(span.className != "odd" && span.className != "even") continue;
			else span.onmouseover = function() {new oExpander(this);};
		 }
	 }
}

function oExpander(oSpn)
{	var inner = oSpn.getElementsByTagName("span");
	var oTh = '';
	var sImgSrc = '';
	var sTxt = '';
	var oHref = '';
	for(var j = 0; j < inner.length; j++)
	{	var ispan = inner[j];
		if (ispan.className == "text") sTxt = ispan.innerHTML
		if (ispan.className == "image") 
		{	oTh = ispan.getElementsByTagName("img")[0];
			sImgSrc = oTh.src.replace('/resizer.aspx?','').replace('width=124','').replace('&','').replace('url=','');
			oHref = ispan.getElementsByTagName("a")[0];
		}
	}

	if (oTh != '' )
	{	//define initial thumb settings and related variables
		this.oTh = oTh
		this.oTh.sTxt = sTxt;
		this.oTh.oHref = oHref;
		this.oTh.expander = this;
		this.oTh.oParent = this.oTh.offsetParent
		this.oTh.oGrandParent = this.oTh.oParent.offsetParent
		this.oTh.iOriginW = oTh.offsetWidth;
		this.oTh.iOriginH = oTh.offsetHeight;
		var iClientMarginWidth = document.body.clientWidth-970
		if (iClientMarginWidth < 0) iClientMarginWidth = 0;
		fIE?this.oTh.iOriginX = this.oTh.oParent.offsetLeft + this.oTh.oGrandParent.offsetLeft-5+(iClientMarginWidth /2):this.oTh.iOriginX = this.oTh.oParent.offsetLeft +(iClientMarginWidth /2);
		this.oTh.iOriginY = this.oTh.oParent.offsetTop + this.oTh.oGrandParent.offsetTop-5;
		this.bExpand = true;
		this.bTicks = false;
	
		// self organized list
		if ( !window.aoExpanders ) window.aoExpanders = new Array();
		window.aoExpanders.push(this);

		// create the full sized image.
		this.oImg = new Image();
		this.oImg.expander = this;
		this.oImg.onload = function(){this.expander.onload();}
		this.oImg.src = sImgSrc;
	}
}

oExpander.prototype.onload = function()
{	//create the element to house the magnified version of the object
	this.oDiv = document.createElement("div");
	this.oDiv.className='magnified';
	document.body.appendChild(this.oDiv);

	this.oAnchor = document.createElement("a");
	this.oDiv.appendChild(this.oAnchor);
	this.oAnchor.appendChild(this.oImg);

	// Add a text absrtact if one exists
	if (this.oTh.sTxt != '')
	{	this.oTxtDiv = document.createElement("span");
		this.oTxtDiv.className='text';

		this.oTxtDiv.innerHTML=this.oTh.sTxt;
		this.oDiv.appendChild(this.oTxtDiv);
	}

	// Add an anchor tag if one exists
	if (eval(this.oTh.oHref) != null) this.oAnchor.href = this.oTh.oHref;

	this.oDiv.expander = this;

	this.bgWdth = this.oImg.width;
	this.bgHght = this.oImg.height;
	
	if (this.bExpand) this.expand();
	else this.oDiv.style.visibility = this.oImg.style.visibility = "hidden";
}

oExpander.prototype.expand = function()
{	// set direction of expansion.
	this.bExpand = true;

	// set all other images to reduce
	for ( var i in window.aoExpanders )
		if ( window.aoExpanders[i] !== this )
			window.aoExpanders[i].reduce();

	// if not loaded, don't continue just yet
	if ( !this.oDiv ) return;

	// calculate initial dimensions
	this.x = this.oTh.iOriginX
	this.y = this.oTh.iOriginY
	this.w = this.oTh.clientWidth;
	this.h = this.oTh.clientHeight;

	this.oDiv.style.left = this.x + "px";
	this.oDiv.style.top = this.y + "px";
	this.oDiv.style.width = this.w + 10 + "px"; //need to take into account border on image
	this.oImg.style.width = this.w + "px";
	this.oDiv.style.height = this.oImg.style.height = this.h + "px";
	this.oDiv.style.visibility = "visible";
	this.oImg.style.visibility = "visible";

	// start the animation engine.
	if ( !this.bTicks )
	{	this.bTicks = true;
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},7);	
	}
}

oExpander.prototype.reduce = function()
{	this.bExpand = false;
}

oExpander.prototype.tick = function()
{	//the expanded item magnifies around the midpoint of the thumb image
	var cx = this.oTh.iOriginX + this.oTh.iOriginW / 2;
	var cy = this.oTh.iOriginY + this.oTh.iOriginH / 2;
	var iClientMarginWidth = document.body.clientWidth-970
	if (iClientMarginWidth < 0) iClientMarginWidth = 0;
	fIE?this.oTh.iOriginX = this.oTh.oParent.offsetLeft + this.oTh.oGrandParent.offsetLeft-5+(iClientMarginWidth /2):this.oTh.iOriginX = this.oTh.oParent.offsetLeft +(iClientMarginWidth /2);

	// calculate target
	var tw,th,tx,ty;
	if ( this.bExpand )
	{	tw = this.bgWdth;
		th = this.bgHght;
		tx = cx - tw / 2;
		ty = cy - th / 2; 
	}
	else
	{	tw = this.oTh.iOriginW;
		th = this.oTh.iOriginH;
		tx = this.oTh.iOriginX;
		ty = this.oTh.iOriginY;
	}	
	// move 5% closer to target
	var nHit = 0;
	var fMove = function(n,tn) 
	{	var dn = tn - n;
		if ( Math.abs(dn) <= 1 )
		{	nHit++;
			return tn;
		}
		else
		{	return n + dn / 7;
		}
	}

	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 + 10 + "px"; //need to take into account border on image
	this.oImg.style.width = this.w + "px";
	this.oImg.style.height = this.oDiv.style.height = this.h + "px";

	// if reducing and size/position is a match, stop the tick	
	if ( !this.bExpand && (nHit == 4) )
	{	this.oImg.style.visibility = "hidden";
		this.oDiv.style.visibility = "hidden";
		this.oTh.style.visibility = "visible";
		this.bTicks = false;
	}
	
	if ( this.bTicks )
	{	this.bTicks = true;
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},7);	
	}
}






