var shop = {
	popup: undefined,
	datepopupdiv: undefined,
	dateinput: undefined,
	body: undefined,
	overlaydiv: undefined,
	findpos: function(obj) {
			var curleft = curtop = 0;
			if (obj.offsetParent) {
				do {
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;
				} while (obj = obj.offsetParent);
			}
			return [curleft,curtop];
		},
	overlay: function(onoff) {
			//var h = document.documentElement.offsetHeight;
			var ps = shop.getPageSize();
			if (!shop.overlaydiv) {
				shop.overlaydiv = document.createElement('DIV');
				shop.overlaydiv.style.position='absolute';
				shop.overlaydiv.style.background='black';
				shop.overlaydiv.style.top='0px';
				shop.body.appendChild(shop.overlaydiv);
				shop.overlaydiv.innerHTML='&nbsp;';
				shop.overlaydiv.style.opacity=0.80;
				shop.overlaydiv.style.filter='alpha(opacity=80)';
			}
			shop.overlaydiv.style.height=ps[1]+'px';
			shop.overlaydiv.style.width=ps[0]+'px';
			shop.overlaydiv.style.display=(onoff ? 'block' : 'none');
		},
	details: function(uri) {
		var st = (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
		shop.overlay(true);

		if (!shop.popup) {
			shop.popup=document.createElement('DIV');
			var mid = document.getElementById('midden');
			shop.popup.className='popup';
			mid.parentNode.appendChild(shop.popup);
		}
		//shop.popup.style.filter='alpha(opacity=0)';
		//shop.popup.style.opacity=0;
		shop.popup.style.display='block';
		$(shop.popup).css('opacity',0);
		st = st > 100 ? st : 100;
		shop.popup.style.top=(st+25)+'px';
		$(shop.popup).load(uri,null,function() {
			$(shop.popup).css('opacity',100);
			});
		/*var x = new XMLHttpRequest();
		x.open("GET",uri,false);
		x.send("");
		shop.popup.innerHTML=x.responseText;
		shop.fadein(shop.popup);*/
		return false;
		},
	fadein: function(obj) {
			var op = parseFloat(obj.style.opacity);
			if (op<1) {
				op+=0.25;
				obj.style.opacity=op;
				obj.style.filter='alpha(opacity='+(op*100)+')';
				setTimeout(function() { shop.fadein(obj); },10);
			}
			return false;
		},
	closepopup: function() {
		shop.overlay(false);
		if (shop.popup)
			shop.popup.style.display='none';
		return false;
		},
	order: function(uri,aantal) {
		var x = new XMLHttpRequest();
		uri += '&aantal='+aantal;
		x.open("GET",uri,false);
		x.send("");
		var div = document.getElementById('cart');
		shop.closepopup();
		div.innerHTML=x.responseText;
		return false;
		},
	datepopup: function(obj) {
			if (!shop.datepopupdiv) {
				shop.datepopupdiv = document.createElement('DIV');
				shop.datepopupdiv.className='date';
				shop.body.appendChild(shop.datepopupdiv);
			}
			var xy = shop.findpos(obj);
			shop.datepopupdiv.style.position='absolute';
			shop.datepopupdiv.style.left = (xy[0]+obj.offsetWidth)+'px';
			shop.datepopupdiv.style.top = xy[1]+'px';
			shop.datepopupdiv.style.display='block';
			shop.dateinput=obj;
			shop.updatepopup('='+obj.value);
			var els = obj.form.elements;
			for (var i=0;i<els.length;i++) {
				if (els[i]!=obj && !els[i].onfocus) els[i].onfocus=shop.closedatepopup;
			}
			return false;
		},
	closedatepopup: function() {
			shop.datepopupdiv.style.display='none';
		},
	dateselect: function(d) {
			shop.dateinput.value=d;
			shop.closedatepopup();
			return false;
		},
	updatepopup: function(param) {
			$(shop.datepopupdiv).load('?bestellen&date'+param);
			/*var x = new XMLHttpRequest();
			x.open("GET","?bestellen&date"+param,false);
			x.send("");
			shop.datepopupdiv.innerHTML=x.responseText;*/
			return false;
		},
	getPageSize: function() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
		},
	init: function() {
			if (!shop.body) {
				var els = document.getElementsByTagName('BODY');
				for (var i=0;i<els.length;i++)
					shop.body = els[i];
			}
		rw_h5();
		}
	};

var hapje = {
		over: function(obj) {
			var m = obj.src.match(/thumb_([a-z0-9]+.jpg)/);
			var big = document.getElementById('big');
			big.src = 'images/big_'+m[1];
		}
	};

var teaser = {
	speed: 5000,
	init: function(id,opts) {
		setTimeout('teaser.swap("'+id+'","'+opts+'")',teaser.speed);
		},
	swap: function(id,opts) {
		var i = document.getElementById(id);
		if (i) {
			var o = opts.split(';');
			var fn = '';
			for (var b=0;b<o.length;b++)
				if (i.src.indexOf(o[b])<0)
					fn=o[b];
			i.src='images/'+fn;
		}
		setTimeout('teaser.swap("'+id+'","'+opts+'")',teaser.speed);
		}
	};

var effect = {
		openup: function(obj) {
				if (obj.parentNode)
					obj.parentNode.style.display='none';
				if (obj.parentNode.nextSibling)
					obj.parentNode.nextSibling.style.display='block';
				return false;
			}
	};
	
function rw_h5() {
	jQuery('H5').each(function() {
		var w = this.offsetWidth;
		var h = this.offsetHeight;
		var c = this.className;
		jQuery(this).replaceWith('<img src="koph5.php?c='+escape(c)+'&amp;txt='+escape(this.innerHTML)+'" alt="'+escape(this.innerHTML)+'" title="'+escape(this.innerHTML)+'" />');
		});
}

