// HANDLE WINDOW.ONLOAD:s ----------------------------------------------------

if (document.getElementById && document.getElementsByTagName && document.createTextNode) {
	window.onload = init;
}

var onLoads = new Array;

function init() {
    
	for (var i = 0; i < onLoads.length; i++) {
		eval(onLoads[i]);
	}
}

function addOnLoad(func) {
	onLoads[onLoads.length] = func;
}

// scroll
function pageScroll() {    	window.scrollBy(0,100);    	scrolldelay = setTimeout('pageScroll()',500); // scrolls every 1000 milliseconds
    	clearTimeout(scrolldelay);}function stopScroll() {    	clearTimeout(scrolldelay);}function jumpScroll() {   	window.scroll(0,0); // horizontal and vertical scroll targets}

// Namespace for open close contact tab --------------------------------------
addOnLoad("anim.initTab()"); // loads initTab() when page is loaded.

var anim = {
	minHeight: 5,
	maxHeight: 205,
	currHeight: 5,
	interval: 40,
	state: 1,
	running: 0,
	timer: null,
	
	initTab: function(){
		target = document.getElementById('tab-contact');
		if(target){
			target.onclick = anim.start;		
		}
	},
	start: function(navL) {
	    if(anim.running == 1){
			return false;
		}else{	
			anim.timer = setInterval(anim.nextFrame, anim.interval);	
		}	
	},
	stop: function(i) {
		target = document.getElementById('tab-contact');
		if(i == 1){
			target.className = "";
			anim.state = i;
			anim.running = 0;		
		}else{
			target.className = "active";
			anim.state = i;
			anim.running = 0;
		}
		clearInterval(anim.timer);
	},
			nextFrame: function() {
		target = document.getElementById('tab-contact');
		if(anim.state == 0){	
			if(anim.currHeight > anim.minHeight){
				anim.running = 1;
				anim.currHeight -= 20
				document.getElementById('contact').style.display = "block";
				document.getElementById('contactInfo').style.display = "none";
				document.getElementById('contact_wrapper').style.height = anim.currHeight+"px";
				pageScroll();
			}else if(anim.currHeight <= anim.minHeight){
				document.getElementById('contact').style.display = "none";
				document.getElementById('contactInfo').style.display = "none";
				anim.stop(1);
			}
		}else if(anim.state == 1){
			if(anim.currHeight < anim.maxHeight){
				anim.running = 1;
				anim.currHeight += 20
				document.getElementById('contact').style.display = "block";
				document.getElementById('contactInfo').style.display = "none";
				document.getElementById('contact_wrapper').style.height = anim.currHeight+"px";
				pageScroll();
			}else if(anim.currHeight >= anim.maxHeight){
				document.getElementById('contact').style.display = "block";
				document.getElementById('contactInfo').style.display = "block";
				pageScroll();
				anim.stop(0);	
			}	
		}
	}
}

