

function d(lager) {
	document.getElementById(lager).style.visibility = "hidden";
}

function v(lager) {
	document.getElementById(lager).style.visibility = "visible";
}

var currentLayer = "none";
var currentLayer2 = "none";

function s(lager) {
	if(currentLayer!=lager){
		if(currentLayer!="none"){
			d(currentLayer);
		}
		if(currentLayer2!="none"){
			d(currentLayer2);
			currentLayer2 = "none";
		}
		v(lager);
		currentLayer = lager;
	}else{
		d(lager);
		if(currentLayer2!="none"){
			d(currentLayer2);
			currentLayer2 = "none";
		}
		currentLayer = "none";
	}
}

function s2(lager) {
	if(currentLayer2!=lager){
		if(currentLayer2!="none"){
			d(currentLayer2);
		}
		v(lager);
		currentLayer2 = lager;
	}else{
		d(lager);
		currentLayer2 = "none";
	}
}


function getsize(lager){
    if (document.all){return document.all[lager].clientHeight;}
    if(document.getElementById){return document.getElementById(lager).offsetHeight;}
}

function getWidth(lager){
    if (document.all){return document.all[lager].clientWidth;}
    if(document.getElementById){return document.getElementById(lager).offsetWidth;}
}

function getHeight(lager){
        if (document.all) return document.all[lager].clientHeight;
        if(document.getElementById){return document.getElementById(lager).offsetHeight;}
}

function bytbild(bildNamn, bildSrc){
 eval('document.'+bildNamn+'.src = bildSrc');
}


// scroll


function createScroll(name, scrollWidth, scrollHeight, lay){
    this.name = name;
    this.scrollWidth = scrollWidth;
    this.scrollHeight = scrollHeight;
    this.lay = lay;
    this.setClipping = setClipping;
    this.ned = false;
    this.up = false;
    this.top = 0;
    this.bot = scrollHeight;
    this.y = document.getElementById(this.lay).style.top;
    this.y = parseInt(this.y);
    this.ner = ner;
    this.upp = upp;
	
	this.v = false;
    this.h = false;
    this.left = 0;
    this.right = scrollWidth;
    this.x = document.getElementById(this.lay).style.left;
    this.x = parseInt(this.x);
    this.hoger = hoger;
    this.vanster = vanster;


    this.Thoger = Thoger;
    this.Tvanster = Tvanster;
	
	this.Thoger2 = Thoger2;
    this.Tvanster2 = Tvanster2;
	this.Tspeed = 10;

    this.scrollUnits = getWidth(lay)/scrollWidth;
    this.scrolledUnits=0;
     	
    this.movedPixels = 0;
    this.pixToScroll = 0;
	this.speed = 40;
    this.checkScroll = checkScroll;
	this.resetScroll = resetScroll;
}

function resetScroll(){
	this.movedPixels 	= 0;
    this.pixToScroll 	= 0;
	this.top			= 0;
	this.bot			= this.scrollHeight;
	this.left			= 0;
	this.right			= this.scrollWidth;
	document.getElementById(this.lay).style.top		= this.y;
	document.getElementById(this.lay).style.left	= this.x;
}

function setClipping(){
    document.getElementById(this.lay).style.clip = "rect(0px "+this.scrollWidth+"px "+this.scrollHeight+"px 0px)";
}

function checkScroll(arrowlay){
	this.resetScroll();
    if (getsize(this.lay) > this.scrollHeight){
		// först flyttar vi scrollen
		if(arrowlay!="scroll2"){
			document.getElementById(arrowlay).style.left = (this.x + this.scrollWidth+107)+"px";
			document.getElementById(arrowlay).style.top = (this.y + this.scrollHeight+3)+"px";
		}
        v(arrowlay);
    }else{
		d(arrowlay);
	}
}

function ner(){
	var t3 = parseInt(document.getElementById(this.lay).style.top);
    this.movedPixels = this.y-t3;
    this.pixToScroll = getsize(this.lay) - this.scrollHeight;
	//alert(t3 +'-'+ document.getElementById(this.lay).style.clip);
    if(this.ned==true && (this.pixToScroll > this.movedPixels)){
        this.top = this.top+3;
        this.bot = this.bot+3;
        document.getElementById(this.lay).style.clip = "rect("+this.top+"px "+this.scrollWidth+"px "+this.bot+"px 0px)";
        document.getElementById(this.lay).style.top = (t3-3)+"px";
        if(this.ned){eval('setTimeout("'+this.name+'.ner()", '+this.speed+')');}
        return true;
    }
}

function upp(){
	var t3 = parseInt(document.getElementById(this.lay).style.top);
    if(this.up==true && (this.y-t3 > 0)){
        this.top = this.top-3;
        this.bot = this.bot-3;
        document.getElementById(this.lay).style.clip = "rect("+this.top+"px "+this.scrollWidth+"px "+this.bot+"px 0px)";
        document.getElementById(this.lay).style.top = (t3+3)+"px";
        if(this.up){eval('setTimeout("'+this.name+'.upp()", this.speed)');}
        return true;
    }
}



function hoger(){
	var t3 = parseInt(document.getElementById(this.lay).style.left);
    this.movedPixels = this.x-t3;
    this.pixToScroll = getWidth(this.lay) - this.scrollWidth;
	//alert(t3 +'-'+ document.getElementById(this.lay).style.clip);
    if(this.h==true && (this.pixToScroll > this.movedPixels)){
        this.left = this.left+3;
        this.right = this.right+3;
        document.getElementById(this.lay).style.clip = "rect("+this.top+"px "+this.right+"px "+this.bot+"px "+this.left+"px)";
        document.getElementById(this.lay).style.left = (t3-3)+"px";
        if(this.h){eval('setTimeout("'+this.name+'.hoger()", '+this.speed+')');}
        return true;
    }
}

