﻿PT.Sites.Gogo.Headmenu = function() {
	var me = this;

	this.currentLayer = null;
	this.defaultLayer = null;
	this.currentLayerNum = 0;
	this.defaultLayerNum = 0;
	this.TimeOut = 500;
	this.currentitem = null;
	this.closeTimer = null;
	
	PT.Sites.General.RegisterEvent(window, "load", function() {me.initCurrent();} );
	document.onclick = function(){me.mClose();};
}

PT.Sites.Gogo.Headmenu.prototype.initCurrent = function() {
	var lis = get$('hoofdmenu').getElementsByTagName('li');
	for(var i=0; i<lis.length; i++){
		if(lis[i].className.indexOf('actief')!=-1){
			if(lis[i].getElementsByTagName('div')[0]) {
				this.currentLayer = lis[i].getElementsByTagName('div')[0];
				this.defaultLayer = lis[i].getElementsByTagName('div')[0];
				this.currentLayerNum = parseFloat(lis[i].getElementsByTagName('div')[0].id.substring(4));
				this.defaultLayerNum = parseFloat(lis[i].getElementsByTagName('div')[0].id.substring(4));
				break;
			}
			else{
				this.currentLayer = null;
				this.defaultLayer = null;
				this.currentLayerNum = 0;
				this.defaultLayerNum = 0;
				break;
			}
		}
		else{
			this.currentLayer = null;
			this.defaultLayer = null;
			this.currentLayerNum = 0;
			this.defaultLayerNum = 0;
		}
	}
}

PT.Sites.Gogo.Headmenu.prototype.mOpen = function(mm, n) {
	var me = this;
	var l = get$("menu" + n);

	if (l) {
		me.mCancelCloseTime();
		l.style.display = 'block';
		if (this.currentLayer && (this.currentLayerNum != n))
			this.currentLayer.style.display = 'none';
		this.currentLayer = l;
		this.currentitem = mm;
		this.currentLayerNum = n;
	}
	/*else if (this.currentLayer) {
		this.currentLayer.style.display = 'none';
		this.currentLayerNum = 0;
		this.currentitem = null;
		this.currentLayer = null;
	}*/
}

PT.Sites.Gogo.Headmenu.prototype.mCloseTime = function() {
	var me = this;
	this.closeTimer = window.setTimeout(function(){me.mClose();}, this.TimeOut);
}

PT.Sites.Gogo.Headmenu.prototype.mCancelCloseTime = function() {
if (this.closeTimer) {
    window.clearTimeout(this.closeTimer);
    this.closeTimer = null;
  }
}

PT.Sites.Gogo.Headmenu.prototype.mClose = function() {
	if (this.currentLayer) {
		this.currentLayer.style.display = 'none';
		this.currentLayerNum = 0;
		this.currentLayer = null;
		this.currentitem = null;
	}
	if (this.defaultLayer) {
		this.defaultLayer.style.display = 'block';
	}
	this.currentLayerNum = this.defaultLayerNum;
	this.currentLayer = this.defaultLayer;
}

