/*****************************************************
 * mySlideOutMenu
 * http://mySlideOutMenus.sourceforge.net/
 * 
 * a nice little script to create exclusive, slide-out
 * menus for ns4, ns6, mozilla, opera, ie4, ie5 on 
 * mac and win32. I've got no linux or unix to test on but 
 * it should(?) work... 
 *
 * Licensed under AFL 2.0
 * http://www.opensource.org/licenses/afl-2.0.php
 *
 * Revised: 
 * - 08/29/2002 : added .hideAll()
 * - 04/15/2004 : added .writeCSS() to support more 
 *                than 30 menus.
 *
 * --youngpup--
 *****************************************************/

mySlideOutMenu.Registry = []
mySlideOutMenu.aniLen = 10
mySlideOutMenu.hideDelay = 500
mySlideOutMenu.minCPUResolution = 80

// constructor
function mySlideOutMenu(id, dir, left, top, width, height)
{
	this.ie  = document.all ? 1 : 0
	this.ns4 = document.layers ? 1 : 0
	this.dom = document.getElementById ? 1 : 0
	this.css = "";

	if (this.ie || this.ns4 || this.dom) {
		this.id			 = id
		this.dir		 = dir
		this.orientation = dir == "left" || dir == "right" ? "h" : "v"
		this.dirType	 = dir == "right" || dir == "down" ? "-" : "+"
		this.dim		 = this.orientation == "h" ? width : height
		this.hideTimer	 = false
		this.aniTimer	 = false
		this.open		 = false
		this.over		 = false
		this.startTime	 = 0

		// global reference to this object
		this.gRef = "mySlideOutMenu_"+id
		eval(this.gRef+"=this")

		// add this menu object to an internal list of all menus
		mySlideOutMenu.Registry[id] = this

		var d = document

		var strCSS = "";
		strCSS += '#' + this.id + 'Container { visibility:hidden; '
		strCSS += 'left:' + left + 'px; '
		strCSS += 'top:' + top + 'px; '
		strCSS += 'width:' + width + 'px; '
		strCSS += 'height:' + height + 'px; '		
		strCSS += 'overflow:hidden; z-index:10000; }'
		strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
		strCSS += '}'

		this.css = strCSS;

		this.load()
	}
}

mySlideOutMenu.writeCSS = function() {
	document.writeln('<style type="text/css">');

	for (var id in mySlideOutMenu.Registry) {
		document.writeln(mySlideOutMenu.Registry[id].css);
	}

	document.writeln('</style>');
}

mySlideOutMenu.prototype.load = function() {
	var d = document
	var lyrId1 = this.id + "Container"
	var lyrId2 = this.id + "Content"
	var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
	if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
	var temp

	if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
	else {
		this.container	= obj1
		this.menu		= obj2
		this.style		= this.ns4 ? this.menu : this.menu.style
		this.homePos	= eval("0" + this.dirType + this.dim)
		this.outPos		= 0
		this.accelConst	= (this.outPos - this.homePos) / mySlideOutMenu.aniLen / mySlideOutMenu.aniLen 

		// set event handlers.
		if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		this.menu.onmouseover = new Function("mySlideOutMenu.showMenu('" + this.id + "')")
		this.menu.onmouseout = new Function("mySlideOutMenu.hideMenu('" + this.id + "')")

		//set initial state
		this.endSlide()
	}
}
	
mySlideOutMenu.showMenu = function(id)
{
	var reg = mySlideOutMenu.Registry
	var obj = mySlideOutMenu.Registry[id]
	
	if (obj.container) {
		obj.over = true

		// close other menus.
		for (menu in reg) if (id != menu) mySlideOutMenu.hide(menu)

		// if this menu is scheduled to close, cancel it.
		if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }

		// if this menu is closed, open it.
		if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
	}
}

mySlideOutMenu.hideMenu = function(id)
{
	// schedules the menu to close after <hideDelay> ms, which
	// gives the user time to cancel the action if they accidentally moused out
	var obj = mySlideOutMenu.Registry[id]
	if (obj.container) {
		if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
		obj.hideTimer = window.setTimeout("mySlideOutMenu.hide('" + id + "')", mySlideOutMenu.hideDelay);
	}
}

mySlideOutMenu.hideAll = function()
{
	var reg = mySlideOutMenu.Registry
	for (menu in reg) {
		mySlideOutMenu.hide(menu);
		if (menu.hideTimer) window.clearTimeout(menu.hideTimer);
	}
}

