/******************************************************************
*               Sky361.com Project                                *
* Name:         Niko UI Frontend Frame @JavaScript                *
* Author:       Niko (bluepspower@163.com)                        *
* Version:      v1.1.9                                            *
* Created Date: 2007-03-28                                        *
* Last Modify:  2007-06-03 by Niko                                *
* Copyright:    2007 Sky361.com                                   *
* Attention:    Please do not remove these comments.              *
******************************************************************/

Ext.BLANK_IMAGE_URL = '../img/s.gif';

window.onload = function() {
	/**
	 * Initialize Tabs Panel
	 */
	var tp = new TabsPanel(["div.dvModule6", "div.dvModule7", "div.dvModule8", "div.dvModule3"]);
	tp.initTabs();
};

var TabsPanel = function(aSelectors) {
	this.modules = aSelectors;
};

TabsPanel.prototype = {

	replaceCls : function(el, oldCls, newCls) {
		el = (typeof el == "object") ? el : ((typeof el == "string") ? document.getElementById(el) : null);
		var s = el.className;
		if(s.indexOf(oldCls) > -1) {
			el.className = s.replace(oldCls, newCls);
		}
	},
	
	initTabs : function() {
		for(var i=0, len=this.modules.length; i<len; i++) {
			var oModule = Ext.query(this.modules[i])[0];   // console.log(oModule);
			var aTabs = Ext.query("div.ltTab", oModule);
			var aTables = Ext.query("div.dvData", oModule);
			for(var j=0, l=aTabs.length; j<l; j++) {
				this.onHandler(aTabs, aTables, j);        // Add Event Handler to the current Tab
			}
		}
	},

	onHandler : function(aTabs, aTables, iIndex) {
		var _this = this;
		var oCurrTab = aTabs[iIndex];
		oCurrTab.onmouseover = function() {
			for(var i=0, len=aTabs.length; i<len; i++) {
				var oTab = aTabs[i];
				var oTable = aTables[i];
				var oRtTab = Ext.query("div.rtTab", oTab)[0];        // console.log(oRtTab);
				var oCrTab = Ext.query("input.crTab", oTab)[0];      // console.log(oCrTab);
				if(i == iIndex) {                                    // console.log("current cls: " + oCurrTab.className);
					_this.replaceCls(oCurrTab, "bgTabOut", "bgTabOn");
					_this.replaceCls(oRtTab, "bgTabOut", "bgTabOn");
					_this.replaceCls(oCrTab, "bgTabOut", "bgTabOn");
					_this.replaceCls(oCrTab, "fTabOut", "fTabOn");
					if(oTable) {
						oTable.style.display = '';
					}
				} else {                                             // console.log("other cls: " + aTabs[i].className);
					_this.replaceCls(oTab, "bgTabOn", "bgTabOut");
					_this.replaceCls(oRtTab, "bgTabOn", "bgTabOut");
					_this.replaceCls(oCrTab, "bgTabOn", "bgTabOut");
					_this.replaceCls(oCrTab, "fTabOn", "fTabOut");
					if(oTable) {
						oTable.style.display = "none";
					}
				}
			}
		}
	}
};

var fnAdvOption = function(oCBox) {
	var oEl = Ext.query('div.b1')[0];
	oEl.style.display = oCBox.checked ? 'block' : 'none';
};

var fnInitTree = function() {
	Ext.QuickTips.init();
	var XT = Ext.tree;
	var XNode = XT.TreeNode;
	var oTree = new XT.TreePanel('select_games', {animate : true, rootVisible : false});
	var oRoot = new XNode({text : 'SelectGames'});
	oTree.setRootNode(oRoot);
	var oSub = new XNode({text : 'World of Warcraft (US)', href: '../navigate.do?action=wowus', qtip: 'World of Warcraft (US)'});
	oRoot.appendChild(oSub);
	oSub.appendChild(
		new XNode({text: 'Buy Power Leveling', cls: 'btnList1', href: '../navigate.do?action=powerleveling&gameId=1', qtip: 'WOW (US) Buy Power Leveling'}),
		new XNode({text: 'Buy Gold', cls: 'btnList2', href: '../navigate.do?action=goldlist&gameId=1', qtip: 'WOW (US) Buy Gold'})
	);
	oSub = new XNode({text : 'World of Warcraft (EU)', href: '../navigate.do?action=woweu', qtip: 'World of Warcraft (EU)'});
	oRoot.appendChild(oSub);
	oSub.appendChild(
		new XNode({text: 'Buy Power Leveling', cls: 'btnList1', href: '../navigate.do?action=powerleveling&gameId=2', qtip: 'WOW (EU) Buy Power Leveling'}),
		new XNode({text: 'Buy Gold', cls: 'btnList2', href: '../navigate.do?action=goldlist&gameId=2', qtip: 'WOW (EU) Buy Gold'})
	);
	oTree.render();
	oTree.expandAll();
};