function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = jQuery(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
$(document).ready(function() {
	equalHeight($(".matchTitleHeight")); 
});
$(document).ready(function() {
	equalHeight(jQuery(".matchContainerHeight"));
});
$(function() {
			
			$("ul.topnav li a").hover(function() {
				
				$(this).parent().find("ul.subnav").slideDown('fast').show();
					$(this).parent().hover(function() {
						$(this).addClass("subhover");
					}, function(){
						$(this).removeClass("subhover");
						$(this).parent().find("ul.subnav").fadeOut('fast');
					});
				}).hover(function() {
					$(this).addClass("subhover");
						}, function(){ //On Hover Out
					$(this).removeClass("subhover");
				});
			
			$("ul.subnav").mouseover(function() {
			
				$(this).parent().addClass("hover");
					$(this).parent().hover(function() {
						}, function(){
					$(this).parent().removeClass("hover");
				});
			}).hover(function() {
				$(this).parent().addClass("hover");
					}, function(){ //On Hover Out
				$(this).parent().removeClass("hover");
				});
});

$(function() {
		   
		  $("ul.latest li div.innerdiv a").hover(function() {
				
				$(this).parent().find(".caption").slideDown('fast')
					$(this).parent().hover(function() {
					}, function(){
						$(this).parent().find(".caption").slideUp('fast')
					});
				})
		   

});

$(function(){
	$('.newsItems').vTicker({ 
		speed: 500,
		pause: 4000,
		animation: 'fade',
		mousePause: true,
		height: 0,
		showItems: 3
	});
});

$(function() {
	$('.contentBlock table').wrap('<div class="table_wrap" />');
});
$(function() {
	$('hr').wrap('<div class="hrReplacement clearfix" />');
});

$(function() {
var twoColList = $("ul.twoColList");
    for(var i = 0; i < twoColList.length; i+=2) {
      twoColList.slice(i, i+2).wrapAll("<div class='twocolulwrap clearFix' />");
    }
});
$(function() {
var threeColList = $("ul.threeColList");
    for(var i = 0; i < threeColList.length; i+=3) {
      threeColList.slice(i, i+3).wrapAll("<div class='threecolulwrap clearFix'/>");
    }
});
$(function() {
var fourColList = $("ul.fourColList");
    for(var i = 0; i < fourColList.length; i+=4) {
      fourColList.slice(i, i+4).wrapAll("<div class='fourcolulwrap clearFix'/>");
    }
});


$(function($){
  $('img.floatedRight').each(function(index) {
	$(this).wrap('<div class="img_wrap_right" />');
	var wrapper = $(this).parent();
    //$this = $(this).wrap('<div class="img-caption" />');
	$('.img_wrap_right').wrap('<div class="img_wrap_right_caption" />');
    $('<div class="img-caption"><p class="caption">' + $(this).attr("title") + '</p></div>').insertAfter($(this).parent('.img_wrap_right'));
  });
});

$(function($){
  $('img.floatedLeft').each(function(index) {
	$(this).wrap('<div class="img_wrap_left" />');
	var wrapper = $(this).parent();
    //$this = $(this).wrap('<div class="img-caption" />');
	$(this).parent('.img_wrap_left').wrap('<div class="img_wrap_left_caption" />');
    $('<div class="img-caption"><p class="caption">' + $(this).attr("title") + '</p></div>').insertAfter($(this).parent('.img_wrap_left'));
  });
});

$(function(){  
			jQuery("a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_rounded'});
		});


$.validator.methods.equal = function(value, element, param) {
		return value == param;
	};
	
	//$("input[name=formSubmit]").click(function () {
	$('input[name=formSubmit]').live('click', function() {
		var validator = $("#contactForm").bind("invalid-form.validate", function() {
			$("#summary").html("Your form contains " + validator.numberOfInvalids() + " errors, see details below.");
		}).validate({
			debug: true,
			errorElement: "em",
			errorContainer: $("#warning"),
			errorPlacement: function(error, element) {
				error.appendTo( element.parent("div").next("div") );
			},
			success: function(label) {
				label.addClass("success");
			},
			submitHandler:function(form) {
					submitcontactform();
				},
			rules: {
					cstName: "required",		// simple rule, converted to {required:true}
					cstEmail: {				// compound rule
						required: true,
						email: true
					},
					cstVerify: {
					equal: 11	
				}
			}
		});
		
	});


function submitcontactform(){
	
	var cstName = jQuery("#cstName").val();
	var cstEmail = jQuery("#cstEmail").val();
	var cstTel = jQuery("#cstTel").val();
	var cstCompany = jQuery("#cstCompany").val();
	var cstEnquiry = jQuery("#cstEnquiry").val();
	
	var encodedName = encodeURIComponent(cstName); 
	var encodedEmail = encodeURIComponent(cstEmail); 
	var encodedTel = encodeURIComponent(cstTel);
	var encodedCompany = encodeURIComponent(cstCompany); 
	var encodedEnquiry = encodeURIComponent(cstEnquiry); 
	
	var dataString = 'cstName='+ encodedName + '&cstEmail='+ encodedEmail + '&cstTel='+ encodedTel + '&cstCompany='+ encodedCompany + '&cstEnquiry='+ encodedEnquiry + '';

	
	$.ajax({
		type:"POST",
		url: "../includes/incBuildContactEmail.asp",
		dataType: "application/x-www-form-urlencoded",
		data: dataString,
		async: false,
		success: function(){
			$("#submitbutton").hide();
			$("#waiting").fadeIn(400);
			
			window.setTimeout(function() {
			 $(".form").hide();
			 $(".thanks").fadeIn(400);
			
			}, 2000);
			
			
	}
	
	})
}


$(function() {
	$("#subscribe").click(submitregform);
	$("#regFormThanks").hide();
});
function submitregform(){
	
	var cstFirstname = jQuery("#cstFirstName").val();
	var cstLastname = jQuery("#cstLastName").val();
	var cstEmail = jQuery("#cstRegEmail").val();
	
	var encodedFirstname = encodeURIComponent(cstFirstname); 
	var encodedLastname = encodeURIComponent(cstLastname); 
	var encodedEmail = encodeURIComponent(cstEmail); 
	
	var dataString = 'cstFirstname='+ encodedFirstname + '&cstLastname='+ encodedLastname + '&cstEmail='+ encodedEmail + '';

	
	jQuery.ajax({
		type:"POST",
		url: "/includes/incRegForm.asp",
		dataType: "application/x-www-form-urlencoded",
		data: dataString,
		async: false,
		success: function(){
			jQuery("#subscribe").hide();
			
			window.setTimeout(function() {
			 jQuery("#regForm").hide();
			jQuery("#regFormThanks").fadeIn(400);
			
			}, 2000);
			
			
	}
	
	})
}
