$(document).ready( function() {

$("#top li a").animate({backgroundColor: "#eee"}, 150);

jQuery.fn.wordCount = function(params)
{
   var p =  {
   counterElement:"display_count"
   };
	
	var total_words;

  if(params) {
      jQuery.extend(p, params);
 }

function check(e){
  total_words=e.value.split(/[\s\.\?]+/).length;
  showAlert = 1;
  if((total_words > 1000) && (showAlert != 0)){
  	$("div#toomuch").fadeIn(700);
  	$("div#toomuch").animate({
  		left : '700px'
  		}, { queue: false, duration: 700 });
  	showAlert = 1;
  }
  if((total_words < 1000) && (showAlert)){
  	$("div#toomuch").fadeOut(700);
  	$("div#toomuch").animate({
  		left : '675px'
  		}, { queue: false, duration: 700 });
  	showAlert = 0;
  }
  total_words /= 5;
  if(total_words < 1){
  	total_words = 1;
  	}
  total_words = Math.round(total_words); 
  jQuery('#'+p.counterElement).html(total_words); 
}

this.mousemove(function()
  {
check(this);
});

this.keypress(function()
  {
check(this);
});

this.blur(function()
  {
check(this);
});
};

$('#tranText').wordCount();
$("#collaborativeDiv").fadeIn('slow');

$("#details ul li a").click(function(){
var target = $(this).attr("href");
var old = $("#details .current").attr("href");
$("#details .current").attr("class", "");
$(this).attr("class", "current");
$(old).fadeOut('fast', function() {
	$(target).fadeIn('slow');
	});
return false;
});

$("#email").focus(function(){
$("div#detailsinfo").fadeIn(700);
$("div#detailsinfo").animate({
  		left : '700px'
  		}, { queue: false, duration: 700 });
});

$("#email").blur(function(){
if (isValidEmailAddress($(this).val())){
$("div#detailsinfo").fadeOut(700);
$("div#detailsinfo").animate({
  		left : '675px'
  		}, function(){
$("div#detailsinfo p").css('color', 'black');
$("div#detailsinfo p").html('Email Address Needs to Match a Verified Paypal Account.'), { queue: false, duration: 700 }
  		}
  		);
} else {
$("div#detailsinfo p").css('color', 'red');
$("div#detailsinfo p").html('Please Enter A Valid Email Address, Thanks!');
}
});

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);
}

$("div#yourDetails textarea").focus(function(){
$(this).css('color', '#000');
$(this).css('font-style', 'normal');
$(this).html('');
});

$("div#yourDetails textarea").blur(function(){
if($(this).val()==''){
$(this).css('color', '#777');
$(this).css('font-style', 'italic');
$(this).html('Include any special instructions, such as how to present the translated document, here.');
}
});

$("#cmdMail").hide();
$("div#translationText").attr('class', 'down');
$("div#yourDetails").hide();
$("div#pay").hide();

$("#link1").click(function(){
if($("div#translationText").hasClass('down')){
return false;
} else {
	$("div.down").fadeOut('fast', function(){
		$("div#translationText").slideDown('fast');
	}
		);
	$("div.down").attr('class', '');
	$("div#translationText").attr('class', 'down');
	$("div#content h3 a.current").attr('class', '');
	$("#link1").attr('class', 'current');
	return false;
}
});


$("#link2").click(function(){
if($("div#yourDetails").hasClass('down')){
return false;
} else {
if($("#tranText").val()==''){
$("div#pleaseenter").fadeIn(700);
$("div#pleaseenter").animate({
  		left : '700px'
  		}, { queue: false, duration: 700 });
  	open = 'true';
	} else {
	if (open){
	$("div#pleaseenter").fadeOut(700);
	$("div#pleaseenter").animate({
  		left : '675px'
  		}, { queue: false, duration: 700 });
  		open = 'false';
		}
	$("div.down").slideUp('fast', function(){
	$("div#yourDetails").fadeIn('fast');
	}
		);
	$("div#content h3 a.current").attr('class', '');
	$("#link2").attr('class', 'current');
	$("div.down").attr('class', '');
	$("div#yourDetails").attr('class', 'down');
	}
	return false;
}
});

$("#link3").click(function(){
if($("div#pay").hasClass('down')){
return false;
} else {
if($("div#translationText").hasClass('down')){
	return false;
} else {
	if((isValidEmailAddress($("#email").val()))&&($("#name").val() != '')){
	if (open){
	$("div#fieldsrequired").fadeOut(700);
	$("div#fieldsrequired").animate({
  		left : '675px'
  		}, { queue: false, duration: 700 });
  		open = 'false';
		}
	
	$("div.down").slideUp('fast', function(){
	$("div#pay").fadeIn('fast');
	}
	);
	$("div#content h3 a.current").attr('class', '');
	$("#link3").attr('class', 'current');
	$("div.down").attr('class', '');
	$("div#pay").attr('class', 'down');

	} else {
	$("div#fieldsrequired").fadeIn(700);
	$("div#fieldsrequired").animate({
  		left : '700px'
  		}, { queue: false, duration: 700 });
  	warning = 'true';
	}
	return false;
}
}
});


$("#top li a").hover(function(){
	$(this).animate({backgroundColor: "#fff"}, 150);
  }, function(){
	$(this).animate({backgroundColor: "#eee"}, 300);
  });
  
 $("#top li a").mousedown(function(){
	$(this).animate({backgroundColor: "#ddd"}, 150);
  });


$("#cmdMail2").click(function(){
	if((isValidEmailAddress($("#CUemail").val()))&&($("#CUname").val() != '')&&($("#CUmessage").val() != '')){
		$.post("contactUs.php",
   { CUname: $("#CUname").val(), CUemail: $("#CUemail").val(), CUmessage: $("#CUmessage").val() },
   	function(data){
		if(data=="Thanks! Your message has been submitted. You'll hear from us shortly."){
		$("#contactForm").fadeOut('fast');
		$("#userMessage").html(data);
		$("#userMessage").fadeIn('fast');
		} else {
		$("#userMessage").html(data);
		$("#userMessage").fadeIn('fast');
		}
	});
	} else {
		$("#userMessage").html("Please Fill In All Fields Correctly");
		$("#userMessage").fadeIn('fast');
	}
	return false;
});

$paneTarget = $("body");

$("#top a").click(function(){
		anchor = $(this).attr('href');
		$paneTarget.stop().scrollTo( anchor , 500 );
		return false;
	});

Cufon.replace('h2');

});


