var insideLayer = false;

function navOver(id, isSub, fc) {

	var pf = (isSub ? '' : '_root');

	document.getElementById('nav_item_'+id).className = 'navigation_item'+pf+'_over';
	document.getElementById('nav_label_'+id).className = 'navigation_label'+pf+'_over';

	if (fc) {
		var arrow = document.getElementById('nav_arrow_'+id);
		if (arrow) arrow.src = "/mod_bin/general/arrow.php?fc="+fc;
	}

}

function navOut(id, isSub, fc) {

	var pf = (isSub ? '' : '_root');

	document.getElementById('nav_item_'+id).className = 'navigation_item'+pf;
	document.getElementById('nav_label_'+id).className = 'navigation_label'+pf;

	if (fc) {
		var arrow = document.getElementById('nav_arrow_'+id);
		if (arrow) arrow.src = "/mod_bin/general/arrow.php?fc="+fc;
	}

}

var IE = document.all ? true : false;

function move(el) {

	var ld = document.getElementById('link_donate');

	if (ld != null) {
		if (IE) { // grab the x-y pos.s if browser is IE
			tempY = event.clientY + document.documentElement.scrollTop;
		} else {  // grab the x-y pos.s if browser is NS
			tempY = e.pageY;
		}
		if (tempY < 0){tempY = 0;}
		tempY = tempY - 150;
		ld.style.top = tempY + 'px';
	}
}

function fZoom(uri){

	window.open('/uri/?uri=' + uri, 'zoom', 'width=800,height=640,scrollbars=no,status=no,resizable=no,toolbar=no,menubar=no,location=no');

}

function hideFlash() {
	var ctr = document.getElementById('flash_container');
	ctr.style.display = 'none';

	var ctr2 = document.getElementById('flash_container_border');
	ctr2.innerHTML = '';

}

function showFlash(flv_file, width, height) {

	var ctr = document.getElementById('flash_container');
	ctr.style.display = '';

	flv_file.replace(/^\s*|\s*$/g,"");

	var so = new SWFObject('/img/flv/player.swf?file=/img/flv/'+flv_file, "malaika_player", width, height, "7", "#FFFFFF");
	
//	so.skipDetect = true;
	so.write("flash_container_border");
	
	return;
}

function showLayer(id, parent, hPos, vPos, hAlign, vAlign, hOffset, vOffset) {

	var layer = document.getElementById(id);
	var offset = new totalElementOffset(parent);
	var left = offset.x;
	var top = offset.y;
	
	if (hPos == 1) left += parent.offsetWidth;
	if (vPos == 1) top += parent.offsetHeight;
	if (hAlign == 1) left -= layer.style.width.replace(/px/,'');
	if (vAlign == 1) top -= layer.style.height.replace(/px/,'');
	if (hOffset) left += hOffset;
	if (vOffset) top += vOffset;

	layer.style.display = '';
	layer.style.left = left+'px';
	layer.style.top = top+'px';

}

// Hide a previously shown layer
function hideLayer(id) {

	var layer = document.getElementById(id);
	if (layer) layer.style.display = 'none';

}

// Crossbrowser compatible positioning
// Returns an object containing the total x and y offsets for obj relative to the document
function totalElementOffset(obj) {

	var yOffset = (obj.offsetTop ? obj.offsetTop : 0);
	var xOffset = (obj.offsetLeft ? obj.offsetLeft : 0);
	var elParent = obj.offsetParent;

	while (elParent) {
		yOffset += (elParent.offsetTop ? elParent.offsetTop : 0);
		xOffset += (elParent.offsetLeft ? elParent.offsetLeft : 0);
		elParent = elParent.offsetParent;
	}

	this.y = yOffset;
	this.x = xOffset;

}


var iFileCounter=0;

function add_attachment() {

	var eForm = document.forms['upload_form'];
	var eContainer = document.getElementById('att_container');
	var eInputFile = document.createElement('input');
	
	var i = iFileCounter++;

	eInputFile.setAttribute('type', 'file');
	eInputFile.setAttribute('name', 'upload['+i+']');
	eInputFile.setAttribute('id', 'upload_'+i);
	
	eContainer.appendChild(eInputFile);
	
	if (window.ie) {	

		//eInputFile.style.display = 'none';
		//eInputFile.onchange = function(){selectfile('upload_'+i);};
		//eInputFile.click();

	} else {

		eContainer.appendChild(document.createElement('br'));

	}

}

function selectfile(id) {
	
	var eForm = document.forms['upload_form'];
	var eContainer = document.getElementById('att_container');
	var eInputFile = document.getElementById(id);

	if (eInputFile) {
		eContainer.appendChild(document.createTextNode(eInputFile.value));
		eContainer.appendChild(document.createElement('br'));
	}
	

}


if (!window.XMLHttpRequest)	{
	window.XMLHttpRequest =	function() {
		var	types =	[
				'Microsoft.XMLHTTP',
				'MSXML2.XMLHTTP.5.0',
				'MSXML2.XMLHTTP.4.0',
				'MSXML2.XMLHTTP.3.0',
				'MSXML2.XMLHTTP'
				];

		for	(var i = 0;	i <	types.length; i++) {
			try {
				return new ActiveXObject(types[i]);
			}
			catch(e) {}
		}
		return undefined;
	}
}