function vanster(){
	var t3 = parseInt(document.getElementById(this.lay).style.left);
    if(this.v==true && (this.x-t3 > 0)){
        this.left = this.left-3;
        this.right = this.right-3;
        document.getElementById(this.lay).style.clip = "rect("+this.top+"px "+this.right+"px "+this.bot+"px "+this.left+"px)";
        document.getElementById(this.lay).style.left = (t3+3)+"px";
        if(this.v){eval('setTimeout("'+this.name+'.vanster()", this.speed)');}
        return true;
    }
}

//	function Thoger(){
//		var t3 = parseInt(document.getElementById(this.lay).style.left);
//		this.movedPixels = this.x-t3;
//		this.pixToScroll = getWidth(this.lay) - this.scrollWidth;
//		//alert(t3 +'-'+ document.getElementById(this.lay).style.clip);
//		if(this.h==true && (this.pixToScroll > this.movedPixels)){
//			this.left = this.left+285;
//			this.right = this.right+285;
//			document.getElementById(this.lay).style.clip = "rect("+this.top+"px "+this.right+"px "+this.bot+"px "+this.left+"px)";
//			document.getElementById(this.lay).style.left = (t3-285)+"px";
//			return true;
//		}
//	}

//	function Tvanster(){
//		var t3 = parseInt(document.getElementById(this.lay).style.left);
//		if(this.v==true && (this.x-t3 > 0)){
//			this.left = this.left-285;
//			this.right = this.right-285;
//			document.getElementById(this.lay).style.clip = "rect("+this.top+"px "+this.right+"px "+this.bot+"px "+this.left+"px)";
//			document.getElementById(this.lay).style.left = (t3+285)+"px";
//			return true;
//		}
//	}


function Thoger(){ 
     if(this.scrolledUnits<this.scrollUnits && !this.h){this.scrolledUnits++;} 
     this.h=true; 
     this.Thoger2(); 
} 
 
function Thoger2(){ 
     if(this.scrolledUnits<this.scrollUnits){ 
          var t3 = parseInt(document.getElementById(this.lay).style.left); 
         this.movedPixels = this.x-t3; 
         this.pixToScroll = getWidth(this.lay) - this.scrollWidth; 
          var jumpPix=7; 
          //alert(t3 +'-'+ document.getElementById(this.lay).style.clip); 
         if(this.movedPixels < ((this.scrollWidth*this.scrolledUnits)-jumpPix) ){ 
             this.left = this.left+jumpPix; 
             this.right = this.right+jumpPix; 
             document.getElementById(this.lay).style.clip = "rect("+this.top+"px "+this.right+"px "+this.bot+"px "+this.left+"px)"; 
             document.getElementById(this.lay).style.left = (t3-jumpPix)+"px"; 
               eval('setTimeout("'+this.name+'.Thoger2()", this.Tspeed)'); 
             return true; 
         }else{ 
               this.left = this.left+((this.scrollWidth*this.scrolledUnits)-this.movedPixels); 
               this.right = this.right+((this.scrollWidth*this.scrolledUnits)-this.movedPixels); 
               document.getElementById(this.lay).style.clip = "rect("+this.top+"px "+this.right+"px "+this.bot+"px "+this.left+"px)"; 
             document.getElementById(this.lay).style.left = (t3-((this.scrollWidth*this.scrolledUnits)-this.movedPixels))+"px"; 
               this.h=false; 
               return true; 
          } 
     }      
} 
 
function Tvanster(){ 
     if(this.scrolledUnits!=0 && !this.v){ this.scrolledUnits--; } 
     this.v = true; 
     this.Tvanster2(); 
} 
 
function Tvanster2(){ 
          if(this.scrolledUnits>=0){ 
          var t3 = parseInt(document.getElementById(this.lay).style.left); 
         this.movedPixels = this.x-t3; 
         this.pixToScroll = getWidth(this.lay) - this.scrollWidth; 
          var jumpPix=7; 
          //alert(t3 +'-'+ document.getElementById(this.lay).style.clip); 
         if(this.movedPixels > ((this.scrollWidth*this.scrolledUnits)+jumpPix) ){ 
             this.left = this.left-jumpPix; 
             this.right = this.right-jumpPix; 
             document.getElementById(this.lay).style.clip = "rect("+this.top+"px "+this.right+"px "+this.bot+"px "+this.left+"px)"; 
             document.getElementById(this.lay).style.left = (t3+jumpPix)+"px"; 
               eval('setTimeout("'+this.name+'.Tvanster2()", this.Tspeed)'); 
             return true; 
         }else{ 
               this.left = this.left+((this.scrollWidth*this.scrolledUnits)-this.movedPixels); 
               this.right = this.right+((this.scrollWidth*this.scrolledUnits)-this.movedPixels); 
               document.getElementById(this.lay).style.clip = "rect("+this.top+"px "+this.right+"px "+this.bot+"px "+this.left+"px)"; 
             document.getElementById(this.lay).style.left = (t3-((this.scrollWidth*this.scrolledUnits)-this.movedPixels))+"px"; 
               this.v=false; 
               return true; 
          } 
     } 
} 


function vAlignLayer(layer){
	var wWin;		
	
	//wWin =  window.innerHeight || document.body.offsetHeight;
	wWin = document.documentElement.clientHeight;
	
	if(wWin > 500){
		wWin = parseInt((wWin-500)/2);
	}else{
		wWin = 0;
	}
	
	document.getElementById(layer).style.top = wWin+'px';
	
}

function init(){
	vAlignLayer("page");
	if(document.getElementById && !document.all){
		onresize=pageResize;
	}else{
		window.onresize=pageResize;
	}
}

function pageResize(){
		vAlignLayer("page");
}
	
	