// JavaScript Document
function isValidEmail(str) { 
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(str)){
		return false
	}else{
		return true
	}
}
var sliderTimer;

$(document).ready(function() {
	setTimeout("popUpDescription()", 500)
	
	$('a[rel=lb]').lightBox();
	
	$("#features").mouseover(function(){
		if($.browser.msie){
			$('.next, .prev').show()
		}else{
			$('.next, .prev').fadeIn("fast")
		}
		clearTimeout(sliderTimer)
	})
	
	$(".next").click(function(){
		$("#description").slideUp("fast")
		$("#slider").animate({ marginLeft: "-=950px"}, 800, function(){
			var item = $("#slider a:first")
			item.remove()
			$("#slider").append(item)
			$(this).css("marginLeft", "-950px")
			$("#description").html($("#slider img:eq(1)").attr("alt")+' <strong><a href="'+$("#slider img:eq(1)").parent().attr("href")+'">Read More</a></strong>.').slideDown("slow")			
		})
	})
	
	$(".prev").click(function(){
		$("#description").slideUp("fast")
		$("#slider").animate({ marginLeft: "+=950px"}, 800, function(){
			var item = $("#slider a:last")
			item.remove()
			$("#slider").prepend(item)
			$(this).css("marginLeft", "-950px")
			$("#description").html($("#slider img:eq(1)").attr("alt")+' <strong><a href="'+$("#slider img:eq(1)").parent().attr("href")+'">Read More</a></strong>.').slideDown("slow")			
		})				
	})
	
	$("#features").mouseout(function(){
		sliderTimer=setTimeout("fadeOutSliderNav()", 200)
	})
	
	$(".blub").mouseover(function(){
		$(this).animate({backgroundPosition: '500px 150px'}, "slow")
	})
	
	$("#send").hide()
	$("form.contact input, form.contact textarea").not($("#send")).focus(function(){
		$(this).removeClass("invalid")
		$("#send").slideDown()
		if (!$(this).hasClass("valid")&&!$(this).hasClass("invalid")){
			$(this).val("");
		}
	})
	$("form.contact input, form.contact textarea").not($("#send")).blur(function(){

		if ($(this).attr("name")=="name"){
			if ($(this).val()=="Your Name"||!$(this).val()){
				$(this).removeClass("valid").addClass("invalid")
				$(this).val("Your Name")

			}else{
				$(this).removeClass("invalid").addClass("valid")
			}

		}

		if ($(this).attr("name")=="email"){
			if (!isValidEmail($(this).val())){
				$(this).removeClass("valid").addClass("invalid")
			}else{
				$(this).removeClass("invalid").addClass("valid")
			}

			if (!$(this).val()){
				$(this).val("Your Email")
				$(this).removeClass("valid").addClass("invalid")
			}

		}
		if ($(this).attr("name")=="phone"){
			if (!$(this).val()){
				$(this).val("Your Phone")
			}
			//$(this).addClass("valid")
		}

		if ($(this).attr("name")=="message"){
			if ($(this).val()=="Your Message / Enquiry" || !$(this).val()){
				$(this).removeClass("valid").addClass("invalid")
				$(this).val("Your Message / Enquiry")		
			}else{
				$(this).removeClass("invalid").addClass("valid")
			}
		}

	})
});
function fadeOutSliderNav(){
	if($.browser.msie){
		$('.next, .prev').hide();
	}else{
		$('.next, .prev').fadeOut("fast")
	}
}
function popUpDescription(){
	$("#description").html($("#slider img:eq(1)").attr("alt")+' <strong><a href="'+$("#slider img:eq(1)").parent().attr("href")+'">Read More</a></strong>.').slideDown("slow")			
}
function sendForm(){
	if (!$("input[name=name]").val()||$("input[name=name]").val()=="Your Name"){
		alert("Please correct you name")
		$("input[name=name]").focus();
		return false;
	}
	if (!isValidEmail($("input[name=email]").val())){
		alert("Please correct you email")
		$("input[name=email]").focus();
		return false;
	}
	if (!$("textarea[name=message]").val()||$("textarea[name=message]").val()=="Your Message / Enquiry"){
		alert("Please enter your message")
		$("textarea[name=message]").focus();
		return false;
	}

	$("#send").val("Sending...").css("background","#ffffff")

	$.ajax({
	  type: 'POST',
	  url: 'contact.php',
	  data: $('form.contact').serialize(),
	  success: function(){
		$("form.contact").slideUp(function(){
			$(this).html('Thank you for your message, we will get back to you quickly.<br><br><a href="/contact">Send another message.</a>').slideDown();
		})
	}
	});
	return false;
	
}
