// 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
	}
}
function showSite(){
	if (!shown){
		shown=true;
	$("#intro_cover").fadeIn(function(){
		$("#about").hide()
		$("#intro").remove()
		$("#intro_cover").fadeOut(function(){
			$("#about").show()
			$("#copyInfo").fadeIn()

		});

	});
	}
}
function showLocations(){
	if (!shown){
		shown=true;
		$("#nav_about").removeClass("selected")
		
	$("#intro_cover").fadeIn(function(){
		$("#locations, #about").hide()
		$("#intro").remove()
		$("#intro_cover").fadeOut(function(){
			$("#nav_locations").trigger("click").trigger("mouseover")
			

		});

	});
	}
}
function emaillist(){
	$('#clickheremailing').hide();
	$('#mailing_list').fadeIn();
}
function mlcheck(){
	var self=$("#mailing_list");
	if (!$('#mailing_list input[name="name"]').val()){
		alert("Please correct your name.");
		$('#mailing_list input[name="name"]').focus();
		return false;
	}
	if (!isValidEmail($('#mailing_list input[name="email"]').val())){
		alert("Please correct your email.");
		$('#mailing_list input[name="email"]').focus();
		return false;
	}

	$.post("mailing_list.php", $("#mailing_list").serialize(), function(data){
		$(self).fadeOut("fast", function(){
	   		$("#clickheremailing").html("Thank you for joining.").show();
			Cufon.replace('.quicksand, #clickheremailing');
		//	$()
		});
 	});
}
	function showEnq2(){
		$('#enq1').hide();
		$('#enq2').show();
		$('#map').fadeOut('fast')
		
		
		$("#enq2, #enq2 a").click(function(e){ e.stopPropagation(); });
		
		setTimeout("setBind()", 500)
	
	
}

function setBind(){
	$(document).bind("click", function(){ 
		$('#enq2').hide();
		$('#enq1').show();
		$('#map').fadeIn('fast')
		setTimeout("unBind()", 500)
		
	});
}
function setBind2(){
	$(document).bind("click", function(){ 
		$('#dirs').hide();
		$('#enq1').show();
		setTimeout("unBind()", 500)
		
	});
}

function unBind(){
	$(document).unbind('click');
}

function showDirs(){
	$("#enq1").hide();
	$("#dirs").fadeIn("fast")
	
	$("#dirs").click(function(e){ e.stopPropagation(); });
	
	setTimeout("setBind2()", 500)
	
	
}
scrollpanelash=false;
scrollpanebrow=false;
scrollpanefeather=false;

