var replaced = false;
			
function initReplace() {
	if(!replaced) {
		var e = document.getElementById('s');
		e.value = ''; replaced = true;
	}
}

var clientsOffset	= 0;
var totalOffset		= 12;
var direction		= 0;

function clientsScroll() {
	
	if(direction == 0) {
		if(clientsOffset < totalOffset)
			clientsOffset++;
		else
			return false;
	
		var mt = clientsOffset*-115;
	
		$('#clients img').animate({ marginTop: mt+'px' }, 1000);
		
		if(clientsOffset == totalOffset) {
			$('#clients_button img').attr('src', '/templates/mei/images/btn-clients2.gif');
			direction = 1;
		}
	
	} else {
		if(clientsOffset > 0)
			clientsOffset--;
		else
			return false;
	
		var mt = clientsOffset*-115;
	
		$('#clients img').animate({ marginTop: mt+'px' }, 1000);
		
		if(clientsOffset == 0) {
			$('#clients_button img').attr('src', '/templates/mei/images/btn-clients.gif');
			direction = 0;
		}
	}	
	
	return false;
}

function displayVideo(vid) {
	var myQTObject = new QTObject("/videos/"+vid+".m4v", "videoViewer", "640", "375");
	myQTObject.addParam("autostart", "true");
	myQTObject.write('videoViewer');
	
	return false;
}


function validateEmail(e) {
	var emailRE = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;

	if(!e.match(emailRE))
		return false;

	return true;
}

function submitForm(subject) {
	var fname 	= $('#f_fname').val();
	var lname 	= $('#f_lname').val();
	var email	= $('#f_email').val();
	var comp	= $('#f_comp').val();
	
	if(fname == '') {
		alert('Please enter your first name!');
		return false;
	}
	
	if(lname == '') {
		alert('Please enter your last name!');
		return false;
	}
	
	if(email == '') {
		alert('Please enter your email!');
		return false;
	}
	
	if(!validateEmail(email)) {
		alert('Please enter a valid email address!');
		return false;
	}
	
	if(subject == 'Inquiry About MEI/Products') {
		var phone	= $('#f_phone').val();
		var comment	= $('#f_comment').val();
		
		if(comment == '') {
			alert('Please enter your comment!');
			return false;
		}
	
		$.ajax({
			type:		"POST",
			url:		"http://meidev.web2sandbox.com/sendForm.php",
			data:		{ fn: fname, ln: lname, e: email, c: comp, s: subject, p: phone, ct: comment },
			cache:		false,
			success:	function(val){ submitForm_cb(); }
		});
		
	} else {
		$.ajax({
			type:		"POST",
			url:		"http://meidev.web2sandbox.com/sendForm.php",
			data:		{ fn: fname, ln: lname, e: email, c: comp, s: subject },
			cache:		false,
			success:	function(val){ submitForm_cb(); }
		});
	}
		
	return false;
}

function submitForm_cb(val) {
	$('#actionForm').slideUp('fast', function () {
		$('#actionForm').html('<div class="message"><h3>Your Request Has Been Sent</h3><p>Your request has been sent to us, and we will respond as quickly as possible.</p></div>');
		
		$('#actionForm').slideDown();
	});
}

var currBubble = 0;
var bubbleHold = false;

function bubbleOverview(num) {
	for(var i=0; i<=5; i++) {
		if(currBubble != i)
			$('#b'+i).fadeOut('fast');
	}
	
	if(currBubble != num) {
		$('#b'+currBubble).fadeOut('fast', function() { $('#b'+num).fadeIn('fast'); });
		currBubble = num;
		
		$('#bubble').css('backgroundImage', 'url(/images/stories/mei/bubble'+currBubble+'.gif)');
	}
	
	return false;
}
