
//用户变量
var oWhere = document.body;
var OptionText = new Array();
OptionText[0] = "--网站友情链接--";
OptionText[1] = "浙江省国土资源厅";
OptionText[2] = "浙江省测绘学会";
OptionText[3] = "中国测绘新闻网";
OptionText[4] = "浙江省人事考试网";
//OptionText[5] = "浙江华东工程科技发展有限公司";

//下拉菜单主体
//var selectDiv = document.createElement("Table");
var selectDiv=document.getElementById("objSelect");
var selectDivTR = selectDiv.insertRow();
var defaultValueTD = selectDivTR.insertCell();
var arrow = selectDivTR.insertCell();
var strAlreadySelectValue=OptionText[0];
//arrow.width=150;
with(selectDiv)cellSpacing=0,cellPadding=0,border=0,className="selectDiv";
with(defaultValueTD)innerText = OptionText[0],className="defaultSelect";
with(arrow)innerText="",className="arrow";
//oWhere.appendChild(selectDiv);
//外层Div
var optionDiv = document.createElement("div");
//设置下拉菜单选项的坐标和宽度
with(optionDiv.style) {
	var select = selectDiv;
	var xy = getSelectPosition(select);
	pixelLeft = xy[0];
	pixelTop = xy[1]+select.offsetHeight;
	width = selectDiv.offsetWidth;
	optionDiv.className = "optionDiv";
}
//下拉菜单内容
var Options = new Array();
for (var i=0;i<OptionText.length;i++) {
	Options[i] = optionDiv.appendChild(document.createElement("div"));
}
for (i=0;i<Options.length;i++) {
	Options[i].innerText = OptionText[i];
}
oWhere.appendChild(optionDiv);


//禁止选择文本
selectDiv.onselectstart = function() {return false;}
optionDiv.onselectstart = function() {return false;}

arrow.onmousedown = function() {
	this.setCapture();
	this.style.borderStyle="inset";
}
arrow.onmouseup = function() {
	this.style.borderStyle="outset";
	this.releaseCapture();
}
arrow.onclick = function() {
	event.cancelBubble = true;
	optionDiv.style.visibility = optionDiv.style.visibility=="visible"?"hidden":"visible";
}

document.onclick = function() {
    //alert(2);
	optionDiv.style.visibility = "hidden";
}
defaultValueTD.onclick = function() {
	event.cancelBubble = true;
	optionDiv.style.visibility = optionDiv.style.visibility=="visible"?"hidden":"visible";
}
//移动Option时的动态效果
for (i=0;i<Options.length;i++) {
	Options[i].attachEvent("onmouseover",function(){moveWithOptions("highlight","white")});
	Options[i].attachEvent("onmouseout",function(){moveWithOptions("","")});
	Options[i].attachEvent("onmouseup",selectedText);
}

function moveWithOptions(bg,color) {
	with(event.srcElement) {
		style.backgroundColor = bg;
		style.color = color;
	}
}

function selectedText() {
	with(event.srcElement) {
		defaultValueTD.innerText = innerText;
	}
	with(defaultValueTD.style)background="highlight",color="white";
	
	if(defaultValueTD.innerText!=strAlreadySelectValue)
	{
	  strAlreadySelectValue=defaultValueTD.innerText;
	  //重新打开界面

	  if(strAlreadySelectValue=="--网站友情链接--")
	  {
	  }
	  else if(strAlreadySelectValue=="浙江省国土资源厅")
	  {
	    //window.open('http://www.zjdlr.gov.cn','','left=40,top=30,width=800,height=600,resizable=yes,scrollbars=yes');
	  	 window.setTimeout(function(){window.open('http://www.zjdlr.gov.cn','','left=40,top=30,width=800,height=600,resizable=yes,scrollbars=yes')},600);

	  }
	  else if(strAlreadySelectValue=="浙江省测绘学会")
	  {
	    //window.open('http://www.zjch.org.cn','','left=40,top=30,width=800,height=600,resizable=yes,scrollbars=yes');
	    window.setTimeout(function(){window.open('http://www.zjch.org.cn','','left=40,top=30,width=800,height=600,resizable=yes,scrollbars=yes')},600);
	  }
	  else if(strAlreadySelectValue=="中国测绘新闻网")
	  {
	    //window.open('http://www.zgchb.com.cn','','left=40,top=30,width=800,height=600,resizable=yes,scrollbars=yes');
	    window.setTimeout(function(){window.open('http://www.zgchb.com.cn','','left=40,top=30,width=800,height=600,resizable=yes,scrollbars=yes')},600);
	  }
	  else if(strAlreadySelectValue=="浙江省人事考试网")
	  {
	    window.setTimeout(function(){window.open('http://www.zjks.com','','left=40,top=30,width=800,height=600,resizable=yes,scrollbars=yes')},600);
	  }
	  else if(strAlreadySelectValue=="浙江华东工程科技发展有限公司")
	  {
	    //window.open('http://www.zjdlr.gov.cn','','left=40,top=30,width=800,height=600,resizable=yes,scrollbars=yes');
	  }
	  
	}
	
	//alert('change');
	//strAlreadySelectValue
}


//获取对象坐标
function getSelectPosition(obj) {
	var objLeft = obj.offsetLeft;
	var objTop = obj.offsetTop;
	var objParent = obj.offsetParent;
	while (objParent.tagName != "BODY") {
		objLeft += objParent.offsetLeft;
		objTop += objParent.offsetTop;
		objParent = objParent.offsetParent;
	}
	return([objLeft,objTop]);
}


