// def.js build:110

//Tilføjelse i clickMenu(xid) af Karsten Ronge, Gyldendal 14-01-2003
//-- DHTML function
NS4 = (document.layers)?true:false;
IE4 = (document.all)?true:false;
st = (document.all)?'.style':'';
range = (document.all)?'document.all.':'document.layers.';
sh = (document.all)?'visible':'show';
hd = (document.all)?'hidden':'hide';
var visible = (NS)? 'show':'visible';
var hidden = (NS)? 'hide':'hidden';

var IE = navigator.appName.indexOf("Microsoft") != -1;
var NS = navigator.appName.indexOf("Netscape") != -1;
var MAC = navigator.platform.indexOf("Mac") != -1;
var ie=document.all?1:0;
var n=document.layers?1:0;
var isVergine = true;
var imageDir = "/gyldendal/gu/ressource.nsf/id/js_img/$File/";
var omr = new Object();

styleSwitch = (n)?'':'.style';
layerRef = (n)?'document.layers':'document.all';
styleSwitch = (n)?'':'.style';
layerStyleRef = (n)?'layer.':'layer.style.';
x_show = (n)?'show':'visible';
x_hide = (n)?'hide':'hidden';
x_bgcolor = (n)?'bgColor':'backgroundColor';
x_src = (n)?'src':'innerHTML';
var oLMenu;

function getref(lay, nostyle) {if (nostyle) {obj = eval(range + lay);} else {obj = eval(range + lay + st);}return obj;}

function menurepos(refimg, reflay, obj) {
	t_dx =  obj.xadjust;
	var menuoffsetY = false;
	alert(refimg+' ' + reflay+' ' +  obj);
	if (n) {
		var refobj = eval('document.layers.' + reflay + '.document.' + refimg);
		var reflayobj = eval('document.layers.' + reflay) 
		var menuoffsetX = parseInt(refobj.x) - parseInt(obj.w) + refobj.width + reflayobj.left;
		obj.move(menuoffsetX +t_dx, false);
	} else {
		var refobj = eval('document.' + refimg);
		var reflayobj = eval('document.all.' + reflay + st) 
		menuoffsetX = parseInt(refobj.offsetLeft) + parseInt(refobj.width) + parseInt(reflayobj.left) + parseInt(refobj.offsetParent.offsetLeft) - obj.w;
		obj.move(menuoffsetX +t_dx, menuoffsetY);
	}
}
function resizeFix() {
var bodyHeight
var bodyWidth;
	if (NS) {
		if  (bodyHeight != this.innerHeight || bodyWidth != this.innerWidth) {
//			location.reload();
			bodyHeight = this.innerHeight;
			bodyWidth = this.innerWidth;
		}		
	} else if (IE) {
		bodyHeight = document.body.clientHeight;
		bodyWidth = document.body.clientWidth;
	}
	
}
function layeronold(leftsubmenu){
 if (document.layers) {
		document.layers['DUMMY'].document.layers['leftchoosetext'].visibility = hd;
		document.layers['DUMMY'].document.layers['leftmenusub'].visibility = sh;
    }
    else if (document.all) {
		document.all['DUMMY'].document.all['leftchoosetext'].style.visibility = hd;
		document.all['DUMMY'].document.all['leftmenusub'].style.visibility = sh;
    }
}

function menuOn() {
	menuShow = true;
	getref('newsbox').visibility = hd;
	getref('leftmenusub').visibility = sh;
}
function layerOn(thelayer){
getref(thelayer).visibility = sh;
}


var nswidth = 0;
function checkwidth() {
	if (nswidth!=window.innerWidth) {
		nswidth =window.innerWidth; 
		location.reload;
		}
	setTimeout('checkwidth()',100);
}

function flytlag(lag, x,y) {
	// set lag til usynligt
	getref(lag).visibility = hd;
	// flyt laget til y-koordinat 100
	getref(lag).top = y;
	// flyt laget til x-koordinat 100
	getref(lag).left = x;

		
	// hvis du vil slippe for at positioner angives med 'px' i enden skal du bare sige:
	var XXX = parseInt(getref(lag).left);
	// husk det STORE I i Int
}
function chk() {
	var width;
	//alert('yoyo');
	if (document.all){
		width = document.body.offsetWidth;
	}
	else if (document.layers){
	    width = window.innerWidth;
	}
	return width;
}


