﻿//================================================
// CN WoW Community Site
// (c)2009 Blizzard Entertainment. Shanghai Easenet. All rights reserved.
//================================================

var dualTalentDisplay = {
	status: {
		isPaused: false,
		current: -1,
		delay: 5000
	},
	start: function() {
		this.triggerHolder = $("dualtalent-intro-dail").addEvents({
			mouseenter: this.triggerAutoShow.bind(this,[true]),
			mouseleave: this.triggerAutoShow.bind(this,[false])
		});
		this.triggers = this.triggerHolder.getElements('a');
		this.contentHolder = $("dualtalent-intro-content").addEvents({
			mouseenter: this.triggerAutoShow.bind(this,[true]),
			mouseleave: this.triggerAutoShow.bind(this,[false])
		});
		this.contents = this.contentHolder.getElements('li');
		this.triggers[0].addClass("current");
		this.contents[0].setStyle("display","");
		this.status.current = 0;
		this.triggers.each(function(trigger,i) {
			trigger.addEvent('click',this.skipTo.bindWithEvent(this,[i]));
		}.bind(this));
		this.autoShow.periodical(this.status.delay,this);
		return this;
	},
	triggerAutoShow: function(isPausing) {
		this.status.isPaused = isPausing;
		return this;
	},
	skipTo: function(e,i) {
		new Event(e).stop();
		this.gotoStep(i);
		return this;
	},
	gotoStep: function(i) {
		this.triggers[this.status.current].removeClass("current");
		this.contents[this.status.current].setStyle("display","none");
		this.status.current = i;
		this.triggers[this.status.current].addClass("current");
		this.contents[this.status.current].setStyle("display","");
		return this;
	},
	autoShow: function() {
		if(!this.status.isPaused) {
			var next = ( this.status.current < this.triggers.length - 1 ) ? this.status.current + 1 : 0;
			this.gotoStep(next);
		}
		return this;
	}
};

var sideMenuControl = {
	start: function(currentSideNav) {
		$("patch313Side").getElements("a")[currentSideNav].addClass("current");
		return this;
	}
};

var page = {
	data: {
		currentSideNav: 0
	},
	start: function() {
		sideMenuControl.start(page.data.currentSideNav);
		if(page.data.currentSideNav == 2) {
			dualTalentDisplay.start();
		}
		return this;
	}
};

window.addEvent('domready',page.start);