$(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("subhover");
					}, function(){ //On Hover Out
				$(this).parent().removeClass("subhover");
				});
});

$(function() {
		   
		  $("ul.examples li .innerdiv a").hover(function() {
				
				$(this).parent().find(".caption").slideDown('fast')
					$(this).parent().hover(function() {
					}, function(){
						$(this).parent().find(".caption").slideUp('fast')
					});
				})
		   

});



$(function() {
jQuery(".tweet").tweet({
          join_text: "auto",
          username: "untiedshoes",
          avatar_size: null, 
          count: 3,
          join_text: "we said,",
          auto_join_text_ed: "we",
          auto_join_text_ing: "we were",
          auto_join_text_reply: "we replied",
          auto_join_text_url: "we were checking out",
          loading_text: "loading tweets..."
        });
});

$(function() {
	$('hr').wrap('<div class="hrReplacement" />');
});
$(function() {
	$('#content_left table').wrap('<div class="table_wrap" />');
});
$(function() {
	$('.contentBlock').wrap('<div class="contentBlockWrapper" />');
	$("table.removeMe").replaceWith('<div class="contentBlock">' + $(".contentBlock").html() + '</div>');
	$("table.removeMe").detach();
});

$(function() {
	$('#formWrapper').load('/includes/library/incContactForm.asp');
});
$(function() {
	$('.latestNews div').load('/includes/library/incSideArticlesList.asp');
});
$.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);
			
			
	}
	
	})
}


