var CURRENT_ANNOTATION = null;
var ELEMENT_NAME = 'A';
var AUTOLINK_DIRECTORY = '/assets/images/autolinks/';



function getAbsoluteLeft(o) {
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}
function getAbsoluteTop(o) {
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}
function getScreenWidth() { //{{{2
	if (document.all) return(document.body.clientWidth + document.body.scrollLeft)
	else return(window.innerWidth + window.scrollX)
}
function getScreenHeight() { //{{{2
	if (document.all) return(document.body.clientHeight + document.body.scrollTop)
	else return(window.innerHeight + window.scrollY)
} 
function intValue(val){
	return parseInt(parseFloat(val));
}
function showAnnotation(span)
{
	if(span.DIV==null)
	{
		span.DIV = document.createElement('DIV');
		
		
		var screengrab = new Image();
		screengrab.style.cursor = 'pointer';
		
		try{
			var src = span.className.split(' ')[1].split('_').join('.');
			screengrab.src = AUTOLINK_DIRECTORY+src;
			screengrab.width = 150;
			screengrab.height = 127;
			screengrab.onclick = function(){window.location=span.title+'.php';}
		}catch(e){
			//alert('err 55');
		}
		
		
		var closebutton = new Image();
		closebutton.className = 'close';
		closebutton.onclick = function(){this.parentNode.style.display='none';return false;};
		closebutton.src = '/assets/images/screenGrabs/closePopup.png';
		closebutton.onmouseover = function(){this.style.borderColor='Gray';}
		closebutton.onmouseout = function(){this.style.borderColor='Silver';}
		
		if(src)
		{
			span.DIV.appendChild(screengrab);
		}
		span.DIV.appendChild(closebutton);	
			
		span.DIV.style.left = (span.offsetWidth)+getAbsoluteLeft(span)-20+'px';
		span.DIV.style.position = 'absolute';
		span.DIV.style.top = (getAbsoluteTop(span) - 160)+'px';
		span.appendChild(span.DIV);	
		span.DIV.className = 'annotationPopup';
		
		if(document.all && navigator.userAgent.indexOf('MSIE 7')==-1)
		{
			span.DIV.style.background ='White';
			span.DIV.style.border = '1px solid Silver';
		}
		
	}
	else if(span.DIV==CURRENT_ANNOTATION)
	{
		return;
	}
	
	span.DIV.style.display='block';
	
	if(CURRENT_ANNOTATION!=null)
	{
		CURRENT_ANNOTATION.style.display = 'none';
	}
	CURRENT_ANNOTATION = span.DIV;
	
}

function buildAnnotations()
{
	var spans = document.body.getElementsByTagName(ELEMENT_NAME);
	for(var i in spans)
	{
		try{		
			if(spans[i].className.indexOf('annotation')!=-1)
			{
				spans[i].onmouseover = function(){
					showAnnotation(this);
				}
			}
		}
		catch(e){
			
		}
	}
}
