// JavaScript Document
function ddlMenu(topMenuItemName,subMenuItemName,topMenuItemNum,subMenuItemNum,menuType){
	this.topMenuItemName="";
	this.subMenuItemName="";
	this.menuType="";
	this.topMenuItemNum=0;
	this.subMenuItemNum=[];
	this.interval=30;
	this.topItem=[];
	this.moveTime=[];
	this.subItem=[[]];
	this.bolDectects=[[]];
	this.mTimes=2;
	this.baseY=10;
	this.subMenuHeight=19;
	this.timer="";
	
	this.topMenuItemName=topMenuItemName;
	this.subMenuItemName=subMenuItemName;
	this.topMenuItemNum=topMenuItemNum;
	this.subMenuItemNum=subMenuItemNum;
	
	if ((menuType!="topMenu")&&(menuType!="bottomMenu")){
		this.menuType="topMenu";
	}else{
		this.menuType=menuType;
	}
	this.bolDectects=new Array(this.topMenuItemNum);
	this.subItem=new Array(this.topMenuItemNum);
	for(var i=0;i<this.topMenuItemNum;i++){
			this.bolDectects[i]=new Array(this.subMenuItemNum[i]+1);
			this.subItem[i]=new Array(this.subMenuItemNum[i]);
			this.topItem[i]=document.getElementById(topMenuItemName+i);
			this.topItem[i].style.zIndex=1000;
			this.topItem[i].style.position="absolute";
			this.moveTime[i]=0;
			this.bolDectects[i][0]=false;
			//addEvent(this.topItem[i], function(){this.bolDectects[i][0]=true}, "mouseover")
			//addEvent(this.topItem[i], function(){alert(i+":"+topMenu.bolDectects[0][0])}, "mouseover")
			//addEvent(this.topItem[i], function(){bolDectects[i][0]=false}, "mouseout")
			
			
			for(var j=0;j<this.subMenuItemNum[i];j++){
				
	
				this.subItem[i][j]=document.getElementById(this.subMenuItemName+i+"_"+j);
				
				
				this.subItem[i][j].style.position="absolute";
				this.bolDectects[i][j+1]=false;
				
				//if(menuType=="topMenu") {
					this.subItem[i][j].style.zIndex=1000-(j+1);
				//}
				//else{
				//	this.subItem[i][j].style.zIndex=1000-(this.subMenuItemNum[i]-j);
				//}
				//addEvent(this.subItem[i][j], function(){this.bolDectects[i][j+1]=true}, "mouseover")
				//addEvent(this.subItem[i][j], function(){this.bolDectects[i][j+1]=false}, "mouseout")
			}
			
			
		}
		
}

ddlMenu.prototype.setBolDectects=function(i,j,bol){
	this.bolDectects[i][j]=bol;
}



ddlMenu.prototype.startMenu=function(obj){
	
	setInterval(function(){playMenu(obj)},obj.interval);
	
}

function playMenu(obj){
	//document.getElementById("printText").innerHTML=obj.bolDectects[0].length;
	

	for (var i=0; i<obj.topMenuItemNum; i++) {
		//alert(this.bolDectects[0].length);
		
		subBtnAnimation(obj,i,findArrayValus(true, obj.bolDectects[i]));
	}
	//setTimeout(function(){playMenu(obj)},obj.interval);
}

function subBtnAnimation(obj,indexItem, isSelect) {
		//trace(indexItem+";"+isSelect);
		
	obj.moveTime[indexItem] = isSelect ? obj.moveTime[indexItem]+1 : obj.moveTime[indexItem]-1;
	obj.moveTime[indexItem] = obj.moveTime[indexItem]<0 ? 0 : obj.moveTime[indexItem];
	obj.moveTime[indexItem] = obj.moveTime[indexItem]>obj.subMenuItemNum[indexItem]*obj.mTimes ? obj.subMenuItemNum[indexItem]*obj.mTimes : obj.moveTime[indexItem] ;
	//trace(_root["top_btn"+indexItem].moveTime+"'"+subItemList[indexItem]*mTimes);
	for (var i=0; i<obj.subMenuItemNum[indexItem]; i++) {
		obj.subItem[indexItem][i].style.left=obj.topItem[indexItem].offsetLeft+"px";
		
		if (obj.moveTime[indexItem]/obj.mTimes<=i) {
			//if(obj.menuType=="topMenu"){
				//obj.subItem[indexItem][i].style.top =(obj.baseY+obj.topItem[indexItem].offsetTop)+"px";
			//}else{
				//obj.subItem[indexItem][i].style.top =(obj.topItem[indexItem].offsetTop)+"px";
			//}
				
				obj.subItem[indexItem][i].style.top ="-1000px";

		} else {
			
			if (obj.moveTime[indexItem]/obj.mTimes>=(i+1)) {
				obj.subItem[indexItem][i].style.top = (obj.menuType=="topMenu"?obj.baseY+(obj.subMenuHeight*(i+1)):obj.topItem[indexItem].offsetTop-(obj.subMenuHeight*(i+1)))+"px";
			} else {
				if(obj.menuType=="topMenu"){
					obj.subItem[indexItem][i].style.top=(obj.baseY+(Math.round(obj.subMenuHeight/obj.mTimes)*obj.moveTime[indexItem]))+"px";
				}else{
					obj.subItem[indexItem][i].style.top=(obj.topItem[indexItem].offsetTop-(Math.round(obj.subMenuHeight/obj.mTimes)*obj.moveTime[indexItem]))+"px";
				}
				//subItem[indexItem][i].offsetTop=this.menuType=="topMenu"?baseY+(Math.round(subMenuHeight/mTimes)*.moveTime[indexItem]):topItem[i].offsetTop-(Math.round(subMenuHeight/mTimes)*.moveTime[indexItem]);		
			}
		}
	}
}
	
function findArrayValus(input, arrayData) {
	
	for (var i=0; i<arrayData.length; i++) {
		if (arrayData[i] == input) {
			
			return true;
		}
	}

	return false;
}



/*
function addEvent(target, functionref, tasktype) {
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false);
	else if (target.attachEvent)
		target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
}

*/
	
	
	

