$(document).ready(function(){

	$('div#mySlides').innerfade({
		speed: 1000,
		timeout: 9000,
		type: 'sequence',
		containerheight: '255px'
	});
	
	$(".postthumb img").hover(
		function() {$(this).animate({"opacity": ".3"}, "medium");}, 
		function() {$(this).animate({"opacity": "1"}, "medium");}
	);
	
	$("#nav-one").dropmenu({});
		
	if($('#first_name').length > 0) $('#first_name').focus();
	
	//FINISH CHECKOUT
	if($('#receiptBox').length > 0) {
		safeGo();
		var safeToGo = false;
	}
});


function safeGo() {
	setTimeout(function(){ 
		$('#receiptBox').css('display','block');
		$('#receiptWaitBox').css('display','none');
		safeToGo = true;
	}, 5000 );
}

$(window).unload(function() {
	if(safeToGo == false) {
		alert('nope');
	}
});


/////////////////////////////////
// BOTTOM CONTENT ROTATOR ///////
/////////////////////////////////
function rotateThis(rotNum) {
	
	var numberOfSeconds = 8; //TIME BETWEEN ITEM SWITCHES 
	var rotBoxNum = rotNum;
	var rotBox = 'homeRot'+rotNum;
	var rotItems = null;
	var currentItem = 0;
	var prevItem = 0;
	rotItems = $('#'+rotBox+' p');
	rotItems.each(function(i) { if(i != 0) $(this).fadeOut(0); });
	var rotInterval = setInterval(nextRotItem, 500+(rotBoxNum*200));
	
	function nextRotItem() {
		clearInterval(rotInterval);
		rotItems.each(function(i) { 
			(i != currentItem) ? $(this).fadeOut(0): $(this).fadeIn(500); 
		});
		rotInterval = setInterval(nextRotItem, numberOfSeconds*1000);
		prevItem = currentItem;
		currentItem = (currentItem+1 > rotItems.length-1) ? 0: currentItem+1;
	}
}

function validateLead(form) {
	var error = false;
	if(form.first_name.value == "" || form.last_name.value == "" || form.company.value == "" || form.title.value == "" || form.email.value == "") {
		error = true;
		alert("Please fill in all required fields.");
	}
	return (error == false) ? true: false;
}
function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

