// browser check
var ie = document.all ? 1 : 0		
var ns = document.layers ? 1 : 0

// mouse position
ttMouseX = 0, ttMouseY = 0; 

// tooltip visibility
var ttVisible = 0;
var ttShowTime = 0;

var iconWidth=15;

// default tooltip container name
ttContainer="ttContainer";

// Set Netscape up to run the "mouseÜps" function whenever
// the mouse is moved. For Internet Explorer and NS 6, you can capture
// the movement a little easier.
if (ns) {
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = ttMousePos;
} else if (ie) {
    document.onmousemove = ttMousePos;
} else if (document.getElementById) { // Netscape 6
    document.onmousemove = ttMousePos;
}

// this function saves the mouse position every time the mouse is moved and moves the div to the current mouse position
function ttMousePos(e) {
    if (ns) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        ttMouseX = e.pageX;
        ttMouseY = e.pageY;
    } else if (ie) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        ttMouseX = window.event.x+document.body.scrollLeft;
        ttMouseY = window.event.y+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        ttMouseX = e.pageX;
        ttMouseY = e.pageY;
    }
	ttMove();
}

// move the layer to cursor + 22 for alignment directly below cursor
function ttMove() {
	document.getElementById(ttContainer).style.left = ttMouseX + document.documentElement.scrollLeft;
	document.getElementById(ttContainer).style.top = ttMouseY + document.documentElement.scrollTop + 22;
	
	// modification by michael 22/2/06 (adjust tooltip on window overflow)
	currentWidth = document.getElementById('ttCaption').clientWidth;
	if(document.getElementById('ttContent').clientWidth > currentWidth) {
		currentWidth = document.getElementById('ttContent').clientWidth;		
	}
	currentHeight = document.getElementById('ttCaption').clientHeight+document.getElementById('ttContent').clientHeight;
	// move to left if tooltip exceeds current iframe dimensions
	horizOverflow = parseInt(document.getElementById(ttContainer).style.left) + currentWidth - document.body.clientWidth - document.body.scrollLeft;
	horizOverflow += 5;
	if(horizOverflow > 0) {
		document.getElementById(ttContainer).style.left = parseInt(document.getElementById(ttContainer).style.left) - horizOverflow;
	}
	// move to top if tooltip exceeds current iframe dimensions
	/*vertOverflow = parseInt(document.getElementById(ttContainer).style.top) + currentHeight - document.body.clientHeight - document.body.scrollTop;
	vertOverflow += 5;
	if(vertOverflow > 10) {
		document.getElementById(ttContainer).style.left = parseInt(document.getElementById(ttContainer).style.left) + iconWidth;
		document.getElementById(ttContainer).style.top = parseInt(document.getElementById(ttContainer).style.top) - vertOverflow;
	}*/
}

function ttShow() {
	time = new Date();
	ttShowTime = time.getSeconds();
	setTimeout('ttCheckHide('+ttShowTime+')',7000);
	//if(!ttVisible) {
		//ttVisible=1;
		setTimeout("document.getElementById(ttContainer).style.visibility = 'visible';",100);
		setTimeout("ttMove();",101);
		setTimeout("document.getElementById(ttContainer).style.display = 'block';",100);
		//ttFade('in');
	//}
}

function ttCheckHide(showTime) {
	if(showTime > 55) {
		showTime-=60;
	}

	if(ttShowTime<=showTime) {
		ttHide();
	}
}

function ttHide() {
	document.getElementById(ttContainer).style.visibility = 'hidden';
	document.getElementById(ttContainer).style.display = 'none';
}

function tt(title,content,dummy) { // dummy is used for buymode, there data is filled manually into tooltip
	if(title || content ||dummy) {
		ttShow();
	} else {
		ttHide();
	}
	if(!dummy) {
		if(title) {
			document.getElementById('ttCaption').innerHTML = title;
		} else {
			document.getElementById('ttCaption').innerHTML = '&nbsp;';
		}
		if(content) {
			document.getElementById('ttContent').innerHTML = content;
		} else {
			document.getElementById('ttContent').innerHTML = '';
		}
	}
}