$(document).ready(function(){
	//		$('#preload').flash(
	//			{
	//				swf: 'preload.swf',
	//				height: 560, width: 1000 // default is 180
	//			})
		
	//	setTimeout("showSite()", 9000)
		
		
		$('#media').css("top",($(".menu_container").position().top+22))
		$("div.sub").hide()		
			$('a[rel=lb]').lightBox();
			$('a[rel=lb2]').lightBox();
			$('a[rel=lb3]').lightBox();
			$('a[rel=lb4]').lightBox();
			$('a[rel=lb5]').lightBox();
			$('a[rel=lb6]').lightBox();
			
		$("a.service-image").click(function(){ //On service click	
			if (!$(this).hasClass("selected")){
				if ($(this).attr("id")=="lash_extensions" && !scrollpanelash){
						$('#lash_content .scroll-pane').jScrollPane();
						scrollpanelash=true;
				
				}
				if ($(this).attr("id")=="brow_area" && !scrollpanebrow){
						$('#brow_content .scroll-pane').jScrollPane();
						scrollpanebrow=true;
				}
				if ($(this).attr("id")=="feather" && !scrollpanefeather){
						$('#feather_content .scroll-pane').jScrollPane();
						scrollpanefeather=true;
				}
				
				
				$('a.service-image').animate({left: '0'}, {queue:false}).not(this).animate({left: '-58px'}, {queue:false}) //Adjust image views
				$('div.sub').animate({width: '116px'}, {queue:false}) //Make others smaller
				$(this).parent().parent().animate({width:'579px'}) //Make selected larger
				$("div.sub a.selected").removeClass("selected").find("img").fadeIn()
				$(this).addClass("selected")
			}
		})		

		$("a.service-image, .media_item").hover(
			function () {
				if (!$(this).hasClass("selected")){
					$(this).find("img").stop(true,true).fadeOut();
				}
			}, 
			function () {
				if (!$(this).hasClass("selected")){
					$(this).find("img").stop(true,true).fadeIn();
				}
			}
		);

		$(".media_item").mouseover(function(){
			$(this).find(".media_title").stop(true,true).fadeIn("fast")
		})
		
		$(".media_item").mouseout(function(){
			$(this).find(".media_title").stop(true,true).fadeOut("fast")
		})

		Cufon.replace('.quicksand.hover', { hover: true });
		
		Cufon.replace('.quicksand, .scroll-pane p');
		Cufon.replace('.serlio.hover', { hover: true, fontFamily: 'Serlio LH' });
	
		Cufon.replace('.serlio', { fontFamily: 'Serlio LH' });
		
		var dirin=false;
		$("#show_dirs").click(function(){
			$(this).blur()
			if (!dirin){
				$(".nondir").hide()
				$(".directions").fadeIn("fast");
				dirin=true;
			}else{				
				$(".directions").hide();
				$(".nondir").fadeIn("fast")
				dirin=false;
			}
		})
		
		$('#stockist_form a.clearform').click(function(){
			if (confirm("Clear fields?")){
				$("#stockist_form input, #stockist_form textarea").val("")
			}
		})
		$('#subscribe_form a.clearform').click(function(){
			if (confirm("Clear fields?")){
				$("#subscribe_form input, #subscribe_form textarea").val("")
			}
		})
		$('#stockist_form a.submit').click(function(){
			var self=$("#stockist_form");
			if (!$('#stockist_form input[name="name"]').val()){
				alert("Please correct your name.");
				$('#stockist_form input[name="name"]').focus();
				return false;
			}
			if (!isValidEmail($('#stockist_form input[name="email"]').val())){
				alert("Please correct your email.");
				$('#stockist_form input[name="email"]').focus();
				return false;
			}
			if (!$('#stockist_form input[name="telephone"]').val()){
				alert("Please correct your telephone number.");
				$('#stockist_form input[name="telephone"]').focus();
				return false;
			}
			if (!$('#stockist_form input[name="address1"]').val()){
				alert("Please correct your address.");
				$('#stockist_form input[name="address1"]').focus();
				return false;
			}
			if (!$('#stockist_form input[name="address2"]').val()){
				alert("Please correct your address.");
				$('#stockist_form input[name="address2"]').focus();
				return false;
			}
			if (!$('#stockist_form input[name="country"]').val()){
				alert("Please correct your country.");
				$('#stockist_form input[name="country"]').focus();
				return false;
			}
			$.post($("#stockist_form").attr("action"), $("#stockist_form").serialize(), function(data){
				$(self).fadeOut("fast", function(){
			   		if (data=="Success"){
						$('#thankyou').html('<p style="font-size:8pt;">Thank you for your interest. We will be in touch shortly.</p>').fadeIn();			
					}else{
						$('#thankyou').html('<p style="font-size:8pt;">An error occurred, please email or call us directly.</p>').fadeIn();
					}
					Cufon.replace('.quicksand, #thankyou');
				});
		 	});

			return false;

		});
		
		
		$('#subscribe_form a.subscribe').click(function(){
			var self=$("#subscribe_form");
			if (!$('#subscribe_form input[name="name"]').val()){
				alert("Please correct your name.");
				$('#subscribe_form input[name="name"]').focus();
				return false;
			}
			if (!isValidEmail($('#subscribe_form input[name="email"]').val())){
				alert("Please correct your email.");
				$('#subscribe_form input[name="email"]').focus();
				return false;
			}
			if (!$('#subscribe_form input[name="telephone"]').val()){
				alert("Please correct your telephone number.");
				$('#subscribe_form input[name="telephone"]').focus();
				return false;
			}
			if (!$('#subscribe_form input[name="address1"]').val()){
				alert("Please correct your address.");
				$('#subscribe_form input[name="address1"]').focus();
				return false;
			}
			if (!$('#subscribe_form input[name="address2"]').val()){
				alert("Please correct your address.");
				$('#subscribe_form input[name="address2"]').focus();
				return false;
			}
			if (!$('#subscribe_form input[name="country"]').val()){
				alert("Please correct your country.");
				$('#subscribe_form input[name="country"]').focus();
				return false;
			}
			$.post($("#subscribe_form").attr("action"), $("#subscribe_form").serialize(), function(data){
				$(self).fadeOut("fast", function(){
			   		if (data=="Success"){
						$('#sub_thankyou').html('<p style="font-size:8pt;">Thank you for subscribing.</p>').fadeIn();			
					}else{
						$('#sub_thankyou').html('<p style="font-size:8pt;">An error occurred, please email us directly.</p>').fadeIn();
					}
					Cufon.replace('.quicksand, #sub_thankyou');
				});
		 	});

			return false;

		});
		
});
