/* */
/* globals */

var APEX_HOVER;

var axOldOnLoad, axPhotoList, axTimer;
var axHoverIsActive = false;
var isDebug = true;
var zztmpCmd;
var zztmpTimer;

function zztmpCloser() {
	clearTimeout(zztmpTimer);
	document.getElementById('popup').style.display = 'none';
}
/*
if(typeof(window.onload) == 'function') {
	axOldOnLoad = window.onload;
}
window.onload = function() {
	if(axOldOnLoad) {
		axOldOnLoad();
	}
	axInit();
}*/
axInit();

function axInit() {
	APEX_HOVER = new axHover();
}

function axHover() {
	this.c_photoList = null;
	this.c_sizes = new Array();
	this.c_debug = '';
	this.c_openTimer = null;
	this.c_closeTimer = null;
	this.c_delay = 100;
	this.c_closeDelay = 50;
	this.isOpen = null;

	this.c_sizes['tiny']   = 50;
	this.c_sizes['small']  = 110;
	this.c_sizes['medium'] = 270;
	this.self = this;

	this.cmd = '';

}
axHover.prototype.GetDebug = function() {
	if(this.c_debug != '') {
		alert("Debug Messages:\n ---start of debug---\n " + this.c_debug + "\n ---end of debug---\n");
	}
}
axHover.prototype.ax_debug = function() {
	if(arguments.length == 0 || arguments[0] == null) {
		this.c_debug += "Blank debug message sent.\n";
	} else {
		this.c_debug += arguments[0] + "\n";
	}
}

function calcMath(th_h,th_w,large) {
	var med_h, med_w, adj_p, adj_w;
	if(th_h > th_w) {
		med_h = large;
		med_w = parseInt( ( large / th_h ) * th_w );
		adj_p = parseInt( ( med_w + 10 ) );
		adj_w = parseInt( ( ( ( large - adj_p ) - 10 ) / 2 ) + ( th_w / 2 ) );
	} else {
		med_w = large;
		med_h = parseInt( ( large / th_w ) * th_h );
		adj_p = 280;
		adj_w = 30;
	}
	return med_h + "," + med_w + "," + adj_p + "," + adj_w;
}
// voor de id die meegegeven wordt deze functie gaan uitvoeren
axHover.prototype.OnMouseOver = function(eleid) {

	/* On Mouse Over Function goes here */
//alert(eleid);
	if(APEX_HOVER.c_openTimer) {
		clearTimeout(APEX_HOVER.c_openTimer);
	}
	var img = xGetElementById(eleid);
//alert(img.alt);
	var small_h = parseFloat(img.style.height);
//alert(img.style.height);
	var small_w = parseFloat(img.style.width);
	var nMath;
	var med_h, med_w, adj_p, adj_w;

	nMath = calcMath( small_h, small_w, APEX_HOVER.c_sizes['medium'] );
	nMath = nMath.split(',');
	med_h = parseInt(nMath[0]);
	med_w = parseInt(nMath[1]);
	adj_p = parseInt(nMath[2]);
	adj_w = parseInt(nMath[3]);

	// center over the smaller one
	var x = xPageX(eleid) - med_w/2;
	var y = xPageY(eleid) - med_h/2 ;

	// make sure the top isn't off the screen or right on it.
	if(y <= xScrollTop()) {
		y = xScrollTop() + 5; // add padding
	}

	// make sure the bottom of the image doesn't go out of screen view.
	var y_bottom = xScrollTop() + xClientHeight();
	if(y_bottom <= (y + med_h + adj_w + 5)) {
		y = y_bottom - med_h - adj_w - 5; // less padding too
	}

	// make sure the left image is on the screen
	if(x <= xScrollLeft()) {
		x = xScrollLeft() + 5;
	}

	// make sure the right side of the image doesn't go out of screen view.
	var x_right = xScrollLeft() + xClientWidth();
	if(x_right <= (x +  med_w + 35)) {
		x = x_right - med_w - 35; // less padding too
	}

	//afbeelding naar boven
	y=y-425;
	//afbeelding naar links
	x=x-600;
//alert(x +","+ y +","+ med_w +","+ med_h +","+ adj_p +","+ adj_w +","+ eleid);
	APEX_HOVER.cmd = "axDisplay("+ x +","+ (y+55) +","+ med_w +","+ med_h +","+ adj_p +","+ adj_w +","+ eleid +")";
	APEX_HOVER.c_openTimer = setTimeout(APEX_HOVER.cmd, APEX_HOVER.c_delay);

}

