
function ScrollSection(section,scrollArea,offset){
	
	/*for(var i=0;i<=numMenuItem;i++)
	{
		if(elt=document.getElementById('m-section'+i))
		{
			if(section=='section'+i){elt.className='sel';
		}
		else elt.className='';
		}
	}
	*/
	offset = 'section0';
	theScroll=document.getElementById(scrollArea);
	position=findElementPos(document.getElementById(section));
	if(offset!="")
	{
		offsetPos= findElementPos(document.getElementById(offset));
		position[0]=position[0]-offsetPos[0];
	
	}
	scrollStart(theScroll,theScroll.scrollLeft,position[0],"horiz");
	current=section;
	if (scrollUpdateCount)
	{
		var st=parseInt(current.split('section').join(''))+1;
	for (var i=0; i<=scrollUpdateCount.length; i++)
		{
			if (eltm=document.getElementById(scrollUpdateCount[i])) 
			{
				eltm.innerHTML = st;
			}
		}
	}
}
function scrollNext(scrollArea,offset)
{
	var step=parseInt(current.split('section').join(''));
	step++; 
	if(step>numMenuItem) step=0;
	ScrollSection('section'+step,scrollArea,offset);
}
function scrollPrev(scrollArea,offset)
{
	var step=parseInt(current.split('section').join(''));
	step--;
	if(step<0) step=numMenuItem;
	ScrollSection('section'+step,scrollArea,offset);
}
var scrollanim = {time:0,begin:0,change:0.0,duration:0.0,element:null,timer:null};
function scrollStart(elem,start,end,direction) {
	if(scrollanim.timer!=null)
	{
		clearInterval(scrollanim.timer);scrollanim.timer=null;
	}
	scrollanim.time=0;
	scrollanim.begin=start;
	scrollanim.change=end-start;
	scrollanim.duration=25;
	scrollanim.element=elem;
	if(direction=="horiz")
	{
		scrollanim.timer=setInterval("scrollHorizAnim();",15);
	}
	else{
		scrollanim.timer=setInterval("scrollVertAnim();",15);
	}
}
function scrollVertAnim()
{
	if(scrollanim.time>scrollanim.duration)
	{
		clearInterval(scrollanim.timer);
		scrollanim.timer=null;
	}
	else
	{	
	move=sineInOut(scrollanim.time,scrollanim.begin,scrollanim.change,scrollanim.duration);
	scrollanim.element.scrollTop=move;
	scrollanim.time++;
	}
}
function scrollHorizAnim()
{
	if(scrollanim.time>scrollanim.duration)
	{
		clearInterval(scrollanim.timer);
		scrollanim.timer=null;
	}
	else
	{
		move=sineInOut(scrollanim.time,scrollanim.begin,scrollanim.change,scrollanim.duration);
		scrollanim.element.scrollLeft=move;
		scrollanim.time++;
		}
}
function sineInOut(t,b,c,d)
{
	return-c/2*(Math.cos(Math.PI*t/d)-1)+b;
}
function findElementPos(elemFind)
{if(!elemFind) return false;var elemX=0;var elemY=0;do{elemX+=elemFind.offsetLeft;elemY+=elemFind.offsetTop;}while(elemFind=elemFind.offsetParent)
return Array(elemX,elemY);}

