// Global variables containing the position of the mouse
var mouseX = 0;
var mouseY = 0;

var isHoverActive = false;

function captureMouse() {
	// define how to capture mouse movements depending on browser
	if (document.layers) { // Netscape needs this
	  document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = findMouseCrossBrowser;
}

function findMouseCrossBrowser(e) {
    if (document.all) { // IE
    	mouseX = window.event.x+document.body.scrollLeft;
    	mouseY = window.event.y+document.body.scrollTop;
    }
    else if (document.layers || document.getElementById) { // NS
    	mouseX = e.pageX;
    	mouseY = e.pageY;
    }
}
 
function moveHoverWithMouse() {
    var thingToManipulate  = document.getElementById('1437');
    thingToManipulate.style.left=""+(mouseX+10)+"px";
    thingToManipulate.style.top=""+(mouseY+10)+"px";
}

function findPos(obj) {
    /* See why this is complicated: http://www.quirksmode.org/js/findpos.html */
    var curleft = 0;
    var curtop = 0;
    if (obj && obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}

function hideHoverDiv(id){
    isHoverActive = false;
    setTimeout('hideHoverActual(\''+id+'\')', 400);
}

function hideHoverActual(id){
    if(!isHoverActive){
        hide(id);
        document.getElementById(id).className = 'askville_hover greenbox';
    }
}

function showHoverAnimRight(linkId, hoverId, contentId, width, height) {
	showHoverAnimStep(1, linkId, hoverId, contentId, width, height, false);
}

function showHoverRight(linkId, hoverId, contentId) {
	showHoverAnimStep(1, linkId, hoverId, contentId, null, null, false, 1);
}

function showHoverAnimBottom(linkId, hoverId, contentId, width, height) {
    showHoverAnimStep(1, linkId, hoverId, contentId, width, height, true);
}

function showHoverBottom(linkId, hoverId, contentId) {
	showHoverAnimStep(1, linkId, hoverId, contentId, null, null, true, 1);
}

function showHoverBottomDelay(linkId, hoverId, contentId) {
    isHoverActive = true;
    setTimeout("showHoverBottomCheck('" + linkId +"','"+hoverId+"','"+contentId+"')", 400);
}

function showHoverBottomCheck(linkId, hoverId, contentId) {
    if (isHoverActive) {
        showHoverAnimStep(1, linkId, hoverId, contentId, null, null, true, 1);
    }
}

function showHoverAnimStep(step, linkId, hoverId, contentId, width, height, fromBottom, maxSteps) {
    var hoverDiv = document.getElementById(hoverId);
    var link = document.getElementById(linkId);
    if (linkId == null) {
        alert('missing id for link element');
    }
    if (!maxSteps) {
        maxSteps = 3;
    }

    isHoverActive = true;
	if (step == 1) {
	    if (contentId != null) {
	    	hoverDiv.innerHTML = '';
	    }
        if (fromBottom) {
            hoverDiv.style.left = findPos(link)[0] + 'px';
	        hoverDiv.style.top = findPos(link)[1] + link.offsetHeight + 'px';
        }
        else {
            hoverDiv.style.left = findPos(link)[0] + link.offsetWidth + 'px';
	        hoverDiv.style.top = findPos(link)[1] + 'px';
        }
        hoverDiv.style.display = 'block';
	}
	
	if (step < maxSteps) {
	    hoverDiv.style.width = width / (maxSteps - step) + 'px';
    	hoverDiv.style.height = height / (maxSteps - step) + 'px';
		++step;
	    setTimeout("showHoverAnimStep(" + step + ",'" + linkId +"', '"+hoverId+"','"+contentId+"', "+width+","+height+","+fromBottom+","+maxSteps+")", 50);
	}
	else {
	    showHoverActual(hoverId, contentId, !fromBottom);
    }
}
 
function showHoverActual(hoverId, contentId, autoScrollWidth) {
    var hoverDiv = document.getElementById(hoverId);
    hoverDiv.className = 'askville_hover';
    if (contentId != null) {
    	hoverDiv.innerHTML = document.getElementById(contentId).innerHTML;
        if (autoScrollWidth) {
            window.scrollBy(hoverDiv.offsetWidth, 0);
        }
    }
}