function xObj(obj,nest,vis){
    	this.css= eval(range + obj + st);
		this.obj = eval(range + obj);
        this.hideIt= b_hideIt;
        this.showIt= b_showIt;
		this.top=b_gettop;
		this.content = b_content;
}
//-- DHTML sub functions
function b_content(s) {
	if (n) {
		document.layers.leftmenusub.document.open();
		document.layers.leftmenusub.document.write(s); 
		document.layers.leftmenusub.document.close();
	} else {
		this.obj[x_src] = s; 
	}
}

//Get's the top position.
function b_gettop(){ 
	return (n) ? eval(this.css.top):this.obj.offsetTop; 
}
//The functions for showing and hiding
function b_showIt(){
        this.css.visibility=x_show;
}
function b_hideIt() { this.css.visibility=x_hide; }

function b_bgcolor() { this.css.x_bgcolor; }

//-- DHTML function END
//-- Menu function


var indentCount = 0;

var arrow = new Object;
arrow['open'] = 'comm_arrow2menu.gif';
arrow['closed'] = 'comm_arrow1menu.gif';
arrow['right'] = 'comm_arrow3menu.gif';
arrow['none']	= 'dot.gif';

//-- redraw l-menu on mouseClick using drawMenu
function clickMenu(xid) {
 t_state = '';
 t_id = xid; 
 selectedId = xid;
 //if (state[xid]=='open') { t_state='closed';   } else { if ( state[xid]=='closed' ) {  t_state='open'; t_id=getFirstChild(xid); } } // old line - open/close
 t_state='open'; t_id=getFirstChild(xid); // new line - always open
 drawMenu(t_id);
 if (t_state) state[xid]=t_state;
 
 if (url[xid]) {
  s = url[xid];
	//######### by KR 14-01-2003 ###:
	o=(omr && omr[xid] ? omr[xid]:'');
	if (areaCode && areaCode=='digi')
	{
		o=(o=='digi' || o=='' ? '':'&omraadeid='+o);
	}
	else{
		o=(o=='digi' ? '&omraadeid='+o:'');
	}
	//######### END by KR 14-01-2003 ###

  if ( url[xid].indexOf("?") != "-1") {
   //document.s[i].search= replaceLink( url[xid] )
   //(s.substr(0,1)=='@') ? eval(s.substr(1)):location= replaceLink( url[xid] ); //KR 14-01-2003
   (s.substr(0,1)=='@') ? eval(s.substr(1)):location= replaceLink( url[xid]+o ); //KR 14-01-2003
  }
  else
  {
   //(s.substr(0,1)=='@') ? eval(s.substr(1)):location= url[xid]; //KR 14-01-2003
   (s.substr(0,1)=='@') ? eval(s.substr(1)):location= url[xid]+o; //KR 14-01-2003
  }
 }
}

//-- draws the menu
function drawMenu(id) {
	
	if (! id) id = selectedId;
	indentCount=0;
	oLMenu.content( '<table bgcolor="#ffffff" width="170" cellpadding="0" cellspacing="0" border="0">'+doParent(  parentId[id] ) +doSiblins(id)+'</table>' );
}

function getFirstChild(id) {
	for (var i in parentId) { 
		if (parentId[i]==id) { return i; }
	}
	return false;
}