function axCloseHover(obj) {
	if(zztmpTimer) {
		clearTimeout(zztmpTimer);
	}
	zztmpCmd = "zztmpCloser()";
	zztmpTimer = setTimeout(zztmpCmd,60);
}

function axCheckHover(obj) {
	if(zztmpTimer) {
		clearTimeout(zztmpTimer);
	}
}

function axDisplay(x,y,w,h,adj_p,adj_w,id) {
// !!!!!!!!!!!!!!! de id die hier binnen komt moet een getal zijn want dan is het een nummer.
// staat er een letter in dan komt hier een object binnen en dat moet niet !!!!!!!!!!!!!!!!!!
// alert(id);


	var pop,popshadow,popimage,poplink;
	var href,contain;
	pop = xGetElementById('popup');
	if(!pop) {
		throw new Error("Failed to get popup holder element by id reference.");
		return;
	}
	popshadow = xGetElementById('popupshadow');
	popimage  = xGetElementById('popupimage');
	poplink   = xGetElementById('popuplink');
	contain   = xGetElementById('popupcontain');
	href 	  = xGetElementById('href' + id);
//alert(href.href);
	
	/* Resets */
	pop.style.display = 'none';
	popimage.src      = '/images/spacer.gif';

	// dit moet hier zo staan. alt en title moeten met deze functie opgehaald worden.
	popimage.title      = document.getElementById(id).title;
	popimage.alt      = document.getElementById(id).alt;
  poplink.style.backgroundColor = "transparent";
	
	/* Set up the href */
	if(href.href) {
		poplink.href   = href.href;
	} else {
		poplink.href   = '#';
	}
	if(href.target) poplink.target = href.target;
	if(href.title)  poplink.title = href.title;
	if(href.target) poplink.target = href.target;


	pop.style.width = adj_p + 'px';
	pop.style.top   = y + 'px';
	pop.style.left  = x + 'px';

	popshadow.style.width  = w + 'px';
	popshadow.style.height = h + 'px';
	popimage.style.width  =  w + 'px';
	popimage.style.height =  h + 'px';
	popimage.src = APEX_HOVER.Path(id, 'medium');

	clearTimeout(APEX_HOVER.c_openTimer);

	pop.style.display = 'block';
	xMoveTo(pop,x,y);
}

axHover.prototype.OnMouseOut = function(eleid) {
	/* On Mouse Out Function goes here */
	if(APEX_HOVER.c_openTimer) {
		clearTimeout(APEX_HOVER.c_openTimer);
	}
	var pop = xGetElementById('popup');
	if(pop.style.display != 'none') {
		/* handle this */
		return;
	} else {
		/* close this item */
		pop.style.display = 'none';
	}
}

