/* HOVER PART */
var imgShow = false;
var hvHeight = 2;
var hvWidth = 2;

var hvEle = false;
var hvDiv = false;
var hvFrame = false;

function dpHv(ele, url) {
	hvEle = ele;
	hvEle.onmouseout = new Function('dpHvClose();');
	
	if (document.images) {
		if (!hvDiv) {
			hvDiv = document.createElement('div');
			hvDiv.style.position        = 'absolute';
			hvDiv.style.border          = 'solid #d5d5d5 1px';
			hvDiv.style.backgroundColor = 'white';
			hvDiv.style.padding         = '0px';
			hvDiv.style.display         = 'none';
			hvDiv.style.zIndex		   = 1001;
			if (BrowserDetect.browser == "Explorer") {
				hvFrame = document.createElement('iframe');
				hvFrame.style.position = 'absolute';
				hvFrame.style.display  = 'none';
				hvFrame.frameBorder = '1';
				hvFrame.style.filter = 'alpha(opacity = 0)';
				hvFrame.style.zIndex = 1000;
				
				document.body.appendChild(hvFrame);
			}
			document.body.appendChild(hvDiv);
		}
				
		if (!imgShow || hvHeight <= 2) {
			var img = new Image();
			img.src = url;

			hvHeight = img.height;
			hvWidth = img.width;
		}
		
		divPos = dpHvCalcPos(20);
   
		hvDiv.style.left = divPos[0] + 'px';
		hvDiv.style.top = divPos[1] + 'px';
		
		if (hvFrame) {
			hvFrame.style.left = hvDiv.style.left;
			hvFrame.style.top = hvDiv.style.top;
		}

		if (!imgShow) {
			imgShow = true;
			
			htmlText = '<div style="padding: 5px;"><img src="' + url + '" onerror=\"dpHvStop();\" /></div>';
			
			hvDiv.innerHTML = htmlText;
			hvDiv.style.display = '';
			
			if (hvFrame) {
				hvFrame.style.display = '';
				hvFrame.style.width = (hvWidth + 12); // border is 2px + padding van 10px totaal
				hvFrame.style.height = (hvHeight + 2); // border is 2px + padding van 10px totaal
			}
		}
	}
}

function dpHvStop() {
	if (hvEle) {
		hvEle.style.display = 'none';
		hvEle.onmousemove = 'return false';
		hvEle.onmouseout = 'return false';
		dpHvClose();
	}
}
 
function dpHvClose() {
	if (hvDiv) {
		hvDiv.style.display = 'none';
		
		if (hvFrame) {
			hvFrame.style.display = 'none';
		}
		imgShow = false;
		hvEle = false;
	}
}

function dpHvCalcPos(mrY) {
	browserSize = calcBrwSize();

	newLeft = psX + 15;
	newTop = psY;
	
	scrolbarWidth = 28;
	
	// Breedte check
	intersectsWidth = false;
	if (hvWidth + scrolbarWidth + newLeft > browserSize[0]) {
		intersectsWidth = true;
		newLeft = (browserSize[0] - hvWidth - scrolbarWidth);
	}
	
	// Hoogte check
	scrollTop = calcScrollTop();
	visibleTop = (newTop - scrollTop);
	if (visibleTop - hvHeight - mrY > 0) {
		newTop -= hvHeight;
		newTop -= mrY;
	} else if (!intersectsWidth) {
		overflowHeight = (browserSize[1] - (visibleTop + hvHeight + mrY));
		if (overflowHeight < 0) {
			newTop = scrollTop;
		} else {
			newTop += (mrY / 2);
		}
	} else {
		newTop += (mrY / 2);
	}
	
	return new Array(newLeft, newTop);
}

function calcBrwSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	return new Array(myWidth, myHeight);
}

function calcScrollTop() {
	return parseInt(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
}