f_menuCellStart = '<tr><td width="170">';
f_menuCellEnd   = '</td></tr>';
f_menuDelimiter = '<tr><td><img src="'+imageDir+'dotline170.gif" width="170"></td></tr>';
if ( navigator.appVersion.indexOf("IE 4")!=-1 ) {
f_menuCellStart = '';
f_menuCellEnd   = '<br>\n';
f_menuDelimiter = '<img src="'+imageDir+'dotline170.gif" width="170"><br>\n';
}
function doSiblins(id) {
	s = '';
	t = '';
	cap = new Object();
	for (var k in parentId)
	{
		if((caption[k].length + indentCount) > 22)
		{
			stopper = 22 - caption[k].length;
			cap[k] = caption[k].slice(0, (stopper-(indentCount*2)))+" ...";
		}
		else
		{
			cap[k] = caption[k];
		}
	}

	pid=parentId[id];
	if (pid) {
		for (a=0; a<indentCount; a++){ t+='&nbsp;&nbsp;'; }
		for (var i in parentId) 
		{      
			if (parentId[i]==pid) 
			{ 
			 	c = (i==id)?'':'';
			 	ahref = '<a href="javascript: void clickMenu(\''+i+'\')"  class="menutext">';
				state[i]='closed';
				if ( ( (pil[i]=='yes')&&(getFirstChild(i)) ) || (pil[i]=='right') ) {
				    arrowimg = (pil[i]=='right')?'right':'closed';
				} else {
					arrowimg = 'none';
				}
				t_arrow = '<img src="'+imageDir+arrow[arrowimg]+'" width="5" height="7" alt="" border="0"> ';

	
				s += f_menuCellStart + '<img src="'+imageDir+'dot.gif" width='+(indentCount*10+10)+' height=12>' + ahref + t_arrow + cap[i] +'</a>'+ f_menuCellEnd+'\n';
			 }
		}   
	}
	return s;
}

function doParent(id) {
	
	this.id = id;
	this.s = '';
	var cap = '';
	if (id == 'root') return s;
	
	if ((id != '')&&(id != 'root')&&( parentId[id] != 'root')&&( parentId[id] != ''))
	{
		
		state[id]='open';
		s = doParent( parentId[id] );
	}
		t = '';
		for (a=0; a<indentCount; a++){ t+='&nbsp;&nbsp;'; }
		if (! indent[id]) indent[id] = t;
		indentCount++;

		if ((caption[id].length + indentCount) > 25)
		{
			stopper = (24-caption[id].length);
			cap = caption[id].slice(0, (stopper-(indentCount*2))) + " ...";
		}
		else
		{
			cap = caption[id];
		}

		ahref = '<a href="javascript: void clickMenu(\''+id+'\')"  class="menutext">';
		t_arrow = '<img src="'+imageDir+arrow['open']+'" width="5" height="7" alt="" border="0"> ';
		s+= f_menuCellStart + '<img src="'+imageDir+'dot.gif" width='+indentCount*10+' height=12>'+ ahref + t_arrow + cap+'</a>'+ f_menuCellEnd+f_menuDelimiter+'\n';
	return s
	
}

//-- Menu function END

//-- Init functions 
var indentCount = 0;

var mObjs = new Array;
var mObjTop = new Array;
var mObjDy  = new Array;
var isLoaded = false;

var bottomTop=0;
var glPos = -1;
var glPosRap = 0;
var showMenu = true;
tmp = 0;
var counter = 0;
var timeout = 16;

counterMax = (n)?18:38;
var scrolled=0;
var glBodyHeight = -1;
var glBodyWidth = -1;
var set_mInc	= 10;
var set_mSpeed  = 1;
var rm;
var lm;
function jsinit() {
	
	isLoaded = true;
    scrolled=n?"window.pageYOffset":"document.body.scrollTop";
	menuBarInit();

	
}
//-- Init functions END

//-- Top & Bottom functions


function menuBarInit(){
	  	//checkScrolled();
		resizeFix();
}
glBodyWidth =0;
glBodyHeight =0;

/* Init offset so it is "not scrolled" when the page is loaded the first time*/
var offset = -10;

//function checkScrolled() {
//	if (document.layers) {
//		if (offset != self.pageYOffset && offset !=-500) //{Isscrolled(self.pageYOffset)}
//		offset = self.pageYOffset;
//	} else {
//		if (offset != document.body.scrollTop && offset !=-500) //{Isscrolled(document.body.scrollTop)}
//		offset = document.body.scrollTop;
//	}
//		setTimeout('checkScrolled()',10);
//}
//function Isscrolled(gPos) {
//	for (var aa in mObjs) {
//		if (mObjTop[aa]) {
//			mObjs[aa].css.top = gPos + mObjDy[aa];
//			//if (IE4) mObjs[aa].obj.style.filter = 'alpha(opacity = ' + transpt //+ ')';
//		} else { 
//			var h = mObjDy;
//			t_dy = (n)?0:-2;
//			
//			(IE4) ? mObjs[aa].css.top=getHeight() - 28 - //t_dy:mObjs[aa].css.top=getHeight() - 23 - t_dy;
//		}
//	}
//	if(rm) {rm.y= gPos+25;}
//	if(lm) {lm.y= gPos+125;}
//}

