function lib_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.opera6=this.agent.indexOf("Opera 6")>-1
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie5=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie5 || this.ie6 || this.ie7
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie7 || this.ie6 || this.ie5 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()

function calcPosition(){
	if (bw.ns4 || bw.ns6) {
		doc_width = self.innerWidth;
	} 
	else if (bw.ie5 || bw.ie6 || bw.ie7) {
		doc_width = document.body.clientWidth;
	}
	var pos = (doc_width/2) - 375;
	if(bw.ie5 || bw.ie6 || bw.ie7 || bw.opera5 || bw.opera6){
		document.all.submenu1.style.left = pos + 160;
		document.all.submenu2.style.left = pos + 278;
		document.all.submenu3.style.left = pos + 396;
		document.all.submenu4.style.left = pos + 514;
		document.all.submenu5.style.left = pos + 632;
	}
	if (bw.ns6){
		document.getElementById("submenu1").style.left = pos + 160;
		document.getElementById("submenu2").style.left = pos + 278;
		document.getElementById("submenu3").style.left = pos + 396;
		document.getElementById("submenu4").style.left = pos + 514;
		document.getElementById("submenu5").style.left = pos + 632;
	}
		
	if(bw.ns4){
		document.layers[0].left = pos + document.layers[0].left;
		document.layers[0].top = document.layers[0].top - 7;
		document.layers[1].left = pos + document.layers[1].left;
		document.layers[1].top = document.layers[1].top - 7;
		document.layers[2].left = pos + document.layers[2].left;
		document.layers[2].top = document.layers[2].top - 7;
		document.layers[3].left = pos + document.layers[3].left;
		document.layers[3].top = document.layers[3].top - 7;
		document.layers[4].left = pos + document.layers[4].left;
		document.layers[4].top = document.layers[4].top - 7;
	}
}

function objects(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=objects(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
// vars for layers
var openLayer= new Array();
openLayer[0] = "0";
subLayer = "";
var timer;
var mousePosition;
function controlLayers() {
  var i,p,v,obj,args=controlLayers.arguments;
if(openLayer[0] != 0 && args[1] == ""){
	recursiveClose();
	}
  openLayer[0] = args[0];
  
  if (objects(openLayer[0]) != null){ // finns objektet
	if(bw.ie5 || bw.ie6 || bw.ie7 || bw.opera5 || bw.opera6)
		document.all[openLayer[0]].style.left = mousePosition-25;
	if (bw.ns6)
		document.getElementById(openLayer[0]).style.left = mousePosition-25;
  }
	
	
  for (i=0; i<(args.length-2); i+=3) if ((obj=objects(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
function closeLayer() {
  var i,p,v,obj,args=closeLayer.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=objects(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
function recursiveClose(){ //om man använder flera nivåer, vilket vi inte gör
	for(i=0; i< openLayer.length; i++){
		if(openLayer[i] != null)
		 closeLayer(openLayer[i],'','hide');
	}
}
function countdown(){
timer = setTimeout("recursiveClose()", 1000);
}
function clearTheTimer(){
	clearTimeout(timer);
}

//Scroll functions ###################################################################################################################
var timer;
var speed;

function makeObj(obj,nest){
    nest=(!nest) ? "":'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie6?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie6?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight
	this.up=goUp;this.down=goDown;
	this.moveIt=moveIt; this.x=0; this.y=0;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

function moveIt(x,y){
	this.x = x
	this.y = y
	this.css.left = this.x+px
	this.css.top = this.y+px
}

//Makes the object go up
function goDown(move){
	if (this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(0,this.y-move)
			if (loop) setTimeout(this.obj+".down("+move+")",speed)
	}
}

//Makes the object go down
function goUp(move){
	if (this.y<0){
		this.moveIt(0,this.y-move)
		if (loop) setTimeout(this.obj+".up("+move+")",speed)
	}
}

//Calls the scrolling functions. Also checks whether the page is loaded or not.
function scroll(speed){
	if (scrolltextLoaded){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

//Stops the scrolling (called on mouseout)
function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}

//Makes the object
var scrolltextLoaded = false
function scrolltextInit(){
	oCont = new makeObj('news')
	oScroll = new makeObj('newsText','news')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	scrolltextLoaded = true
	
}

//Start scrolling after stopped (called on mouseout)
function newScroll(speed){
	loop = false
	if (timer) clearTimeout(timer)
}


//Misc. functions ###################################################################################################################

function openWin(url, name,spec){
window.open(url, name, spec)
}

function printNews(){
	window.print();
	window.close();
}

function language(id){
document.images["language"].src= "images/system/language" + id + ".gif";
}
function mPos(position){
mousePosition = position;
}
function movemenu(){
	mPos(event.clientX);
	if (objects(openLayer[0]) != null){ // finns objektet
	if(bw.ie5 || bw.ie6 || bw.ie7|| bw.opera5 || bw.opera6)
		document.all[openLayer[0]].style.left = mousePosition-25;
	if (bw.ns6)
		document.getElementById(openLayer[0]).style.left = mousePosition-25;
  }
}
