// edit by Batiaan de Vogel 01-2010
setTimeout("$(document).ready(function(){ajaxready()})",2000);
var usePopupScript = 1;
var newThImg,newImg,totaltop,totalheight,totalleft,topscroll,deklas,maxrow,e,mouseX,mouseY,entered,aHeight,aWidth,aSrc;
var position = '';
var thumb = '';

function ajaxready(){
	swichPopupOnOff(1)
	$().mousemove(function(e){
		mouseX = e.pageX;
		mouseY = e.pageY;
	}); 
    if (typeof draginit === 'function') {
        // onsubmit is executable, test the return value
        if (draginit()) {
            // onsubmit returns true, submit the form
            draginit();
        }
    }
}

function swichPopupOnOff(val){
	if(val != null){
		usePopupScript = val;
	}
}

function doMouseOver(img){
		thumb = img;
		position = $(img).offset();
		if(usePopupScript == 1){
			thediv = document.getElementById("compDIV");
			theimg = document.getElementById("compIMG");
			thethimg = document.getElementById("thIMG");
			captiondiv = document.getElementById("captionDiv");
			thediv.style.display = 'block';
			var newThImg = new Image();
			newThImg.src = img.src;
			theimg.src = newThImg.src;
			//enlarge the th, get factor based on largest edge
			if(newThImg.height>newThImg.width){//portrait image
				ratio = newThImg.width / newThImg.height;
				theimg.height = 350;
				theimg.width = Math.round(350 * ratio);
			}
			else{
				ratio = newThImg.height / newThImg.width;
				theimg.width = 350;
				theimg.height = Math.round(350 * ratio);
			}
			theimg.style.display = 'block';
			captiondiv.innerHTML = img.getAttribute("alt");
			captiondiv.style.clear = "both";
			captiondiv.style.width = theimg.width + "px";
			captiondiv.style.height = 35 + "px";
			getSize(img.getAttribute("compimgsrc"));
			theimg.src = aSrc;
			getSize(aSrc);
			if(aHeight != undefined){
				if(aHeight != 0){
					theimg.height = aHeight;
					theimg.width = aWidth;
					captiondiv.style.width = aWidth + "px";
				}
			}
			if (navigator.userAgent.indexOf('Safari') == -1) { // Alles behalve safari         
				totaltop = document.documentElement.scrollTop;
				totalheight = document.documentElement.clientHeight;
				totalleft = document.documentElement.clientWidth;
			} else{ // safari         
				totaltop = document.body.scrollTop;
				totalheight = document.documentElement.clientHeight;
				totalleft = document.documentElement.clientWidth;
			}
			if((position.top + theimg.height + thumb.height) > (totaltop + totalheight)){ //popup hits the bottom
				if(((mouseY - totaltop) - theimg.height) < 0){ //popup hits the top
					if(mouseY < (totaltop + (totalheight/2))){
						thediv.style.top = (mouseY + 15) +'px';
					} else{
						thediv.style.top = (mouseY - theimg.height - 30) +'px';
					}
				} else{
					thediv.style.top = (mouseY - theimg.height - 30) +'px';
				}
			} else {
				thediv.style.top = (mouseY + 15) +'px';
			}
			if((position.left + theimg.width + thumb.width)>totalleft){
				thediv.style.left = (mouseX - theimg.width - 15) +'px';
			} else {
				thediv.style.left = (mouseX + 15) +'px';
			}
		}
	entered = 1;
}

function mousemove(evt) {
	thediv = document.getElementById("compDIV");
	theimg = document.getElementById("compIMG");
	thethimg = document.getElementById("thIMG");
	captiondiv = document.getElementById("captionDiv");
	theimg.src = aSrc;
	getSize(aSrc);
	if(aHeight != undefined){
		if(aHeight != 0){
			theimg.height = aHeight;
			theimg.width = aWidth;
			captiondiv.style.width = aWidth + "px";
		}
	}
	if (navigator.userAgent.indexOf('Safari') == -1) { // Alles behalve safari         
		totaltop = document.documentElement.scrollTop;
		totalheight = document.documentElement.clientHeight;
		totalleft = document.documentElement.clientWidth;
	} else{ // safari         
		totaltop = document.body.scrollTop;
		totalheight = document.documentElement.clientHeight;
		totalleft = document.documentElement.clientWidth;
	}
	if(mouseY!=null){//this check is added because of a problem that occurs if the mouse happens to be on top of a thumbnail while the page is loading. Then mouseY is not yet known
		if((position.top + theimg.height + thumb.height) > (totaltop + totalheight)){ //popup hits the bottom
			if(((mouseY - totaltop) - theimg.height) < 0){ //popup hits the top
				if(mouseY < (totaltop + (totalheight/2))){
					thediv.style.top = (mouseY + 15) +'px';
				} else{
					thediv.style.top = (mouseY - theimg.height - 30) +'px';
				}
			} else{
				thediv.style.top = (mouseY - theimg.height - 30) +'px';
			}
		} else {
			thediv.style.top = (mouseY + 15) +'px';
		}
		if((position.left + theimg.width + thumb.width)>totalleft){
			thediv.style.left = (mouseX - theimg.width - 15) +'px';
		} else {
			thediv.style.left = (mouseX + 15) +'px';
		}
	}
}
function resetComp(){
	entered = 0;
	thediv = document.getElementById("compDIV");
	theimg = document.getElementById("compIMG");
	thethimg = document.getElementById("thIMG");
	captiondiv = document.getElementById("captionDiv");
	thediv.style.display = 'none';
	theimg.style.display = 'none';
}



function dumpstr(s, nodename){
	str='dump\n';
	cnt=0;
	
	for(X in s){
		if( nodename==null || X.indexOf(nodename)==0){
			str += 'str.'+X+' is '+s[X]+' \n';
			cnt++
			
			if(cnt==20){
				alert(str);
				cnt=0;
				str='dump\n';
			}
		}
	}
	alert(str);
}

function getSize(imgSrc){

	var aImg = new Image();
	
	aImg.src = imgSrc;
	
	aSrc = aImg.src;
	
	aHeight = aImg.height; 
	
	aWidth = aImg.width;

}


// below functions needed for old sites
function getComp(){}
function replaceTH(){}
function showComp(){}
function unresetComp(){}
function clearComp(){}
function gotoDetails(){
	window.location=thumb.parentNode.href;
}
function fadeStart(){}
function fadeIn(){}
function afterFade(){}
function Xbody(){}