function getHeight() {
	if (n) {			
		var xMax = window.innerHeight;
		var jdscrl = self.pageYOffset;
	} else {
		var xMax = document.body.clientHeight;
		var jdscrl = document.body.scrollTop;
	}
	return xMax + jdscrl;
}

/* Scroll pop-down2 START */

var menu1;
var timer;
function outTimer() {
	clearTimeout(timer);
	timer = setTimeout('closeAllObjs()', 15000);
}

var activeObjs = new Array();
function closeAllObjs() {
	for (var a = 0; a < activeObjs.length; a++) {
		obj = eval(activeObjs[a])
		if(!obj.closed) {
			obj.unfold(0);
			outlay.visibility = hd;
		}
	}
	outlay = eval(range + 'mouseoutlay' + st);
	clearTimeout(timer);
}

function rollmenu(name, objname) {
// add to list of objects
	activeObjs[activeObjs.length] = objname;

// properties:
	this.lay = name; this.objname = objname; this.item = new Array(); this.itemlink = new Array(); this.closed = true; this.itemsub = new Array();
// positioning properties:
	obj = eval(range + this.lay + st); this.menuheight; this.menuwidth; this.y = parseInt(obj.top); this.speed = 1; this.inc = 1;
	
// close all submenus
	this.closeSubs = closeSubs;

// refobj properties:
	this.refobj; this.refobjinit = refobjinit; 
	//this.switchrefHTML = switchrefHTML; 
	this.resetsize = resetsize; 

// menu items properties:
	this.active = 0; this.ItemStartHTML = ''; this.ItemEndHTML = ''; this.ItemLinkStart1 = ''; this.ItemLinkStart2 = ''; this.ItemLinkEnd = ''; this.MenuStartHTML = ''; this.MenuEndHTML = '';

// initializing functions:
	this.additem = additem; this.setmenu = setmenu; this.menuinit = menuinit; this.setactive = setactive; this.initsize = initsize; this.unfold = unfold;
	
// positioning functions:
	this.move = move; this.setclip = setclip;
	
// Mouseout menu remove
//	this.laybg = name + 'bg';
	// new functionality here!
	this.laybg = 'mouseoutlay';
}

function closeSubs() {
	for (var i = 0; i < this.itemsub.length; i++) {
		if(this.itemsub[i]) {
			var clobj = eval(this.itemsub[i]);
			if (!clobj.closed) {
				clobj.unfold(0);
			}
		}
	}
}

function resetsize() {this.menuheight = this.basemenuheight;this.menuwidth = this.basemenuwidth;}

function move(x, y) {
	var obj = eval(range + this.lay + st);
	if (y != false) {obj.top = y;}
	if (x != false) {obj.left = x;}
}

function setclip(top, h, left, w) {
	if (NS4) {var obj = eval(range + this.lay + '.clip'); obj.top = top; obj.height = h; } else { var obj = eval(range + this.lay + st); obj.clip = 'rect(' + top + 'px auto ' + (top+h) + 'px auto)';}
}
function unfold(stop) {
	outTimer();
	obj = eval(range + this.lay + st);
	bgobj = eval(range + this.laybg + st);
	if (!this.closed) {
		obj.visibility = hd;
		bgobj.visibility = hd;
		this.closed = true;
		return false;
	}
	obj.visibility = sh;


	if (stop > this.menuheight) {
		eval(this.objname + '.move(' + false + ',' + (this.y + this.menuheight - this.menuheight) + ')');
		eval(this.objname + '.setclip(' + (this.menuheight - this.menuheight) + ',' + (this.y + this.menuheight) + ')');
		this.resetsize();
		this.closed = false;
		return false;
	} else {
		eval(this.objname + '.move(' + false + ',' + (this.y + stop - this.menuheight) + ')');
		eval(this.objname + '.setclip(' + (this.menuheight - stop) + ',' + (this.y + stop) + ')');
		setTimeout(this.objname + '.unfold(' + (parseInt(stop) + this.inc) + ')', this.speed)
	}
	bgobj.visibility = sh;
}