axHover.prototype.Path = function(id, size) {
	var path = 'thumbs/';
	var a = new String(parseInt(id)).split('');
	if(a.length > 3) {
		for(var i = a.length; i > 3; i--) a.pop();
		a.reverse();
		path += a.join('/') + '/';
	}
	//return path + size + '/' + id + '.jpg';
	//return 'http://localhost/schatjeskinderkleding/img.php?ID=1190286782&width=100&height=100';
	//alert(id);
	return 'img.php?ID=' + id + '';
	
}
/* Compiled from X 4.11 with XC 1.02 on 20Apr07 */
function xClientHeight(){var v=0,d=document,w=window;if(d.compatMode=='CSS1Compat'&&!w.opera&&d.documentElement&&d.documentElement.clientHeight){v=d.documentElement.clientHeight;}else if(d.body&&d.body.clientHeight){v=d.body.clientHeight;}else if(xDef(w.innerWidth,w.innerHeight,d.width)){v=w.innerHeight;if(d.width>w.innerWidth)v-=16;}return v;}function xClientWidth(){var v=0,d=document,w=window;if(d.compatMode=='CSS1Compat'&&!w.opera&&d.documentElement&&d.documentElement.clientWidth){v=d.documentElement.clientWidth;}else if(d.body&&d.body.clientWidth){v=d.body.clientWidth;}else if(xDef(w.innerWidth,w.innerHeight,d.height)){v=w.innerWidth;if(d.height>w.innerHeight)v-=16;}return v;}function xDef(){for(var i=0;i<arguments.length;++i){if(typeof(arguments[i])=='undefined')return false;}return true;}function xGetComputedStyle(oEle,sProp,bInt){var s,p='undefined';var dv=document.defaultView;if(dv&&dv.getComputedStyle){s=dv.getComputedStyle(oEle,'');if(s)p=s.getPropertyValue(sProp);}else if(oEle.currentStyle){var i,c,a=sProp.split('-');sProp=a[0];for(i=1;i<a.length;++i){c=a[i].charAt(0);sProp+=a[i].replace(c,c.toUpperCase());}p=oEle.currentStyle[sProp];}else return null;return bInt?(parseInt(p)||0):p;}function xGetElementById(e){if(typeof(e)=='string'){if(document.getElementById)e=document.getElementById(e);else if(document.all)e=document.all[e];else e=null;}return e;}function xLeft(e,iX){if(!(e=xGetElementById(e)))return 0;var css=xDef(e.style);if(css&&xStr(e.style.left)){if(xNum(iX))e.style.left=iX+'px';else{iX=parseInt(e.style.left);if(isNaN(iX))iX=xGetComputedStyle(e,'left',1);if(isNaN(iX))iX=0;}}else if(css&&xDef(e.style.pixelLeft)){if(xNum(iX))e.style.pixelLeft=iX;else iX=e.style.pixelLeft;}return iX;}xLibrary={version:'4.11',license:'GNU LGPL',url:'http://cross-browser.com/'};function xMoveTo(e,x,y){xLeft(e,x);xTop(e,y);}function xNum(){for(var i=0;i<arguments.length;++i){if(isNaN(arguments[i])||typeof(arguments[i])!='number')return false;}return true;}function xPageX(e){var x=0;e=xGetElementById(e);while(e){if(xDef(e.offsetLeft))x+=e.offsetLeft;e=xDef(e.offsetParent)?e.offsetParent:null;}return x;}function xPageY(e){var y=0;e=xGetElementById(e);while(e){if(xDef(e.offsetTop))y+=e.offsetTop;e=xDef(e.offsetParent)?e.offsetParent:null;}return y;}function xScrollLeft(e,bWin){var offset=0;if(!xDef(e)||bWin||e==document||e.tagName.toLowerCase()=='html'||e.tagName.toLowerCase()=='body'){var w=window;if(bWin&&e)w=e;if(w.document.documentElement&&w.document.documentElement.scrollLeft)offset=w.document.documentElement.scrollLeft;else if(w.document.body&&xDef(w.document.body.scrollLeft))offset=w.document.body.scrollLeft;}else{e=xGetElementById(e);if(e&&xNum(e.scrollLeft))offset=e.scrollLeft;}return offset;}function xScrollTop(e,bWin){var offset=0;if(!xDef(e)||bWin||e==document||e.tagName.toLowerCase()=='html'||e.tagName.toLowerCase()=='body'){var w=window;if(bWin&&e)w=e;if(w.document.documentElement&&w.document.documentElement.scrollTop)offset=w.document.documentElement.scrollTop;else if(w.document.body&&xDef(w.document.body.scrollTop))offset=w.document.body.scrollTop;}else{e=xGetElementById(e);if(e&&xNum(e.scrollTop))offset=e.scrollTop;}return offset;}function xStr(s){for(var i=0;i<arguments.length;++i){if(typeof(arguments[i])!='string')return false;}return true;}function xTop(e,iY){if(!(e=xGetElementById(e)))return 0;var css=xDef(e.style);if(css&&xStr(e.style.top)){if(xNum(iY))e.style.top=iY+'px';else{iY=parseInt(e.style.top);if(isNaN(iY))iY=xGetComputedStyle(e,'top',1);if(isNaN(iY))iY=0;}}else if(css&&xDef(e.style.pixelTop)){if(xNum(iY))e.style.pixelTop=iY;else iY=e.style.pixelTop;}return iY;}
