var processMove = false;
var processFMove = false;
var timer = false;
var lastMov = new Date();
var actNav = 1;
var curFeat = 1;
nH = 0;
times = 0;

function chngImg(img,tar){
	document.getElementById(tar).src=img;
}

function startTimer(newFet){
	mouse = false;
	moveTimer = window.setInterval("changeMoveElement('+','features_holder',625);",6000)
}

function checkTime(){
	ret = false;
	if (lastMov != 0){
		curDate = new Date();
		curMin = curDate.getSeconds();
		lastMin = lastMov.getSeconds();
		document.getElementById('debug').innerHTML = "Cur: " + curMin + "<br />" + "Last: " + lastMin + "<br />" + document.getElementById('debug').innerHTML;
		if (curMin > (lastMin+30)){
			document.getElementById('debug').innerHTML = "30: true<br />" + document.getElementById('debug').innerHTML;
			ret = true;
		}else if (lastMin > 31 && curMin != lastMin){
			chMin = lastMin-30;
			if (curMin > chMin){
				document.getElementById('debug').innerHTML = "chMin: "+ chMin + " - " + curMin +"<br />" + document.getElementById('debug').innerHTML;
				ret = true;
			}else{
				ret = false;
			}
		}else{
			ret = false;
		}
	}else{
		ret = true;
	}
	document.getElementById('debug').innerHTML = "Last 30: " + curMin + " - " + (lastMin+30) + "<br />" + "ret: " + ret + "<br />" + document.getElementById('debug').innerHTML;
	return ret;
}

function changeMoveElement(dir,tar,w){
	if (curFeat < tot && dir == '+'){
		newFeat = curFeat+1;
	}else if (curFeat == tot && dir == '+'){
		newFeat = 1;
	}else if (curFeat > 1 && dir == '-'){
		newFeat = curFeat-1;
	}else if (curFeat == 1 && dir == '-'){
		newFeat = tot;
	}else if (dir == '+'){
		newFeat = curFeat++;
	}else if (dir == '-'){
		newFeat = curFeat--;
	}
	if (newFeat == 1){
		width = 1;
		moveElement(tar,width,newFeat);
	}else{
		width = -((newFeat-1)*625);
		moveElement(tar,width,newFeat);
	}
}

function moveElement(tar,h,butName){
	if (timer == true && mouse == true){
		timer = false;
		window.clearInterval('moveTimer');
	}
	if (butName != curFeat){
		if (!h){
			if(document.getElementById){
				h = document.getElementById(tar).style.width;
			}else if (document.layers){
				h = document.layers[tar].clip.width;
			}
			h += 70;
		}
		if (processMove == false){
			//move dot
			for(d=1;d<=3;d++){
				if (d == butName){
					document.getElementById('dot'+d).src = 'images2011/feature_dot_active.png';
				}else{
					document.getElementById('dot'+d).src = 'images2011/feature_dot.png';
				}
			}
			curFeat = butName;
			myInterval = window.setInterval("changeHeight('"+tar+"','"+h+"','marginLeft','processMove')", 40);
			processMove = true;
		}
	}
}

function changeHeight(tar,h,el,pr){
	// GET TARGET CURRENT HEIGHT //
	curH = eval('document.getElementById(tar).style.'+el);
	curH = parseFloat(curH);
	if (checkClose(curH,h) == false){
		//if (curH < 0){ curH = curH * -1; }
		dif = h-curH;
		mov = dif/5;
		if (nH != curH+mov){ nH = curH+mov; times = 0; }else{ times = times+1; }
		if (mov < 1 && mov > -1){
			changeTo = h+"px";
		}else{
			changeTo = curH+mov+"px";
		}
		finTar = 'document.getElementById("'+tar+'").style.'+el;
		eval(finTar +"='"+changeTo+"';");
	}else{
		lastMov = new Date();
		clearInterval(myInterval);
		//document.getElementById('debug').innerHTML = "PR: " + pr + "<br />" + document.getElementById('debug').innerHTML;
		processMove = false;
	}
}

function checkClose(curH,h){
	if (Math.round(curH) != h){
		return false;
	}else{
		return true;
	}
}

function emailSignup(){
	fname=document.forms['mailingList'].fname.value;
	if (fname == "" || fname == 'First Name'){
		alert('Please provide us with your first name.');
		return false;
	}
	if (document.forms['mailingList'].lname.value == "" || document.forms['mailingList'].lname.value == 'Last Name'){
		alert('Please provide us with your last name.');
		return false;
	}
	if (document.forms['mailingList'].quest239.value == "" || document.forms['mailingList'].quest239.value == 'Email Address'){
		alert('Please provide us with a valid email address.');
		return false;
	}
	document.forms["mailingList"].submit();
}


function emailPage(tar){
	if (tar){
		nw = window.open("z_includes/emailpage.php?pn="+tar,"emailpage", "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=400,height=500");
	}
}
