$(function() {
	
$('.newwindow').click(function(){window.open(this.href); return false;});
	
var previoustarget = '';	
	
var a =	'<a href="';
var b = 'mai';
var c = 'lto:';
var d = 'carmel';
var e =  '@';
var f =  'endangeredpictures.com';
var g = '">';
var h = '</a>';
var total = a+b+c+d+e+f+g+d+e+f+h;
$('#westall-66-contact').append(total); 
	
	$('.nav').click(function() { 
	
	$('.loader').html('');
	var target = $(this).attr("href");
	
	if ( $('#stilla').is(':hidden') && (target != '#westall-66-trailer') ) {
		$('#stilla').fadeIn(1000);
		$('#stillc').fadeIn(1000);

} 

if ($.browser.msie) {
				$('.fadecontentwindow').hide();
				$('#synopsis').hide();
				$('#stillb').hide();
				}
				
		$('#fadecontent').fadeOut('slow', function () {
		$('#fadecontent').children().hide();
		if (target == '#westall-66-feedback'){
		$('#address').hide();
		$('#copies').hide();
		$('#addresslabel').hide();
		$('#copieslabel').hide();
		$("#address").val('NA');
		$("#copies").val('NA');
		$("#subject").val('Westall Feedback');
		$("#message").val('');
		$('#msglabel').html("Feedback or Information on the Westall case:");
		$('#error').html('');
		$('#error').hide();
		$('#contactForm').show();
		target = '#westall-66-dvd';
		} else if (target == '#westall-66-dvd'){
		$('#address').show();
		$('#copies').show();
		$('#addresslabel').show();
		$('#copieslabel').show();
		$("#address").val('');
		$("#copies").val('');
		$("#subject").val('Westall 66 DVD Order');
		$("#message").val('');
		$('#msglabel').html("Additional Comments or Request:");
		$('#error').html('');
		$('#error').hide();
		$('#contactForm').show();
		} else if (target == '#westall-66-trailer'){
		$('#stilla').fadeOut('slow');
		$('#stillc').fadeOut('slow');
		} 
		
		$(target).show();
		$('#fadecontent').fadeIn(1000);
		previoustarget = target;
		
		});
	});
	
	$('#home').click(function() { 
		$('#fadecontent').fadeOut('slow', function () {
					$('#fadecontent').children().hide();
					//$('#contactForm').show();
					$('#fadecontent').show();
					$('#synopsis').fadeIn(1000);
					$('#stillb').fadeIn(1000);
					previoustarget = '#home';
		});
	});
	
// validation
	
	function isValidEmailAddress(emailAddress) {
 		var pattern = new RegExp(/^(("[\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);
 		return pattern.test(emailAddress); }

	$('#email').blur(function() 
    { var mail = $("#email").val(); 
	if (isValidEmailAddress(mail)){$(this).css({ "border": "Solid #000 2px" }); } });
	
	
	$(".req").blur(function() 
    { if ($(this).val() != ""){$(this).css({ "border": "Solid #000 2px" }); } });
	
  $('#contactForm').submit( function(){

if ($('#name').val() == "") { 
$('#name').css({ "border": "Solid red 2px" }); 
$('#error').show();
$('#error').html('Please enter your name');
return false;} 

if ($('#address').val() == "") { 
$('#address').css({ "border": "Solid red 2px" }); 
$('#error').show();
$('#error').html('Please enter an address');
return false;} 

if ($('#copies').val() == "") { 
$('#copies').css({ "border": "Solid red 2px" });
$('#error').show(); 
$('#error').html('Please enter no. of copies');
return false;} 

var mail = $("#email").val();	
if (isValidEmailAddress(mail))
				{} else {
					$('#email').css({ "border": "Solid red 2px" }); 
$('#error').show();
$('#error').html('Please enter a valid email address');
return false;
				}
//end validation

  //hide the form
  $('#contactForm').hide();

  //show the loading bar
  //$('.loader').append($('.bar'));
 // $('.bar').css({display:'block'});
	$('.bar').show();
  //send the ajax request
  $.get('dvd.php',{name:$('#name').val(),
                    email:$('#email').val(),
					subject:$('#subject').val(),
                    address:$('#address').val(),
					copies:$('#copies').val(),
					comment:$('#message').val()},

  //return the data
  function(data){
    //hide the graphic
    //$('.bar').css({display:'none'});
	$('.bar').hide();
	$('.loader').append(data);
  });

  //stay on the page
  return false;
  });
  
 
  
  
});
