/* 下拉菜单 */
function dropDownMenu(){
	var circleInputArray = YAHOO.util.Dom.getElementsByClassName("circleInput", "div");
	function setZ2ci(){
		var zi = 9999;
		for(var cii in circleInputArray){
			circleInputArray[cii].style.zIndex = zi--;
		}
	}
	setZ2ci();
	
	function getStyle(ele, style) {
		if (typeof ele == "string") ele = document.getElementById(ele);   
		if (ele.currentStyle) { // IE
			return ele.currentStyle[style];
		} else { // DOM compatible browsers
			return document.defaultView.getComputedStyle(ele, null)[style];
		}
	}
	/* 下拉菜单通用处理函数 */
	function selClickHandle($this){
		var $ciList = YAHOO.util.Dom.getElementsByClassName("ciList", "div", $this);
		for(var cii in circleInputArray){
			var ciList = YAHOO.util.Dom.getElementsByClassName("ciList", "div", circleInputArray[cii]);
			if(YAHOO.util.Dom.getStyle(ciList, "display") != "none" ){
				YAHOO.util.Dom.setStyle(ciList, "display" , "none");
				var ciListArrow = YAHOO.util.Dom.getElementsByClassName("icon_arrow", "div", circleInputArray[cii]);
				YAHOO.util.Dom.removeClass(ciListArrow, "arrow_up");
			}
		}		
		
		var ciCss = function(element, prop){return element.currentStyle || document.defaultView.getComputedStyle(element, null);}; 
		if( YAHOO.util.Dom.getStyle($ciList, "display") == "none" ){
			if( YAHOO.util.Dom.getFirstChild($ciList[0]).className.indexOf("chooseFriend") == -1 ){ //对于class="chooseFriend"的宽度不添加自动收缩扩展
				var ciListWidth = getStyle($ciList[0].parentNode , "width"); // IE兼容性
				if(ciListWidth.indexOf("px") != -1 ){
					ciListWidth = parseInt(ciListWidth) + 4 +"px";
				}else{
					ciListWidth = $ciList[0].parentNode.clientWidth - 16 + "px";
				}
				YAHOO.util.Dom.setStyle($ciList, "width" , ciListWidth);
			}

			YAHOO.util.Dom.setStyle($ciList, "display" , "block"); 
		}
	}
	
	YAHOO.util.Event.addListener(circleInputArray , "click" , function(event){
		var ciListArrow = YAHOO.util.Dom.getElementsByClassName("icon_arrow", "div", this);
		selClickHandle( this );
		YAHOO.util.Event.stopPropagation(event);
	});
	
	for(var cii in circleInputArray){
		var hasLi = false;
		var ciListLi
		var ciList;
		var ciDivs = circleInputArray[cii].getElementsByTagName("DIV");
		for(var cidi = 0 ;ciDivs.length > cidi;cidi++){
			if( ciDivs[cidi].className && ciDivs[cidi].className.indexOf("ciList") != -1 ){
				ciList = ciDivs[cidi];
				hasLi = true;
			}
		}
		if(hasLi && YAHOO.util.Dom.getElementsByClassName("chooseFriend", "div", ciList).length == 0){
			ciListLi = ciList.getElementsByTagName("LI");
			YAHOO.util.Event.addListener(ciListLi , "click" , function(event){
				var nowCi = this.parentNode.parentNode.parentNode;
				var ciw = YAHOO.util.Dom.getElementsByClassName("ciWord", "div", nowCi);
				ciw[0].innerHTML = this.innerHTML;
				YAHOO.util.Event.stopPropagation(event);
				selClickHandle( this );
			});
			for(var cill = 0 ;ciListLi.length > cill;cill++){
				ciListLi[cill].onmouseover = function(){
					this.style.color = "#ffffff";
					this.style.backgroundColor = "#EC8B2D";
				};
				ciListLi[cill].onmouseout = function(){
					this.style.color = "#000000";
					this.style.backgroundColor = "#ffffff";
				};
			}
		}
		hasLi = false;
	}
	
	YAHOO.util.Event.addListener(document , "click" , function(event){
		var iconArrow = YAHOO.util.Dom.getElementsByClassName("icon_arrow", "div");
		YAHOO.util.Dom.removeClass(iconArrow , "arrow_up");
		for(cii in circleInputArray){
			var ciList = YAHOO.util.Dom.getElementsByClassName("ciList", "div", circleInputArray[cii]);
			YAHOO.util.Dom.setStyle(ciList , "display" , "none" );

		}
	});
}

dropDownMenu();
