﻿var topMenu = Class.create();
Object.extend(topMenu.prototype, {initialize:function (typeclass) {
	//全局对象
	this.obj = $("topic_mainmenu_class");
	//得出对象宽和高
	this.endWidth = this.obj.offsetWidth;
	this.endHeight = this.obj.offsetHeight;
	//宽和高的系数
	this.coefficient = Math.floor(this.endWidth/this.endHeight*100);
	this.coefficientvalue = 10;
	//设置对象隐藏
	this.obj.style.height = "0px";
	this.obj.style.width = "0px";
	this.obj.style.visibility = "hidden";
	//大类时间系数
	this.timeCategoryID = null;
	//子类时间系数
	this.timesubcategoryID = null;
	//类别id
	this.selectedID = $(typeclass);
	//设参数类别为选中状态
	this.selected();
	//循环给按钮添加事件
	for (var i = 0; i<7; i++) {
		addEvent($("0"+i.toString()), "mouseover", this.hover.bind(this), false);
		addEvent($("0"+i.toString()), "mouseout", this.link.bind(this), false);
	}
	//鼠标离开对象触发的时间
	addEvent(this.obj, "mouseover", this.btnShow.bind(this), false);
	addEvent(this.obj, "mouseout", this.btnHide.bind(this), false);
	//射初始状态
	var loc = MS.Position.getBounds($("01"));
	//初始化坐标
	this.starLeft = loc.left+Math.round(loc.width/2);
	this.starTop = loc.top+loc.height;
}, show:function () {
	if (this.toNum(this.obj.style.width)<=this.endWidth-this.coefficient*this.coefficientvalue/100) {
		this.obj.style.width = this.toNum(this.obj.style.width)+this.coefficient*this.coefficientvalue/100+"px";
		this.obj.style.height = this.toNum(this.obj.style.height)+10+"px";
		this.obj.style.left = this.starLeft-this.toNum(this.obj.style.width)/2+"px";
		this.timesubcategoryID = window.setTimeout(this.show.bind(this), 5);
	} else {
		this.obj.style.width = this.endWidth+"px";
		this.obj.style.height = this.endHeight+"px";
		this.obj.style.left = this.starLeft-this.endWidth/2+"px";
		window.clearTimeout(this.timesubcategoryID);
		this.selectedout();
	}
}, hide:function () {
	if (this.toNum(this.obj.style.height)>10 && this.toNum(this.obj.style.width)>this.endWidth/this.endHeight*10) {
		this.obj.style.width = this.toNum(this.obj.style.width)-this.endWidth/this.endHeight*10+"px";
		this.obj.style.height = this.toNum(this.obj.style.height)-10+"px";
		this.obj.style.left = this.starLeft-this.toNum(this.obj.style.width)/2+"px";
		this.timesubcategoryID = window.setTimeout(this.hide.bind(this), 10);
	} else {
		this.obj.style.width = "0px";
		this.obj.style.height = "0px";
		this.obj.style.left = this.starLeft+"px";
		window.clearTimeout(this.timesubcategoryID);
		$("01").src = $("01").src.replace("hover", "link");
		this.selected();
	}
}, link:function (e) {
	var target = e.srcElement || e.target;
	if (target.id == "01") {
		this.cleartimeout(this.timeCategoryID);
		this.timeCategoryID = window.setTimeout(this.hide.bind(this), 2000);
	} else {
		target.src = target.src.replace("hover", "link");
	}
}, hover:function (e) {
	var target = e.srcElement || e.target;
	if (target.id == "01") {
		var rect = MS.Position.getBounds($("01"));
		this.starLeft = rect.left+Math.round(rect.width/2);
		this.obj.style.height = "0px";
		this.obj.style.width = "0px";
		this.obj.style.top = this.starTop+"px";
		this.obj.style.left = this.starLeft+"px";
		this.cleartimeout(this.timeCategoryID);
		this.timeCategoryID = window.setTimeout(this.show.bind(this), 500);
		this.obj.style.visibility = "visible";
	}
	target.src = target.src.replace("link", "hover");
}, selected:function () {
	this.selectedID.src = this.selectedID.src.replace("link", "visited");
}, selectedout:function () {
	this.selectedID.src = this.selectedID.src.replace("visited", "link");
}, btnShow:function () {
	this.cleartimeout(this.timeCategoryID);
}, btnHide:function () {
	this.cleartimeout(this.timeCategoryID);
	this.timeCategoryID = window.setTimeout(this.hide.bind(this), 200);
}, cleartimeout:function (timeid) {
	if (timeid) {
		window.clearTimeout(timeid);
	}
}, toNum:function (Height) {
	if (Height) {
		return parseInt(Height.replace("px", ""), "10");
	} else {
		return 0;
	}
}}, false);

