/*Heisdo Movement*/
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("flags").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 = 34; //if no mem is set, set it first;
		//alert(this.firstChild.src);
		var width = 0;
		switch(this.id) {
			case "flag_donate":
				width = 95 ;
				break;
			case "flag_comment":
				width = 105;
				break;
			case "flag_reports":
				width = 182;
				break;
			case "flag_facts":
				width = 121;
				break;
			case "flag_fb":
				width = 135;
				break;
		}	
		doWidthChangeMem(this,this.currentWidth,width,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,34,10,10,0.5);
		}
}

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 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)
}

