/// ///////////////////////////////////////////////////////////////////////////////////////////////
//	CREATED BY 		:	T Varghese																//
//	CREATED DATE	:	30 Jan, 2009															//			
//	CREATED FOR 	:   Menu Listing 															//					
// ///////////////////////////////////////////////////////////////////////////////////////////////
//#--	aMenuName -> Shoud be in Array
//#--	aOtherAttribute -> Shoud be in Array
//#--	TotalMenuWidth -> Menu Display area width
var aMenuName = new Array();
var aOtherAttribute = new Array();
var TotalWidth,MenuId,MenuCnt,TotalButtonWidth,PadWith,CurrentIndex,Next,MiddleWidth,NextImgWidth,ParentDiv;
function loadmenu(aMenuName,aOtherAttribute,TotalMenuWidth)
{
	var MenuId,MenuDiv,Index;
	MenuDiv = '<div id="left"></div>';
	MenuDiv += '<div id="cartMenuPart1" class="cartMenuPart1">';
	MenuDiv += '<div class="cartMenu1" id="cartMenu1">';
	MenuCnt = aMenuName.length;
	TotalMenuWidth = TotalMenuWidth-2;//SPACES
	for(Index=0;Index<aMenuName.length;Index++)
	{
		MenuId = "menu_"+Index;
		MenuDiv += '<div class="cartMenuItems1" id="'+MenuId+'" '+aOtherAttribute[Index]+'>'+aMenuName[Index]+'</div>';
	}
	MenuDiv += '</div></div><div id="right"></div>';
	document.write(MenuDiv);
	ParentDiv = document.getElementById("cartMenuPart1");
	var ChildDiv  = document.getElementById("cartMenu1");
	
	MiddleWidth = parseInt(ParentDiv.clientWidth);
	
	TotalButtonWidth = 0;
	PadWith		= 3;//style Padding 3 pixels
	NextImgWidth = 16;
	TotalWidth  = TotalMenuWidth+NextImgWidth;
	CurrentIndex = -1;
	for(index=0;index<MenuCnt;index++)
	{
		MenuId = "menu_"+index;
		TotalButtonWidth	+= parseInt(document.getElementById(MenuId).clientWidth);
		TotalButtonWidth	+= PadWith;
	}
	TotalButtonWidth += 1;//adjustment for mac firefox
	ParentDiv.style.width = TotalWidth+"px";
	ChildDiv.style.width = TotalButtonWidth+"px";
	ChildDiv.style.top   = '0px';
	ChildDiv.style.left  = '0px';
	if(TotalButtonWidth>TotalWidth)
	{
		document.getElementById("right").className = 'rightArrow';
		document.getElementById("right").onclick  = function(){menuend(TotalMenuWidth);};

	}
}
function menustart(TotalMenuWidth)
{
	var leftpos, curleft,MovePosition,MenuId;
	leftpos = parseInt(document.getElementById("cartMenu1").style.left);
	if(Next == false)
	CurrentIndex -= 1;
	else
		Next =false;
	MenuId = "menu_"+CurrentIndex;
	MovePosition = parseInt(document.getElementById(MenuId).clientWidth)+PadWith;
	curleft = leftpos+MovePosition;
	if(curleft > 0)
	{
		curleft = 0;
	}
	if(TotalButtonWidth>TotalWidth)
	{
		if(document.getElementById("right").className == "")
			document.getElementById("right").className = 'rightArrow';
		if(document.getElementById("right").onclick == "")
			document.getElementById("right").onclick  = function(){menuend(TotalMenuWidth);};
	}
	if(curleft==0)
	{
		document.getElementById("left").className = "";
		if(TotalWidth != TotalMenuWidth+NextImgWidth)
			TotalWidth = TotalMenuWidth+NextImgWidth;
		ParentDiv.style.width = TotalWidth+"px";
	}
	document.getElementById("cartMenu1").style.left = curleft+"px";
	if(CurrentIndex==0)
		CurrentIndex = -1;
}

function menuend(TotalMenuWidth)
{	
		var leftpos, curleft,MovePosition;
		
		CurrentIndex += 1;
		leftpos = parseInt(document.getElementById("cartMenu1").style.left);
		MenuId = "menu_"+CurrentIndex;
		MovePosition = parseInt(document.getElementById(MenuId).clientWidth)+PadWith;
		var movepx = (leftpos+TotalButtonWidth)-MiddleWidth;
		if(movepx > MovePosition)	
		{
			curleft = leftpos-MovePosition;
			TotalWidth = TotalMenuWidth;//TotalWidth-NextImgWidth;
			ParentDiv.style.width = TotalWidth+"px";
		}
		else
		{
			curleft = leftpos-MovePosition;
			document.getElementById("right").className = "";
		}
		if(curleft!=0)
		{
			
		if(!document.getElementById("left").className)
			document.getElementById("left").className = 'leftArrow';
		if(!document.getElementById("left").onclick)
			document.getElementById("left").onclick  = function(){menustart(TotalMenuWidth);};
		}
		document.getElementById("cartMenu1").style.left = curleft+"px";
		Next = true;
}
