﻿/*
//This section is used for the animation
*/

var speed = 30;
var changeDimFlag = false;
var elementWidth = 10;
var elementHeight = 5;
var finalElementWidth = 200;
var finalElementHeight = 75;
var showTimeOutID;
var hideTimeOutID;
var changeDimTimeOutID;
var leftOffset = 0;
var topOffset = 11;

var delay = 100;

function processMouseOver(e){
    clearTimeout(hideTimeOutID);
    showTimeOutID = setTimeout("growDiv()", delay);
}

function processMouseOut(e){
    clearTimeout(hideTimeOutID);
    hideTimeOutID = setTimeout("shrinkDiv()", delay);
}

function GetElementPointerById(fieldID){
    var pFld;
    pFld = (document.getElementById) ? document.getElementById(fieldID) : 
            ((document.all) ? document.all(fieldID) : null);
            
    return pFld;            
}

function changeDimensions(){
    var transparentDiv; // transparentDiv
    var animationSpeed = 0;
    
    transparentDiv = GetElementPointerById("transparentDiv");
    
    if ((elementWidth > finalElementWidth)&&(elementHeight > finalElementHeight) && (!changeDimFlag)){
        changeDimFlag = true;
        showTextDiv();
        return;
    }
    else if((elementWidth < speed)&&(elementHeight < speed) && (changeDimFlag)){
        changeDimFlag = false;
        hideTextDiv();
		return;
    }
    
    if (changeDimFlag){
        if (elementWidth > speed){
            elementWidth -= speed;   
        }
        
        if (elementHeight > speed){
            elementHeight -= speed;
        }
    }
    else{        
        if (elementWidth < finalElementWidth){
            elementWidth += speed;
        }
        
        if (elementHeight < finalElementHeight){
           elementHeight += speed; 
        }
    }
    
 	transparentDiv.style.width = elementWidth + 'px';
 	transparentDiv.style.height = elementHeight + 'px';
 	changeDimTimeOutID = setTimeout("changeDimensions();",0);    
}

function growDiv(){
	
	if(changeDimFlag){
		return;
	}
	
	var transparentDiv;
	var contactInformationDiv;
	var contactLink;

	transparentDiv = GetElementPointerById("transparentDiv");
	contactInformationDiv = GetElementPointerById("contactInformationDiv");
	contactLink = GetElementPointerById("contactLink");

	transparentDiv.style.visibility = "visible";
	contactInformationDiv.style.visibility = "hidden";

	transparentDiv.style.left =  getposOffset(contactLink, "left") + leftOffset + "px";
	transparentDiv.style.top  = getposOffset(contactLink, "bottom") + topOffset + "px";

	changeDimensions();
}

function shrinkDiv(){

	if(!changeDimFlag){
		return;
	}

	var transparentDiv;
	var contactInformationDiv;
	var contactLink;
	
	changeHeightFlag = 1;
	changeWidthFlag = 1;

	transparentDiv = GetElementPointerById("transparentDiv");
	contactInformationDiv = GetElementPointerById("contactInformationDiv");
	contactLink = GetElementPointerById("contactLink");

	transparentDiv.style.visibility = "visible";
	contactInformationDiv.style.visibility = "hidden";

	transparentDiv.style.left =  getposOffset(contactLink, "left") + leftOffset + "px";
	transparentDiv.style.top  = getposOffset(contactLink, "bottom") + topOffset + "px";

	changeDimensions();
}

function showTextDiv(){

	if(changeDimFlag){
		var contactInformationDiv;
		var transparentDiv;

		transparentDiv = GetElementPointerById("transparentDiv");
		contactInformationDiv = GetElementPointerById("contactInformationDiv");	

		contactInformationDiv.style.visibility = "visible";
		transparentDiv.style.visibility = "hidden";
		
		contactInformationDiv.style.top = transparentDiv.style.top;
		contactInformationDiv.style.left = transparentDiv.style.left;	

		clearTimeout(changeDimTimeOutID);
		clearTimeout(hideTimeOutID);
	}
}

function hideTextDiv(){
	if(!changeDimFlag){
		var contactInformationDiv;
		var transparentDiv;
		transparentDiv = GetElementPointerById("transparentDiv");
		contactInformationDiv = GetElementPointerById("contactInformationDiv");

		contactInformationDiv.style.visibility = "hidden";
		transparentDiv.style.visibility = "hidden";
		
		clearTimeout(changeDimTimeOutID);
		clearTimeout(hideTimeOutID);	
	}
}

// Adding event listeners to the link and div tag
function attachMouseEvents(e){	
	var contactInformationDiv;
	var contactLink;

	contactInformationDiv = GetElementPointerById("contactInformationDiv");
	contactLink = GetElementPointerById("contactLink");

	if (window.addEventListener) {
		contactLink.addEventListener("mouseover", processMouseOver, false);
		contactLink.addEventListener("mouseout", processMouseOut, false);
		contactInformationDiv.addEventListener("mouseover", processMouseOver, false);
		contactInformationDiv.addEventListener("mouseout", processMouseOut, false);
	}
	else if (window.attachEvent){
		var r;
		r = contactLink.attachEvent("onmouseover", processMouseOver);
		r = contactLink.attachEvent("onmouseout", processMouseOut);
		r = contactInformationDiv.attachEvent("onmouseover", processMouseOver);
		r = contactInformationDiv.attachEvent("onmouseout", processMouseOut);
	}
}


/*
// This following section is used for showing the hint
*/

var horizontal_offset = "-50px"; //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset = "30px"; //horizontal offset of hint box from anchor link. No need to change.
var ie = document.all;
var ns6 = document.getElementById&&!document.all;

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl = what.offsetParent;
	while (parentEl!=null){
		totaloffset = (offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl = parentEl.offsetParent;
	}
	return totaloffset;
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function clearbrowseredge(pFld, hintControl, whichedge){    
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1;
	if (whichedge=="rightedge"){
		var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40;
		hintControl.contentmeasure=hintControl.offsetWidth;
		if (windowedge-hintControl.x < hintControl.contentmeasure)
		    edgeoffset=hintControl.contentmeasure+pFld.offsetWidth+parseInt(horizontal_offset);
	}
	else{
		var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		hintControl.contentmeasure=hintControl.offsetHeight;
		if (windowedge-hintControl.y < hintControl.contentmeasure)
			edgeoffset=hintControl.contentmeasure-pFld.offsetHeight;
	}
	return edgeoffset;
}

if (window.addEventListener) {
	window.addEventListener("load", attachMouseEvents, false);	
}
else if (window.attachEvent){
	window.attachEvent("onload", attachMouseEvents);
}

