function keepItToOurselves() {
	if (top.location!= self.location) {
		top.location = self.location.href;
	}
}
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
			if (dataString.indexOf(data[i].subString) != -1)
				return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]
};
BrowserDetect.init();
/* ====================== *
 * MODAL WINDOW FUNCTIONS *
 * ====================== */
function closeAllWindows(){
	Windows.closeAll();
}
function destroyWindow(cwindow){
	if(cwindow != null) cwindow.destroy();
}
/* ========= *
 * GOOGLEMAP *
 * ========= */
var winMap = null;
function getMap(fr,wi){
	if($('div#rcmap.dialog')) destroyWindow(winMap);
	if(!$('div#rcmap.dialog')) showMap.defer(fr,wi);
}
function showMap(fr,wi){
	if($('rcmap')) {
		winMap.close();
	}
	winMap = new Window({
		className: "alphacube",
		id:'rcmap',
		width: 700,
		height: 400,
		zIndex: 1000,
		title: "Map :: gebruik de [<em>esc</em>]-toets indien problemen bij het sluiten van dit venster.",
		resizable: true,
		draggable:true,
		destroyOnClose: true,
		showEffectOptions: {duration:1.5},
		showEffect:Effect.BlindDown,
		hideEffect: Effect.SwitchOff,
		url: "map.php?c="+fr+"&w="+wi
	});
	winMap.showCenter();
}
function getRoute(vn,nr){
	var van = encodeURI(vn.replace(/\s/,'+'));
	var naar = encodeURI(nr.replace(/\s/,'+'));
	var url = "http://maps.google.be/maps?saddr="+van+"&daddr="+naar+"&hl=nl";
	var route = window.open(url,'googleroute',"fullscreen=yes,height="+screen.availHeight+",width="+screen.availWidth+",top=0,left=0,status=no,toolbar=no,location=no,menu=no,resizable=yes,scrollbars=yes");
	if (window.focus) {route.focus()}
}
/* ========= *
 * SLIDESHOW *
 * ========= */
function slideshow(url){
	var slideshow=window.open(url,'slideshow','width='+screen.availWidth+',height='+screen.availHeight+',top=0,left=0,fullscreen=yes,location=no,menu=no,resizable=no,status=no,toolbar=no,scrollbars=no');
	if (window.focus) {slideshow.focus()}
}
/* ============= *
 * CARD FUNCTIES *
 * ============= */
var playingcard;
var hd;
function sd (j){
	var a = (j) ? 54 : 52;
	var b = new Array();
	var c = (Math.random()*a+1).floor();
	while (b.length < a){
		if(b.indexOf(c) == -1) {
			b.push(c);
		}else{
			c = (Math.random()*a+1).floor();
		}			
	}
	a=c=null;
	return b;
}
function showCard(){
	if(hd.length >= 1){
		playingcard.src = 'images/classic-cards-front/' + hd.pop() + '.png';
	}else{
		hd = sd(1);
		playingcard.src = 'images/classic-cards-front/' + hd.pop() + '.png';
	}
	return;
}
function dcrd(){
	playingcard.src = 'images/classic-cards-back/b1fv.png';
	showCard.delay(.4);
}
/* ================== *
 * NAVIGATIE FUNCTIES *
 * ================== */
function sdsm(a,d){
	var b = a.down(0);
	var s = b.next(0);
	if(s) s.setStyle({display: d});
	b=s=null;
}
function smf(){
	var b = document.viewport.getScrollOffsets().top;
	var d = $('mn').cumulativeOffset().top;
	if(d>0) e = d;
	if(b >= e){
		$('mn').setStyle({position: 'fixed', top: 0+'px', zIndex: 500});
		var hmi = $('hm').childElements();
		hmi.last().down(0).setStyle({marginRight: 0});
		hmi = null;
		var nmnw = $('mn').getWidth();
		$('mn').setStyle({width: nmnw+25+'px'});
		nmnw=null;
	} else {
		$('mn').setStyle({position: 'static', top: '', width: 'auto'});
		$('mn').setStyle({position: 'absolute', width: 'auto'});
	}
	b=d=null;
	return;
}
function go2page(p){
	window.location.href = p;
}
/* ====================== *
 * PAGINA LAYOUT FUNCTIES *
 * ====================== */
 function lnr(){
 	var cbft = $('cbf').cumulativeOffset().top ;
 	var rrft = $('rrf').cumulativeOffset().top ;
 	if(cbft > rrft){
 		var rrfv = cbft - rrft;
 		$('cbf').setStyle({height: '0px'});
 		$('rrf').setStyle({height: rrfv + 'px'});
 	}else{
 		var cbfv = rrft - cbft;
 		$('rrf').setStyle({height: '0px'});
 		$('cbf').setStyle({height: cbfv + 'px'});
 	}
 	var wrw = $('wr').getWidth();
 	$('ft').setStyle({position: 'relative', top: 0, width: wrw + 'px'});
 }
/* ====================== *
 * WINDOW ONLOAD FUNCTIES *
 * ====================== */
function makeLinksExternal(){
 var linken = $$('a');
 linken.each(function(link){
  if(link.readAttribute('rel') == 'external'){
   link.target = '_blank';
  }
 });
}
document.observe('dom:loaded', function() {
    $('hc').update('<img src="images/default/headerGCM1.gif" alt="Koninklijke Bridgeclub Goldstar - Carta Mundi" />');
	keepItToOurselves();
	var as = $$('li.hmi');
	as.each(function(a){
		Event.observe(a, 'mouseover', function(){sdsm(a,'block');});
		Event.observe(a, 'mouseout', function(){sdsm(a,'none');});
	});
	makeLinksExternal();
	Event.observe(window, 'scroll', smf);
	Event.observe(window, 'resize', lnr);
});
Event.observe(window, 'load', function() {
	hd = sd();
	playingcard = $('hcrd');
	Event.observe(playingcard, 'mouseout', dcrd);
	dcrd();
	lnr();
});