mySlideOutMenu.hide = function(id)
{
	var obj = mySlideOutMenu.Registry[id]
	obj.over = false

	if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
	
	// flag that this scheduled event has occured.
	obj.hideTimer = 0

	// if this menu is open, close it.
	if (obj.open && !obj.aniTimer) obj.startSlide(false)
}

mySlideOutMenu.prototype.startSlide = function(open) {
	this[open ? "onactivate" : "ondeactivate"]()
	this.open = open
	if (open) this.setVisibility(true)
	this.startTime = (new Date()).getTime()	
	this.aniTimer = window.setInterval(this.gRef + ".slide()", mySlideOutMenu.minCPUResolution)
}

mySlideOutMenu.prototype.slide = function() {
	var elapsed = (new Date()).getTime() - this.startTime
	if (elapsed > mySlideOutMenu.aniLen) this.endSlide()
	else {
		var d = Math.round(Math.pow(mySlideOutMenu.aniLen-elapsed, 2) * this.accelConst)
		if (this.open && this.dirType == "-")		d = -d
		else if (this.open && this.dirType == "+")	d = -d
		else if (!this.open && this.dirType == "-")	d = -this.dim + d
		else										d = this.dim + d

		this.moveTo(d)
	}
}

mySlideOutMenu.prototype.endSlide = function() {
	this.aniTimer = window.clearTimeout(this.aniTimer)
	this.moveTo(this.open ? this.outPos : this.homePos)
	if (!this.open) this.setVisibility(false)
	if ((this.open && !this.over) || (!this.open && this.over)) {
		this.startSlide(this.over)
	}
}

mySlideOutMenu.prototype.setVisibility = function(bShow) { 
	var s = this.ns4 ? this.container : this.container.style
	s.visibility = bShow ? "visible" : "hidden"
}
mySlideOutMenu.prototype.moveTo = function(p) { 
	this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}
mySlideOutMenu.prototype.getPos = function(c) {
	return parseInt(this.style[c])
}

// events
mySlideOutMenu.prototype.onactivate		= function() { }
mySlideOutMenu.prototype.ondeactivate	= function() { }
var $ = function(i){return document.getElementById(i);}
var ua = navigator.userAgent.toLowerCase();
var isIE = (ua.indexOf("msie") > -1),isIE7 = (ua.indexOf("msie 7") > -1),isOpera = (ua.indexOf("opera") > -1),isSafari = (ua.indexOf("webkit") != -1 || ua.indexOf("khtml") != -1),isGecko = (!isSafari && ua.indexOf("gecko") > -1);

/*???8???*/
var sb = 0;
var sba = 0;
var $ = function(i){ return document.getElementById(i); }
function mychg(m){
    if(sba==1) {
	sbb=$("lm"+m).style.display;
	$("lm"+m).style.display=sbb=="none"?"block":"none";
	$("father"+m).className=$("father"+m).className==""?"on":"";
	}
	else {
    if(sb!=0){ 
	$("lm"+sb).style.display="none";
	$("father"+sb).className="";
	}
    if(sb!=m){
        $("lm"+m).style.display="block";
		$("father"+m).className="on";
        sb=m;
    }
    else sb=0;
	}
}

function mychgall(num){
  for(i=1;i<num+1;i++)
  {
  $("lm"+i).style.display=sba==0?"block":"none";
  $("father"+i).className="on";
  }

  sba=!sba;
  sb=0;
}

