// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
  var tggle='on';


//side nav slide animation
/*  Animation Techniques by Hesido.com; */
if (document.getElementById && document.getElementsByTagName) {
	if (window.addEventListener) window.addEventListener('load', initAnims, false);
	else if (window.attachEvent) window.attachEvent('onload', initAnims);
}

function initAnims() {
	//	Init size animation with memory, both directions
		var animElements = document.getElementById("sidenavslide").getElementsByTagName("a")
		for(var i=0; i<animElements.length; i++) {
			animElements[i].onmouseover = widthChange;
			animElements[i].onmouseout = widthRestore;
		}

		function widthChange() {
			if (!this.currentWidth) this.currentWidth = 21; //if no mem is set, set it first;
			doWidthChangeMem(this,this.currentWidth,80,10,10,0.333);
		}

		function widthRestore() {
			if (!this.currentWidth) return;	//avoid error if mouseout an element occurs before the mosueover
												//(e.g. the pointer already in the object when onload)
			doWidthChangeMem(this,this.currentWidth,21,10,10,0.5);
		}
	
	//	Init motion animation
		var moveIt = document.getElementById('travelGuidePanel');
		if (moveIt != null) moveIt.onmouseover = moveToBottom;
		if (moveIt != null) moveIt.onmouseout = moveToBack;
		
		function moveToBottom() {
			if (!this.currentPos) this.currentPos = [567,74]; //if no mem is set, set it first;
			doPosChangeMem(this,this.currentPos,[699,74],20,20,0.3);
				//move to a random position for demonstration
		}
		function moveToBack() {
			if (!this.currentPos) return;	//avoid error if mouseout an element occurs before the mosueover
												//(e.g. the pointer already in the object when onload)
			doPosChangeMem(this,this.currentPos,[567,74],20,20,0.3);
		}
	
	//	Extend - Init motion animation
		function openExtend() {
			document.getElementById('extendFakeMap').style.display = 'none';
			slideIt = document.getElementById('extend');
			if (slideIt != null) slideit = slideToFull;
		}
		
		function closeExtend() {
			slideIt = document.getElementById('extend');
			if (slideIt != null) slideit = slideToFull;
			document.getElementById('extendFakeMap').style.display = 'block';
		}
	
	
		
		
}


function doWidthChangeMem(elem,startWidth,endWidth,steps,intervals,powr) {
//Width changer with Memory by www.hesido.com
	if (elem.widthChangeMemInt) window.clearInterval(elem.widthChangeMemInt);
	var actStep = 0;
	elem.widthChangeMemInt = window.setInterval(
		function() {
			elem.currentWidth = easeInOut(startWidth,endWidth,steps,actStep,powr);
			elem.style.width = elem.currentWidth+"px";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
		}
		,intervals)

}

function doPosChangeMem(elem,startPos,endPos,steps,intervals,powr) {
//Position changer with Memory by www.hesido.com
	if (elem.posChangeMemInt) window.clearInterval(elem.posChangeMemInt);
	var actStep = 0;
	elem.posChangeMemInt = window.setInterval(
		function() {
			elem.currentPos = [
				easeInOut(startPos[0],endPos[0],steps,actStep,powr),
				easeInOut(startPos[1],endPos[1],steps,actStep,powr)
				];
			elem.style.left = elem.currentPos[0]+"px";
			elem.style.top = elem.currentPos[1]+"px";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.posChangeMemInt);
		}
		,intervals)

}

function doPosChangeMemExtend(elem,startPos,endPos,steps,intervals,powr) {
//Position changer with Memory by www.hesido.com
    //obj=document.getElementById('switch');
	chekr = document.getElementById('extend').style.width;
	
	if (chekr=='657px') {
		endPos = [148,1];
		//nextStep = turnOffArrow();
		//obj.style.display = 'none';
	}
	
	if (elem.posChangeMemInt) window.clearInterval(elem.posChangeMemInt);
	var actStep = 0;
	elem.posChangeMemInt = window.setInterval(
		function() {
			elem.currentPos = [
				easeInOut(startPos[0],endPos[0],steps,actStep,powr),
				easeInOut(startPos[1],endPos[1],steps,actStep,powr)
				];
			elem.style.width = elem.currentPos[0]+"px";
			elem.style.right = elem.currentPos[1]+"px";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.posChangeMemInt);
		}
		,intervals)
	
	//obj.style.display = 'block';

}


function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
//Generic Animation Step Value Generator By www.hesido.com
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}


function turnOnArrow() {
	document.getElementById('extendContainerSwitch').style.display = 'block';
}
function turnOffArrow() {
	document.getElementById('extendContainerSwitch').style.display = 'none';
}


//extend homepage map
		function openExtend() {
			document.getElementById('extendFakeMap').style.display = 'none';
			var slideIt = document.getElementById('extend');
			slideToFull(slideIt);
			document.getElementById('extendContainerSwitch').style.display = 'block';
		}
		
		function closeExtend() {
			var slideIt = document.getElementById('extend');
			slideToFull(slideIt);
			document.getElementById('extendContainerSwitch').style.display = 'none';

			function timedSlide() {
				var t=setTimeout("document.getElementById('extendFakeMap').style.display = 'block';",305);
			}
			timedSlide();
		}
		
		function slideToFull(dude) {
			if (!dude.currentPos) dude.currentPos = [148,1]; //if no mem is set, set it first;
			doPosChangeMemExtend(dude,dude.currentPos,[657,1],20,20,0.32);
		}
