
// ----------------------------------------------------------------------------------------------------
// Dadway
// Motion Controll Class
// ----------------------------------------------------------------------------------------------------

var DadwayMotion = new Class({

	isClassicIE : false,
	isNotPC     : false,

	verticalElements      : null,
	horizontalElements    : null,
	verticalMotionLayer   : null,
	horizontalMotionLayer : null,
	
	verticalElementsBuffer   : null,
	horizontalElementsBuffer : null,
	
	timestamp : 0,
	
	wrapper : null,
	footer  : null,
	
	
	controllers        : Array,
	verticalTimer      : null,
	horizontalTimer    : null,
	verticalInterval   : null,
	horizontalInterval : null,
	
	
	contentWidth    : 0,
	windowWidth     : 0,
	contentHeight   : 0,
	sideSpace       : 0,
	widthDifference : 0,
	
	
	




	// ----------------------------------------------------------------------------------------------------
	// Init - LoadXML

	initialize : function() {
		this.isClassicIE = Boolean(Browser.ie && Browser.version <= 8);
		this.isNotPC     = Boolean(Browser.Platform.mac || Browser.Platform.linux || Browser.Platform.win);
		
		this.createTimestamp();
		
		
		var self = this;
		var req = new Request({
			url : "/data/motion.xml?d=" + this.timestamp,
			method : "get",
			onSuccess: function(text, xml){
				self.onLoadXML(xml);
    		}
		});
		
		req.send();
	},



	// ----------------------------------------------------------------------------------------------------

	onLoadXML : function(xml) {
		var vNodes;
		var hNodes;
		
		try {
			vNodes = xml.getElementsByTagName("vertical")[0].getElementsByTagName("img");
		}
		catch(e){}
		
		try {
			hNodes = xml.getElementsByTagName("horizontal")[0].getElementsByTagName("img");
		}
		catch(e){}
		
		
		this.verticalElements   = new Array();
		this.horizontalElements = new Array();
		
		
		var i, len, node, prop;
		
		if(vNodes) {
			len = vNodes.length;
			for(i=0; i<len; i++) {
				node = vNodes[i];
				prop = { image:node.getAttribute("folder"), total:node.getAttribute("frame"), voice:node.getAttribute("voice") };
				this.verticalElements.push(prop);
			}
		}
		
		if(hNodes) {
			len = hNodes.length;
			for(i=0; i<len; i++) {
				node = hNodes[i];
				prop = { image:node.getAttribute("folder"), total:node.getAttribute("frame"), voice:node.getAttribute("voice") };
				this.horizontalElements.push(prop);
			}
		}
		
		
		this.verticalElementsBuffer   = this.verticalElements.concat();
		this.horizontalElementsBuffer = this.horizontalElements.concat();
		
		if(this.verticalElements.length || this.horizontalElements.length) {
			this.start();
		}
	},






	// ----------------------------------------------------------------------------------------------------
	// Start
	
	start: function() {
		this.wrapper = $$("#wrap div")[0];
		this.footer  = $("foot");
		
		
		this.controllers = new Array();
		this.verticalInterval   = 1000;
		this.horizontalInterval = 800;
		
		
		this.createWrapper();
		this.createMotion();
		this.setWindowListener();
		
		this.fixBgColor();
	},
	
	
	
	
	createWrapper : function() {
		this.verticalMotionLayer = new Element("div");
		this.verticalMotionLayer.id = "vertical-motion-wrap";
		this.wrapper.adopt(this.verticalMotionLayer);
		
		this.horizontalMotionLayer = new Element("div");
		this.horizontalMotionLayer.id = "horizontal-motion-wrap";
		this.footer.adopt(this.horizontalMotionLayer);
	},
	
	
	
	createMotion : function() {
		this.calcWindowSize();
		this.alignElements();
		
		if(document.body.id == "index") {
			this.initVerticalElements();
		}
		
		this.initHorizontalElements();
	},
	
	
	
	setWindowListener : function() {
		var self = this;
		window.addEvent("resize", function(){
			self.calcWindowSize();
			self.alignElements();
			self.reAssignMotion();
		});
	},
	


	adjust : function() {
		this.calcWindowSize();
		this.alignElements();
		this.reAssignMotion();
	},
	
	
	
	fixBgColor : function() {
		var html = document.getElementsByTagName("html")[0];
		if(html) {
			html.style.background = "#00966a";
		}
	},
	



	
	
	// ----------------------------------------------------------------------------------------------------
	// Vertical
	
	initVerticalElements : function() {
		var self = this;
		this.verticalTimer = setTimeout(function(){
			var d = Math.max(2000, self.contentHeight * 2);
			self.verticalInterval = self.getRandomInt(d) + d;
			self.varticalElementCallback();
			self.initVerticalElements();
		},
		this.verticalInterval);
	},
	
	varticalElementCallback: function() {
		var limit = 8;
		//var limit = Math.floor(this.windowWidth / 100);
		//limit = this.flatten(limit, 2, 8);
		
		if(this.isNotPC) {
			limit = 4;
		}
		
		if(this.checkMotionLife("vertical") < limit) {
			var prop = this.getRandomMotionItem("vertical");
			var position = this.getRandomPosition("vertical", limit);
			this.createMotionElement("vertical", prop, position);
		}
	},
	
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// Horizontal
	
	initHorizontalElements : function() {
		var self = this;
		this.horizontalTimer = setTimeout(function(){
			var d = Math.max(6000, self.windowWidth * 6);
			self.horizontalInterval = self.getRandomInt(d) + d;
			self.horizontalElementCallback();
			self.initHorizontalElements();
		},
		this.horizontalInterval);
	},
	
	horizontalElementCallback: function() {
		//var limit = 8;
		var limit = Math.floor(this.windowWidth / 150);
		limit = this.flatten(limit, 4, 16);
		
		if(this.isNotPC) {
			limit = 6;
		}
		
		if(this.checkMotionLife("horizontal") < limit) {
			var prop = this.getRandomMotionItem("horizontal");
			//var position = this.getRandomPosition("horizontal", limit);
			var position = "right";
			this.createMotionElement("horizontal", prop, position);
		}
	},
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------

	getRandomMotionItem : function(mode) {
		var buffer;
			
		if(mode == "vertical") {
			if(!this.verticalElementsBuffer.length) {
				this.verticalElementsBuffer = this.verticalElements.concat();
			}
			buffer = this.verticalElementsBuffer;
		}
		else if(mode == "horizontal") {
			if(!this.horizontalElementsBuffer.length) {
				this.horizontalElementsBuffer = this.horizontalElements.concat();
			}
			buffer = this.horizontalElementsBuffer;
		}
		
		
		
		var key = this.getRandomInt(buffer.length);
		var prop = buffer[key];
		
		buffer.splice(key, 1);
		
		return prop;
	},
	
	
	
	
	
	
	
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// MotionElement
	
	createMotionElement : function(mode, prop, position) {
		var self = this;
		var ctrl = new this.Controller();
		
		this.calcWindowSize();
		this.alignElements();
		
		var dir      = prop.image;
		var total    = Number(prop.total);
		var hasVoice = Boolean(prop.voice != "no");
		var count    = 0;
		
		
		ctrl.mode      = mode;
		ctrl.position  = position;
		ctrl.frame     = 1;
		ctrl.total     = total;
		ctrl.voiceMode = prop.voice;
		
		ctrl.elem = new Element("div");
		ctrl.elem.className = "motion-pict";
		
		
		if(hasVoice) {
			total++;
		}
		
		for(var i=0; i<total; i++) {
			var isVoice = Boolean(hasVoice && i === total - 1);
			var filename = isVoice ? "voice" : (i + 1).toString();
			var src = "/asset/motion/" + dir + "/" + filename + ".png?d=" + this.timestamp;
			var func = callback;
			
			var loader = new this.imageLoader(src, func);
			
			if(isVoice) {
				ctrl.setVoice(loader.elem);
			}
			
			loader.elem.style.display = "none";
			ctrl.elem.adopt(loader.elem);
		}
		
		
		function callback() {
			count++;
			if(count === total) {
				if(mode == "vertical") {
					self.setupVerticalElement(ctrl);
				}
				else if(mode == "horizontal") {
					self.setupHorizontalElement(ctrl);
				}
				
				if(hasVoice) {
					ctrl.setMouseEvents();
				}
			}
		}
	},
	
	
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// SetUp
	
	setupVerticalElement: function(ctrl) {
		var self = this;
		
		this.setFirstImage(ctrl);
		
		var elem = ctrl.elem;
		this.verticalMotionLayer.adopt(elem);
		
		
		elem.style.top = -(ctrl.height + 50) + "px";
		
		if(ctrl.position == "left") {
			ctrl.offset = this.getRandomInt(this.sideSpace - ctrl.width) + ctrl.width;
			elem.style.left = (this.sideSpace - ctrl.offset) + "px";
		}
		else if(ctrl.position == "right") {
			ctrl.offset = this.getRandomInt(this.sideSpace - ctrl.width);
			elem.style.left = (this.contentWidth + this.sideSpace + ctrl.offset) + "px";
		}
		
		
		
		ctrl.ratio = this.getRandomInt(10);
		
		ctrl.go = function(){
			self.fallDown(ctrl);
		}
		
		ctrl.animate();
		ctrl.go();
		
		this.controllers.push(ctrl);
	},
	
	
	
	
	setupHorizontalElement: function(ctrl) {
		var self = this;
		
		this.setFirstImage(ctrl);
		
		var elem = ctrl.elem;
		this.horizontalMotionLayer.adopt(elem);
		
		
		//elem.style.bottom = (this.getRandomInt(20) + ctrl.height) + "px";
		elem.style.bottom = ctrl.height + "px";
		
		if(ctrl.position == "left") {
			elem.style.left  = -(ctrl.width + 50) + "px";
		}
		else if(ctrl.position == "right") {
			elem.style.left  = (this.windowWidth + 50) + "px";
		}


		ctrl.ratio = this.getRandomInt(20) + 20;
		
		ctrl.go = function(){
			self.walk(ctrl);
		}
		
		ctrl.animate();
		ctrl.go();
		
		this.controllers.push(ctrl);
	},
	
	
	
	
	setFirstImage : function(ctrl) {
		var firstElem = ctrl.elem.getElementsByTagName("span")[0];
		var firstImg = ctrl.elem.getElementsByTagName("img")[0];
		
		firstElem.style.display = "block";
		
		ctrl.width  = firstImg.width;
		ctrl.height = firstImg.height;
	},
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// FallDown
	
	fallDown : function(ctrl) {
		var self = this;
		var currentPosition = ctrl.elem.getPosition().y;
		var goal = Math.max(400, this.contentHeight);
		
		if(currentPosition > goal) {
			this.onFallDown(ctrl);
			return;
		}
		
		if(ctrl.fx) {
			ctrl.fx.cancel();
		}
		
		var d = 4000;
		var t = currentPosition + 100 * (this.getRandomInt(3) + 1);
		ctrl.fx = new Fx.Morph(ctrl.elem, {duration: d, transition: Fx.Transitions.Back.easeOut, onComplete:function(){ self.fallDown(ctrl); } });
		ctrl.fx.start({
			"top" : t
		});
	},
	
	
	onFallDown : function(ctrl) {
		this.clearMotion(ctrl);
	},
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// Walk
	
	walk : function(ctrl) {
		var self = this;
		var currentPosition = ctrl.elem.getPosition().x;
		
		var goal;
		var baseWidth = Math.max(960, this.windowWidth);
		
		if(ctrl.position == "left") {
			if(currentPosition > baseWidth) {
				this.onWalk(ctrl);
				return;
			}
			goal = baseWidth;
		}
		else if(ctrl.position == "right") {
			if(currentPosition < -(ctrl.width)) {
				this.onWalk(ctrl);
				return;
			}
			goal = -(ctrl.width);
		}
		
		
		if(ctrl.fx) {
			ctrl.fx.cancel();
		}
		if(ctrl.delay) {
			clearInterval(ctrl.delay);
		}
		
		//var d = Math.abs(goal - currentPosition) * ctrl.ratio;
		var d = 3000;
		var t = currentPosition - 50 * (this.getRandomInt(5) + 1);
		var wait = this.getRandomInt(2000) + 1000;
		ctrl.fx = new Fx.Morph(ctrl.elem, {duration: d, transition: Fx.Transitions.Sine.easeOut, onComplete:function(){ self.walk(ctrl); } });
		ctrl.delay = ctrl.fx.start.delay(wait, ctrl.fx, {
			"left" : t
		});

	},
	
	
	onWalk : function(ctrl) {
		this.clearMotion(ctrl);
	},
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// Clear
	
	clearMotion : function(ctrl) {
		if(ctrl) {
			ctrl.clear();
			this.controllers.erase(ctrl);
		}
	},
	
	clearAllMotion : function() {
		clearTimeout(this.verticalTimer);
		clearTimeout(this.horizontalTimer);
		
		var len = this.controllers.length;
		for(var i=len - 1; i>=0; i--) {
			var ctrl = this.controllers[i];
			this.clearMotion(ctrl);
		}
	},
	
	
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// Pause & Resume
	
	pauseAllMotion : function() {
		clearTimeout(this.verticalTimer);
		clearTimeout(this.horizontalTimer);
		
		var len = this.controllers.length;
		for(var i=0; i<len; i++) {
			var ctrl = this.controllers[i];
			ctrl.pause();
		}
	},
	
	
	
	resumeAllMotion : function() {
		this.initVerticalElements();
		this.initHorizontalElements();
		
		var len = this.controllers.length;
		for(var i=0; i<len; i++) {
			var ctrl = this.controllers[i];
			ctrl.resume();
		}
	},
	
	
	
	
	reAssignMotion : function() {
		var len = this.controllers.length;
		for(var i=0; i<len; i++) {
			var ctrl = this.controllers[i];
			if(ctrl) {
				ctrl.reAssign();
			}
		}
	},
	
	
	
	
	
	
	
	
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// Checker
	
	checkMotionLife : function(mode) {
		var count = 0;
		var len = this.controllers.length;
		for(var i=0; i<len; i++) {
			var ctrl = this.controllers[i];
			if(ctrl.mode && ctrl.mode == mode) {
				count++;
			}
		}
		
		return count;
	},
	
	
	
	
	getRandomPosition : function(mode, num) {
		var leftCount  = 0;
		var rightCount = 0;
		var limit = Math.floor(num / 2);
		
		var len = this.controllers.length;
		for(var i=0; i<len; i++) {
			var ctrl = this.controllers[i];
			if(ctrl.mode && ctrl.mode == mode) {
				if(ctrl.position == "left") {
					leftCount++;
				}
				else if(ctrl.position == "right") {
					rightCount++;
				}
			}
		}
		
		
		var position;
		
		if(leftCount >= limit) {
			position = "right";
		}
		else if(rightCount >= limit) {
			position = "left";
		}
		else {
			var int = this.getRandomInt(2);
			position = ["left", "right"][int];
		}
		
		return position;
	},
	
	
	
	
	
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// Aligner
	
	alignElements : function() {
		this.verticalMotionLayer.style.height = this.contentHeight + "px";
		
		var len = this.controllers.length;
		for(var i=0; i<len; i++) {
			var ctrl = this.controllers[i];
			var elem     = ctrl.elem;
			var mode     = ctrl.mode;
			var position = ctrl.position;
			var offset   = ctrl.offset;
			
			if(mode == "vertical") {
				if(position == "left") {
					elem.style.left = (this.sideSpace - offset) + "px";
				}
				else if(position == "right") {
					elem.style.left = (this.contentWidth + this.sideSpace + offset) + "px";
				}
			}
			
			/*
			else if(mode == "horizontal") {
				elem.style.left = (elem.getPosition().x + this.widthDifference) + "px";
			}
			*/
		}
	},
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// Destroy
	
	destroy : function() {
		this.clearAllMotion();
	},
	
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	// Functions
	
	calcWindowSize : function() {
		if(this.windowWidth) {
			this.widthDifference = Math.floor((this.windowWidth - this.wrapper.getSize().x) / 2);
		}
		
		this.windowWidth   = this.wrapper.getSize().x;
		this.contentWidth  = $("content").getSize().x;
		this.contentHeight = this.wrapper.getSize().y;
		this.sideSpace     = Math.floor((this.windowWidth - this.contentWidth) / 2);
	},
	
	
	getRandomInt : function(num) {
		var rnd = Math.floor( Math.random() * num );
		return rnd;
	},
	
	
	flatten : function(_base, _min, _max) {
		var num = _base;
		if(num < _min) {
			num = _min;
		}
		else if(num > _max) {
			num = _max;
		}
		return num;
	},
	
	
	
	
	
	
	createTimestamp : function() {
		var date = new Date();
		var y = date.getFullYear().toString();
		var m = (date.getMonth() + 1).toString();
		var d = date.getDate().toString();
		var h = date.getHours().toString();
		
		if(m.length < 2) {
			m = "0" + m;
		}
		
		if(d.length < 2) {
			d = "0" + d;
		}
		
		if(h.length < 2) {
			h = "0" + h;
		}
		
		this.timestamp = y + m + d + h;
	},
	
	
	
	
	


	
	
	
	
	
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	//
	// Sub Class
	// Controller
	//
	// ----------------------------------------------------------------------------------------------------

	imageLoader : new Class({
		
		elem : null,
		img  : null,
		
		initialize : function(src, callback) {
			var self = this;
			
			this.elem = new Element("span");
			
			this.img = new Image();
			this.img.src = src;
			
			this.elem.adopt(this.img);
			
			this.img.onload = function() {
				if(this.className.match("loaded")) {
					return;
				}
				this.className += (this.className ? " " : "") + "loaded";
				
				if(Browser.ie6) {
					self.fixIE6();
				}
				
				callback();
			}
			
			if(this.img.complete) {
				this.img.onload();
			}
		},
		
		
		fixIE6 : function() {
			this.img.style.display = "none";
			this.elem.style.width   = this.img.width  + "px";
			this.elem.style.height  = this.img.height + "px";
			this.elem.style.display = "none";
			this.elem.style.filter  = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + this.img.src + ")";
		}
	}),
	
	
	
	
	// ----------------------------------------------------------------------------------------------------
	//
	// Sub Class
	// Controller
	//
	// ----------------------------------------------------------------------------------------------------
	
	Controller : new Class({
		mode        : "",
		position    : "",
		offset      : 0,
		elem        : null,
		voice       : null,
		voiceFx     : null,
		voiceWidth  : 0,
		voiceHeight : 0,
		voiceState  : "",
		voiceMode   : false,
		width       : 0,
		height      : 0,
		frame       : 1,
		total       : 1,
		ratio       : 100,
		timer       : null,
		delay       : null,
		fx          : null,
		go          : function(){},
		
		
		
		
		animate : function() {
			var self = this;
			this.timer = setInterval(function(){ self.nextFrame(); }, 500);
		},
		
		
		pause : function() {
			if(this.fx) {
				this.fx.pause();
			}
			if(this.timer) {
				clearInterval(this.timer);
			}
		},
		
		
		resume : function() {
			if(this.fx) {
				this.fx.resume();
			}
			this.animate();
		},
		
		
		reAssign : function() {
			if(this.fx) {
				this.fx.cancel();
			}
			if(this.delay) {
				clearInterval(this.delay);
			}
			this.go();
		},
		
		
		clear : function() {
			if(this.timer) {
				clearInterval(this.timer);
			}
			if(this.fx) {
				this.fx.cancel();
			}
			if(this.delay) {
				clearInterval(this.delay);
			}
			
			if(this.elem.parentNode) {
				var i, len;
				var childNodes = this.elem.childNodes;
				len = childNodes.length;
				for(i=len - 1; i>0; i--) {
					var c   = childNodes[i];
					var img = c.getElementsByTagName("img")[0];
					
					try {
						c.removeChild(img);
						this.elem.removeChild(c);
					}
					catch(e){}
				}
				this.elem.parentNode.removeChild(this.elem);
			}
		},
		
		
		
		nextFrame : function() {
			var imgs    = this.elem.getElementsByTagName("span");
			var current = this.frame;
			var total   = this.total;
			var next;
			var i, len;
			
			if(current + 1 <= total) {
				next = current + 1;
			}
			else {
				next = 1;
			}
			
			len = imgs.length;
			for(i=0; i<len; i++) {
				var img = imgs[i];
				if(img === this.voice) {
					continue;
				}
				
				if(i+1 === next) {
					img.style.display = "block";
				}
				else {
					img.style.display = "none";
				}
			}
			
			this.frame = next;
		},
		
		
		
		
		
		setVoice : function(_img) {
			this.voice = _img;
			
			if(this.voiceMode == "up") {
				this.voice.style.left = "0";
			}
			else if(this.voiceMode == "side") {
				this.voice.style.top = "0";
			}
			
			this.elem.style.cursor = "pointer";
		},
		
		
		setMouseEvents : function() {
			var self = this;
			this.elem.onmousedown = function() {
				var _voice = self.voice;
				if(self.voiceState == "show") {
					self.hideVoice();
				}
				else {
					self.showVoice();
				}
				
				//return false;
			}
		},
		
		showVoice : function() {
			if(this.voiceFx) {
				this.voiceFx.cancel();
			}
			
			this.voiceState = "show";
			
			var opt = new Object();
			var goal;
			
			if(this.voiceMode == "up") {
				goal = - this.getVoiceHeight();
				goal += this.height;
				opt["top"] = goal;
				this.voice.style.top  = (goal + 20) + "px";
			}
			else if(this.voiceMode == "side") {
				goal = 0;
				opt["left"] = goal;
				this.voice.style.left  = (goal - 20) + "px";
			}
			
			
			if(! $dadway.motion.isClassicIE ) {
				$(this.voice).set("opacity", 0);
				opt["opacity"] = 1;
			}
			
			this.voice.style.display = "block";
			this.voiceFx = new Fx.Morph(this.voice, {duration:150, transition:Fx.Transitions.Back.easeOut});
			this.voiceFx.start(opt);
		},
		
		
		hideVoice : function() {
			if(this.voiceFx) {
				this.voiceFx.cancel();
			}
			
			this.voiceState = "hide";
			
			var v = this.voice;
			var opt = new Object();
			var goal;
			
			if(this.voiceMode == "up") {
				goal = 20 - this.getVoiceHeight();
				goal += this.height;
				opt["top"] = goal;
			}
			else if(this.voiceMode == "side") {
				goal = - 20;
				opt["left"] = goal;
			}
			
			if(! $dadway.motion.isClassicIE ) {
				opt["opacity"] = 0;
			}
			
			this.voiceFx = new Fx.Morph(this.voice, {duration:100, transition:Fx.Transitions.Sine.easeOut, onComplete:function(){ v.style.display = "none"; } });
			this.voiceFx.start(opt);
		},
		
		
		
		getVoiceWidth : function() {
			if(!this.voiceWidth) {
				this.voiceWidth = this.voice.getElementsByTagName("img")[0].width;
			}
			return this.voiceWidth;
		},
		
		getVoiceHeight : function() {
			if(!this.voiceHeight) {
				this.voiceHeight = this.voice.getElementsByTagName("img")[0].height;
			}
			return this.voiceHeight;
		}
	})
	
	
});