function UserAgent() { // user agent information
	var ua = navigator.userAgent;
	this.isWinIE = this.isMacIE = false;
	this.isGecko  = ua.match(/Gecko\//);
	this.isSafari = ua.match(/AppleWebKit/);
	this.isOpera  = window.opera;
	if (document.all && !this.isGecko && !this.isSafari && !this.isOpera) {
		this.isWinIE = ua.match(/Win/);
		this.isMacIE = ua.match(/Mac/);
		this.isNewIE = (ua.match(/MSIE 5\.5/) || ua.match(/MSIE 6\.0/));
	}
	return this;
}

function addEvent(object, type, handler) {
	if (object.addEventListener) {
		object.addEventListener(type, handler, false);
	} else if (object.attachEvent) {
		object.attachEvent(['on',type].join(''),handler);
	} else {
		object[['on',type].join('')] = handler;
	}
}

var Popup = {
	_body			: null,
	_overlay		: null,
	_popup			: null,
	_ua				: null,
	_xmlhttp		: null,
	_initialized	: false,
	_open			: null,

	_init : function() {

		var self = this;
		self._ua   = new UserAgent();
		self._body = document.getElementsByTagName("body")[0];
		
		self._popup = self._createPopup();
		self._overlay = self._createOverlay();

		self._xmlhttp = new XMLHttpRequest();

		self._initialized = true;
	},

	_createOverlay : function() {
		var self = this;

		// create overlay, translucent background
		var overlay = document.createElement('div');
		overlay.id = 'overlay';
		with (overlay.style) {
			display = 'none';
			position = 'fixed';
			top = '0px';
			left = '0px';
			zIndex = '50';
			width = '100%';
			height = '100%';
		}
		if (self._ua.isWinIE) {
			overlay.style.position = 'absolute';
			overlay.style.height = self._body.clientHeight + 'px';
		}

		addEvent(overlay,"click",function() { self.close(); });
		self._body.appendChild(overlay);

		return overlay;
	},

	_createPopup : function() {
		var popup_holder = document.createElement('div');
		popup_holder.id = 'popup_holder';
		popup_holder.style.display = 'none';

		this._body.appendChild(popup_holder);


		return popup_holder;

	},

	_showLoading : function() {
		var self = this;

		var load_img = document.createElement('img');
		load_img.src = '/img/loading.gif';
		load_img.style.margin = '50px';
		
		self._popup.appendChild(load_img);

	},

	show : function(url, exec_onload) {
		var self = this;
		if (!this._initialized) self._init();

		if (self._open) self.close();

		self._positionPopup(500);

		self._popup.style.display = '';
		self._overlay.style.display = '';

		self._open = true;

		self._showLoading();

		var popup_btn_close = document.createElement('img');
		popup_btn_close.id = 'popup_btn_close';
		popup_btn_close.title = 'Sluiten';
		popup_btn_close.alt = 'Sluiten';
		popup_btn_close.src = '/img/popup_close.gif';
		popup_btn_close.onclick = close_popup;


		self._xmlhttp.open("GET", url, true);
		self._xmlhttp.onreadystatechange = function() {
			if (self._xmlhttp.readyState == 4) {
				self._popup.innerHTML = self._xmlhttp.responseText;

				self._popup.appendChild(popup_btn_close);

				if (exec_onload) {
					setTimeout(exec_onload, 0);
				}
			}
		}



		self._xmlhttp.send(null);
		
	},

	close : function() {
		var self = this;
		self._popup.style.display	= 'none';
		self._overlay.style.display	= 'none';	
		self._popup.innerHTML = '';
	},

	_positionPopup : function(width) {
		var self = this;
		

		var docElem = (window.document.documentElement) ? window.document.documentElement : docElem = window.document.body
		var scroll_top = window.pageYOffset ? window.pageYOffset : docElem.scrollTop;
		var page_width = (docElem.scrollWidth ? docElem.scrollWidth : docElem.offsetWidth);
		
		self._popup.style.left = ((page_width - width) / 2) + 'px';
		self._popup.style.top = (100 + scroll_top) + 'px';

	}
	
}


function show_popup(url, exec_onload) {
	Popup.show(url, exec_onload);
}
function close_popup() {
	Popup.close();
}


function show_kid_background(kid_id) {

	var url = '/kids/0/'+kid_id+'&_popup=1';
	Popup.show(url);


}

var ppu_tab_active = null;
var ppu_content_active = null;
function goPPUYearTab(year) {
	//-- hide active content
	if (ppu_content_active) {
		ppu_content_active.style.display = 'none';
	}
	//-- switch tab
	if (ppu_tab_active) {
		ppu_tab_active.className = 'tab_inactive';
	}
	
	//-- show new content	
	ppu_content_active = document.getElementById('contents_year_' + year);
	ppu_tab_active = document.getElementById('ppu_tab_' +  year);
	if (ppu_content_active){
		 ppu_content_active.style.display = '';
	}
	if (ppu_tab_active) ppu_tab_active.className = 'tab_active';
}