//output Q&A 
function setWBtxt(wb_m){
if (wb_m==0) return;
var wbt = Array();
var wbl = Array();
for(i=1;i<6;i++){                      //?????i????????????2???????壨??????????????
	wbt[i] = Array();
	wbl[i] = Array();
	}

wbt[1][1] = "PLZ HELP ME!!!";                                     //items????
wbl[1][1] = "http://help.91.com/answer/2009/02/18/1704.shtml";
wbt[1][2] = "Why can't I pick up items??";
wbl[1][2] = "http://help.91.com/answer/2009/02/19/1710.shtml";
wbt[1][3] = "how to trade items with someone?";
wbl[1][3] = "http://help.91.com/answer/2009/02/19/1711.shtml";

wbt[2][1] = "3rd Summon quest";                                   //features????
wbl[2][1] = "http://help.91.com/answer/2009/01/14/1188.shtml";
wbt[2][2] = "Where can i get quest?";
wbl[2][2] = "http://help.91.com/answer/2008/09/23/303.shtml";
wbt[2][3] = "How to quit the Legion?";
wbl[2][3] = "http://help.91.com/answer/2009/02/19/1716.shtml";
wbt[2][4] = "How to get married in game?";
wbl[2][4] = "http://help.91.com/answer/2009/02/19/1717.shtml";
wbt[2][5] = "Why there is no TG room in CT?";
wbl[2][5] = "http://help.91.com/answer/2008/12/10/996.shtml";

wbt[3][1] = "A mage or a warrior";                    //Skill????
wbl[3][1] = "http://help.91.com/answer/2009/05/17/4056.shtml";
wbt[3][2] = "New Mage How to get new skills";
wbl[3][2] = "http://help.91.com/answer/2008/12/02/768.shtml";
wbt[3][3] = "What am I doing wrong?";
wbl[3][3] = "http://help.91.com/answer/2008/12/02/759.shtml";
wbt[3][4] = "How can I level up in game?";
wbl[3][4] = "http://help.91.com/answer/2008/10/07/666.shtml";
wbt[3][5] = "What classes can you play in Crazy Tao?";
wbl[3][5] = "http://help.91.com/answer/";

wbt[4][1] = "How do I make SaintKylin's stars go up?";                    //Pets????
wbl[4][1] = "http://help.91.com/answer/2008/12/02/769.shtml";
wbt[4][2] = "about pet";
wbl[4][2] = "http://help.91.com/answer/2008/12/23/1036.shtml";
wbt[4][3] = "how can you obtain pets?";
wbl[4][3] = "http://help.91.com/answer/2008/12/02/763.shtml";
wbt[4][4] = "Registering Pets";
wbl[4][4] = "http://help.91.com/answer/2008/12/02/760.shtml";
wbt[4][5] = "What pet should i get?";
wbl[4][5] = "http://help.91.com/answer/2008/11/10/753.shtml";

wbt[5][1] = "patch doesnt work";                                              //Others????
wbl[5][1] = "http://help.91.com/answer/2009/07/10/15014.shtml";
wbt[5][2] = "why does this game not work for?";
wbl[5][2] = "http://help.91.com/answer/2009/07/10/15042.shtml";
wbt[5][3] = "DirectX error";
wbl[5][3] = "http://help.91.com/answer/2009/07/23/16196.shtml";

for(k=1;k<wbt[wb_m].length;k++){
	document.writeln("<img src=\"http://images.91.com/ct91e/09edition/infopage/dot1.gif\" /><a href=\""+ wbl[wb_m][k] +"\" target=\"_self\">"+ wbt[wb_m][k] +"<\/a><br \/>");
	}
}  

//Output Screenshots
function setSStxt(wb_m){
  var jsurl = "http://p.images.91.com/album91e_js/special/ct"
  var jstag ="<script language=\"JavaScript\" type=\"text\/javascript\""
  var ss = jstag+" src=\""+jsurl + wb_m +".js"+"\"><\/script>"
  document.writeln(ss);
}


//go to top
/*
Author: mg12
Update: 2008/11/21
Author URI: http://www.neoease.com/
*/
(function() {

function $(id) {
	return document.getElementById(id);
}

function setStyleDisplay(id, status) {
	$(id).style.display = status;
}

function goTop(acceleration, time) {
	acceleration = acceleration || 0.1;
	time = time || 16;

	var dx = 0;
	var dy = 0;
	var bx = 0;
	var by = 0;
	var wx = 0;
	var wy = 0;

	if (document.documentElement) {
		dx = document.documentElement.scrollLeft || 0;
		dy = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		bx = document.body.scrollLeft || 0;
		by = document.body.scrollTop || 0;
	}
	var wx = window.scrollX || 0;
	var wy = window.scrollY || 0;

	var x = Math.max(wx, Math.max(bx, dx));
	var y = Math.max(wy, Math.max(by, dy));

	var speed = 1 + acceleration;
	window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
	if(x > 0 || y > 0) {
		var invokeFunction = "MGJS.goTop(" + acceleration + ", " + time + ")"
		window.setTimeout(invokeFunction, time);
	}
}

function switchTab(showPanels, hidePanels, activeTab, activeClass, fadeTab, fadeClass) {
	$(activeTab).className = activeClass;
	$(fadeTab).className = fadeClass;

	var panel, panelList;
	panelList = showPanels.split(',');
	for (var i = 0; i < panelList.length; i++) {
		var panel = panelList[i];
		if ($(panel)) {
			setStyleDisplay(panel, 'block');
		}
	}
	panelList = hidePanels.split(',');
	for (var i = 0; i < panelList.length; i++) {
		panel = panelList[i];
		if ($(panel)) {
			setStyleDisplay(panel, 'none');
		}
	}
}

window['MGJS'] = {};
window['MGJS']['$'] = $;
window['MGJS']['setStyleDisplay'] = setStyleDisplay;
window['MGJS']['goTop'] = goTop;
window['MGJS']['switchTab'] = switchTab;

})();