// ----------------------------------------------------------------------------------------------------
// Dadway
// Util Class
// ----------------------------------------------------------------------------------------------------

var Common = new Class({
	
	host : "",
	href : "",
	path : "",
	
	
	initialize : function() {
		this.host = location.host;
		this.href = location.href;
		this.path = this.href.split(this.host)[1]
		
		this.initNav();
		this.initSidemenu();
		this.adjustPageJumpButtons();
	},
	
	initNav : function() {
		var nav = $("nav");
		if(!nav) {
			return;
		}
		
		var self = this;
		var nodes = nav.getElementsByTagName("a");
		var i, len;
		len = nodes.length;
		for(i=0; i<len; i++) {
			var ctrl = new Object();
			var node = nodes[i];
			ctrl.node = node;
			
			var ref = node.getAttribute("href", 2);
			if(this.path.match(ref)) {
				node.className = "active";
			}
			else {
				node.onmouseover = createFunc(ctrl, "over");
				node.onmouseout  = createFunc(ctrl, "out");
			}
		}
		
		function createFunc(c, m) {
			var f = function() { self.swapNav(c, m); }
			return f;
		}
	},
	
	swapNav : function(ctrl, mode) {
		var goalY;
		if(mode == "over") {
			goalY = 0;
		}
		else {
			goalY = -54;
		}
		
		if(ctrl.fx) {
			ctrl.fx.cancel();
		}
		if(ctrl.delay) {
			clearInterval(ctrl.delay);
		}
		
		ctrl.fx = new Fx.Morph(ctrl.node, {duration:200, transition:Fx.Transitions.Sine.easeOut});
		ctrl.fx.start({ "top" : goalY });
	},
	
	
	
	
	
	
	initSidemenu : function() {
		var sidemenu = $("side-menu");
		if(!sidemenu) {
			return;
		}
		
		var nodes = sidemenu.getElementsByTagName("li");
		var len = nodes.length;
		for(var i=0; i<len; i++) {
			var node = nodes[i];
			var a = node.getElementsByTagName("a")[0];
			var ref = a.getAttribute("href", 2);
			if(this.path.match(ref)) {
				node.className = "active";
				break;
			}
		}
	},
	
	adjustPageJumpButtons : function() {
		var nodes = $$(".return-pagetop");
		var node = nodes[nodes.length - 1];
		if(node) {
			$(node).addClass("return-pagetop-bottom");
		}
	}
	
	
});













var $dadway = new Object();

window.addEvent("domready", function(){

	$dadway.motion = new DadwayMotion();
	$dadway.common = new Common();
	
	new Fx.SmoothScroll({
		links: ".return-pagetop a, .inner-nav a, .inner-link",
		duration: 500,
		wheelStops: true
	});
});

window.addEvent("unload", function(){
	$dadway.motion.destroy();
});