function switchrefHTMLxxxx() {
	if (!this.refobj) {
		return false;
	}

	var text = '<a href="javascript: void ' + this.objname + '.unfold(0);">';
	text += this.item[this.active];
	text += '</a>';
	obj = eval(range + this.refobj);
	if (NS4) {	
		swaptext(this.refobj, this.active, rm);
	} else {
		obj.innerHTML = this.item[this.active];
	}
}

function refobjinit(refobjname) {
	this.refobj = refobjname;
	obj = eval(range + this.refobj + st);
	this.rotop = parseInt(obj.top);
	this.roleft = parseInt(obj.left);
	obj = eval(range + this.refobj);
	this.rowidth = (NS4) ? obj.clip.width : obj.clientWidth;
	this.roheight = (NS4) ? obj.clip.height : obj.scrollHeight; // obj.clientHeight;
	
}

function initsize() {
	obj = eval(range + this.lay);
	this.menuheight = (NS4) ? obj.clip.height : obj.scrollHeight; // obj.clientHeight;
	this.menuwidth = (NS4) ? obj.clip.width : obj.clientWidth;
	this.basemenuheight = (NS4) ? obj.clip.height : obj.scrollHeight; // obj.clientHeight;
	this.basemenuwidth = (NS4) ? obj.clip.width : obj.clientWidth;
}

function setactive(id) {
	this.closed = true;
	obj = eval(range + this.lay + st);
	bgobj = eval(range + this.laybg + st);
	this.active = id;
	obj.visibility = hd;
	bgobj.visibility = hd;
	this.setmenu();
	this.resetsize();
//	this.switchrefHTML();
}

function menuinit() {
	this.setmenu();
	this.initsize();
}

function additem(text) {this.item[this.item.length] = text;}

function setmenu() {
	var text = '';
	for (var a = 0; a < this.item.length; a++) {
		if (this.itemsub[a]) {
//			var submenu = eval(range + this.itemsub[a] + st);
			var sublay = eval(this.itemsub[a] + '.lay');
			if (this.active != a) {
				text += this.ItemStartHTML;
				text += '<a href="javascript:void(0);" onclick="' + this.objname + '.closeSubs();' + this.itemsub[a] + '.y=' + (parseInt(eval(range + sublay + st + '.top')) + (a*15)) + ';' + this.itemsub[a] + '.unfold(0);" class="leftchoose">'
//				text += '<a href="javascript:void(0);" onclick="' + this.itemsub[a] + '.y=' + (parseInt(eval(range + sublay + st + '.top')) + (a*15)) + ';' + this.itemsub[a] + '.unfold(0);" onmouseout="if(!' + this.itemsub[a] + '.closed){' + this.itemsub[a] + '.unfold(0);}" class="leftchoose">'
//				text += '<a href="javascript:' + this.itemsub[a] + '.y=' + (parseInt(eval(range + sublay + st + '.top')) + (a*15)) + ';' + this.itemsub[a] + '.unfold(0);" class="leftchoose">'
//				text += '<a href="javascript:' + this.itemsub[a] + '.y=' + (parseInt(eval(range + sublay + st + '.top')) + (a*15)) + '; ' + range + '' + sublay + 'bg' + st + '.top = ' + (eval(this.itemsub[a] + '.y') + (a*15) - 40) + ';' + this.itemsub[a] + '.unfold(0);" class="leftchoose">'
				text += this.item[a];
				text += '</a>'
				text += this.ItemEndHTML;
			}
		} else {
			if (this.active != a) {
				text += this.ItemStartHTML;
				if (this.itemlink[a]) {
					text += this.itemlink[a];
				}
				text += this.item[a];
				if (this.itemlink[a]) {
					text += '</a>';
				}
				text += this.ItemEndHTML;
			}
		}
	}
	obj = eval(range + this.lay);
	if (NS4) {
		obj.document.open();
		obj.document.write(this.MenuStartHTML + text + this.MenuEndHTML);
		obj.document.close();
	} else {
		obj.innerHTML = this.MenuStartHTML + text + this.MenuEndHTML;
	}
}

/* Scroll pop-down2 END */
//returnere window width og browser
function returnWindowWidth() {
var widthbrow = 0;
if (document.layers) {
    widthbrow = window.innerWidth;
	if (widthbrow<796) 
		widthbrow=768;
}
else if (document.all) {
    widthbrow = document.body.clientWidth;
	if (widthbrow<780) 
		widthbrow=768;
}
return widthbrow;
}

