window.onload = init;

var visiblearea = 254;
var moveablebox;
var marginleft = 10;
var t;
var run = true;
var scrollable_Area = 0;
var _speed = 15;

function init(){
	if (document.getElementById("divMenu")){
	moveablebox = document.getElementById("divMenu");
	var aTags = moveablebox.getElementsByTagName("a");
//	var boxLength =	aTags.length * 34;
	var boxLength =	aTags.length * Math.round((aTags.length * 2.6));
	var moveableboxW = boxLength;	
//	moveablebox.style.width = moveableboxW + 'px';;	
	moveablebox.style.width = '650px';;	
	scrollable_Area = parseInt(moveableboxW) - visiblearea;
	}
	if (document.getElementById('divMenu')) {
	returnHash(document.location.href);
	}

}
function stopM(){
	run = false;
}
function goL(){
	run = true;
	moveL();
	}
function goR(){
	run = true;
	moveR();
	}

function moveL(){
	if (marginleft>-scrollable_Area && run ){
		moveablebox.style.marginLeft = (--marginleft) + 'px'	
		t = setTimeout("moveL()",  _speed);		
	}
	return false;
}

function moveR(){
	if (marginleft<10 && run){
		moveablebox.style.marginLeft = (++marginleft) + 'px'	
		t = setTimeout("moveR()",  _speed);	
	}
	return false;
}
function findMarginL(){


var ml = document.getElementById('divMenu').offsetLeft;

	var theDiv = document.getElementById('divMenu');
	
	var theLinks = theDiv.getElementsByTagName('a');
	
	for( var i = 0; i <= theLinks.length; i++) {
		theLinks[i].href = theLinks[i].href + '#' + ml;
	}
}


function returnHash(myString){
	var mySplitResult = myString.split("#");
	
	document.getElementById('divMenu').style.marginLeft = mySplitResult[1] + 'px';
}
