function protect_email() {
	
	$('a.email').each(function(){
	e = this.rel.replace('/','@');
	this.href = 'mailto:' + e;
	$(this).text(e);
	});	
	
}

function contactForm(str1, str2, str3, str4, str5)
{
	
$('#loader').show();
var sendurl="sendform.aspx?formid="+str1+"&bizname="+str2+"&contactname="+str3+"&email="+str4+"&enquiry="+str5+"&sid="+Math.random();
var html = $.ajax({
  url: sendurl,
  async: false,
  success: function(){
	 $('#submitbut').fadeOut("slow");
	 $('#loader').fadeOut("slow");
     $('#confirmation').fadeIn("slow");
   }

 }).responseText;
}

function renewalForm(str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12, str13, str14, str15, str16, str17, str18, str19, str20)
{

$('#loader').show();
var sendurl="sendform.aspx?formid="+str1+"&bizname="+str2+"&addr1="+str3+"&addr2="+str4+"&addr3="+str5+"&contactname="+str6+"&telephone="+str7+"&email="+str8+"&enquiry="+str9+"&day1="+str10+"&month1="+str11+"&day2="+str12+"&month2="+str13+"&day3="+str14+"&month3="+str15+"&day4="+str16+"&month4="+str17+"&othertype="+str18+"&day5="+str19+"&month5="+str20+"&sid="+Math.random();
var html = $.ajax({
  url: sendurl,
  async: false,
  success: function(){
	 $('#submitbut').fadeOut("slow");
	 $('#loader').fadeOut("slow");
     $('#confirmation').fadeIn("slow");
   }

 }).responseText;
}

function highlight_active_links(linkid) {
	
	$("a.menuitem").eq(linkid).addClass("active");

}

function rotate_testimonials(){

	var first = 0;
	var speed = 2000;
	var pause = 6500;
	
		function removeFirst(){
			first = $('ul#testimlist li:first').html();
			$('ul#testimlist li:first')
			.animate({opacity: 0}, speed)
			.fadeOut('slow', function() {$(this).remove();});
			addLast(first);
		}
		
		function addLast(first){
			last = '<li style="display:none">'+first+'</li>';
			$('ul#testimlist').append(last)
			$('ul#testimlist li:last')
			.animate({opacity: 1}, speed)
			.fadeIn('slow')
		}
	
	interval = setInterval(removeFirst, pause);
}

function font_resize() {
	
  // Reset Font Size
  var originalFontSize = $('html').css('font-size');
  $(".resetFont").click(function(){
  $('html').css('font-size', originalFontSize);
  });
  // Increase Font Size
  $(".increaseFont").click(function(){
  	var currentFontSize = $('html').css('font-size');
 	var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.2;
	$('html').css('font-size', newFontSize);
	return false;
  });
  // Decrease Font Size
  $(".decreaseFont").click(function(){
  	var currentFontSize = $('html').css('font-size');
 	var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*0.8;
	$('html').css('font-size', newFontSize);
	return false;
  });
}

function smooth_scroll() {

$('a[href*=#]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
		var $target = $(this.hash);
		$target = $target.length && $target
		|| $('[name=' + this.hash.slice(1) +']');
	if ($target.length) {
		var targetOffset = $target.offset().top;
		$('html,body')
		.animate({scrollTop: targetOffset}, 1000);
		return false;
	}
	}
});

}

/*$.validator.setDefaults({
	submitHandler: function() {
	contactForm(document.getElementById('bizname').value, document.getElementById('contactname').value, document.getElementById('email').value, document.getElementById('enquiry').value);
	}
});*/

function validate_contactform() {
	
	var container = $('div#messages');
	// validate the form when it is submitted
	var validator = $("form").validate({
		errorContainer: container,
		wrapper: 'div class="errormsg"',
		meta: "validate",
		submitHandler: function() {
			contactForm($('#formid').val(), $('#bizname').val(), $('#contactname').val(), $('#email').val(), $('#enquiry').val());
		}
	});
}

function validate_renewalform() {
	
	var container = $('div#messages');
	// validate the form when it is submitted
	var validator = $("form").validate({
		errorContainer: container,
		wrapper: 'div class="errormsg"',
		meta: "validate",
		submitHandler: function() {
			renewalForm($('#formid').val(), $('#bizname').val(), $('#addr1').val(), $('#addr2').val(), $('#addr3').val(), $('#contactname').val(), $('#telephone').val(), $('#email').val(), $('#enquiry').val(), $('#day1').val(), $('#month1').val(), $('#day2').val(), $('#month2').val(), $('#day3').val(), $('#month3').val(), $('#day4').val(), $('#month4').val(), $('#othertype').val(), $('#day5').val(), $('#month5').val());
		}
	});
}

function animate_submit() {
	
$('#submitbut').hover(
function () {
		$(this).removeClass("out");
        $(this).addClass("over");
      }, 
      function () {
        $(this).removeClass("over");
		$(this).addClass("out");
      }
    );
}

$(document).ready(function(){
						   
	protect_email();
	rotate_testimonials();
	smooth_scroll();
	$('div#logo').pngFix()
});
