/********************************************************************************
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts. 
This may be used freely as long as this msg is intact!
********************************************************************************
Browsercheck:*/
ie=document.all?1:0
n=document.layers?1:0

//These are the variables you have to set:

//How many pixels should it move every step? 
var move=10;

//At what speed (in milliseconds, lower value is more speed)
menuSpeed=40

//Do you want it to move with the page if the user scroll the page?
var moveOnScroll=true

/********************************************************************************
You should't have to change anything below this.
(except in the init function to set how many menus and such.)
********************************************************************************/
//Defining variables
var tim;

//Object constructor
function makeMenu(obj,nest,lshow){
    nest=(!nest) ? '':'document.'+nest+'.'
    this.css=(n) ? eval(nest+'document.'+obj):eval(obj+'.style')					
    this.state=1
    this.go=0
    this.lshow=lshow
    this.ltop=(n)?this.css.top:this.css.pixelTop;
    this.mleft=m_left;
    this.right=m_right;
    this.menu=m_menu;
    this.tim
    this.width=n?this.css.document.width:eval(obj+'.offsetWidth')
    this.left=b_getleft
    this.obj = obj + "Object";
    eval(this.obj + "=this")	
}
//Gets the left position.
function b_getleft(){
	var gleft=(n) ? eval(this.css.left):eval(this.css.pixelLeft);
	return gleft;
}
/********************************************************************************
Deciding what way to move the menu (this is called onmouseover, onmouseout or onclick)
********************************************************************************/
function m_menu(){
	if(!this.state){
		clearTimeout(this.tim)
		this.mleft()	
	}else{
		clearTimeout(this.tim)
		this.right()
	}
}
//Menu in
function m_left(){
	if(this.left()>-this.width+this.lshow){
		this.go=1
		this.css.left=this.left()-move
		this.tim=setTimeout(this.obj+".mleft()",menuSpeed)
	}else{
		this.go=0
		this.state=1
	}	
}
//Menu out
function m_right(){
	if(this.left()<0){
		this.go=1
		this.css.left=this.left()+move
		this.tim=setTimeout(this.obj+".right()",menuSpeed)
	}else{
		this.go=0
		this.state=0
	}	
}
/********************************************************************************
Checking if the page is scrolled, if it is move the menu after
********************************************************************************/
function checkScrolled(){
		oMenu[0].css.top=eval(scrolled)+oMenu[0].ltop
		
	if(n) setTimeout('checkScrolled()',30)
}
/********************************************************************************
Inits the page, makes the menu objects, moves it to the right place, 
show it..Make as many as you want but remember that they take some
prosessor power in netscape if you have the moveOnScroll on.
In the makeMenu, after the layername and the nest, the next
parameter is the old lshow, it's how much of
the menu will show when the menu is in the in state.
********************************************************************************/
function menuInit(){
	oMenu=new Array()
	oMenu[0]=new makeMenu('divMenu','',16)
	scrolled=n?"window.pageYOffset":"document.body.scrollTop"
	// left = negative width (totally off screen) + show amount
	oMenu[0].css.left=-oMenu[0].width+oMenu[0].lshow
	oMenu[0].css.visibility='visible'
	if(moveOnScroll) ie?window.onscroll=checkScrolled:checkScrolled();
}

//Initing menu on pageload
onload=menuInit;