$(document).ready(function() {
	$(".slideshow .slider").easySlider({
		continuous: true,
		auto: true,
		controlsShow: false,
		speed: 1500,
		pause: 7500,
	});
	$('.post a img, .widget a img').parent().addClass("lightbox");
	$('a.lightbox').lightBox();

	// Form validation 
	$("form.validate #email").focus(function() {
		if ($(this).val() == "Email address") {$(this).val('');} 
		if ($(this).val() == "Invalid email.") {
			$(this).val(''); 
			$(this).attr('style',''); 
		} 
	});
	$("form.validate #email").blur(function() {
		if ($(this).val() == '') {
			$(this).val('Email address'); 
		} 
	});
	$("form.validate #email").blur(function() {
		if ($("form.validate #email").val() == 'Invalid email.') {
			$("form.validate #email").val('Email address');
			$("form.validate #email").attr('style','');
		} 
	});
	$("form.validate #fname").focus(function() {
		if ($(this).val() == "First name") {$(this).val('');} 
		if ($(this).val() == "Invalid name.") {
			$(this).val(''); 
			$(this).attr('style',''); 
		} 
	});
	$("form.validate #fname").blur(function() {
		if ($(this).val() == '') {
			$(this).val('First name'); 
		} 
	});
	$("form.validate #lname").focus(function() {
		if ($(this).val() == "Last name") {$(this).val('');} 
		if ($(this).val() == "Invalid name.") {
			$(this).val(''); 
			$(this).attr('style',''); 
		} 
	});
	$("form.validate #lname").blur(function() {
		if ($(this).val() == '') {
			$(this).val('Last name'); 
		} 
	});
});


function valid_email(the_form) {
    var el = the_form.email;
    var val = el.value;
    var isValid = true;
    var Regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!Regex.test(val)) {
      isValid = false;
    }
    if( !isValid ) { 
      el.value = 'Invalid email.';
      el.style.color = 'red';
    }
  return isValid;
}

function check_length(id,default_value,error_text,min) {
    var el = document.getElementById(id);
    var val = el.value;
    var isValid = true;
    if (val.length<=min || val==default_value || val==error_text) {
      isValid = false;
    }
    if( !isValid ) { 
      el.value = error_text;
      el.style.color = 'red';
    }
  return isValid;
}

function check_form(the_form) {
    var a = check_length('fname', 'First name', 'Invalid name.', 0);
    var b = check_length('lname', 'Last name', 'Invalid name.', 0);
    var c = valid_email(the_form);
    return (a && b && c);
}
