$(document).ready(function() {

	$.fn.clearQueue = $.fn.unpause = function(type) {
		return this.each(function(){
			type = type || "fx";
			if(this.queue && this.queue[type]) {
				this.queue[type].length = 0;
			}
		});
	};

	// Smooth scrolling to anchor elements with #reference
  function filterPath(string) {
  return string
	.replace(/^\//,'')
	.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
	.replace(/\/$/,'');
  }
  var locationPath = filterPath(location.pathname);
  $('a[href*=#]').each(function() {
	var thisPath = filterPath(this.pathname) || locationPath;
	if (  locationPath == thisPath
	&& (location.hostname == this.hostname || !this.hostname)
	&& this.hash.replace(/#/,'') ) {
	  var $target = $(this.hash), target = this.hash;
	  if (target) {
		var targetOffset = $target.offset().top;
		$(this).click(function(event) {
		  event.preventDefault();
		  $('html, body').animate({scrollTop: targetOffset}, 500, function() {
			location.hash = target;
		  });
		});
	  }
	}
  });

	//IE6 PNGFIX
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}

	jQuery.validator.messages.required = "";
	$(".validate").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = '<span class="input-notification error png_bg">Required field(s) are empty or invalid</span>'
				$("#response").html(message);
			} else {
				$("#response").empty();
			}
		}
	});
	
	jQuery.validator.addMethod("alphanumeric", function(value, element) {
	return this.optional(element) || /^[a-z0-9 ]+$/i.test(value);
	}, "Letters, numbers and spaces only please");

	jQuery.validator.addMethod("numeric", function(value, element) {
	return this.optional(element) || /^[0-9.]+$/i.test(value);
	}, "Numbers only please");

	function clearConsole() {
		if (window.console && window.console.firebug) {
			console.clear()
		}
	}
	

	$('.image-small img').click(function(e) {
		e.preventDefault();
		img = $(this).attr("src").replace("t.jpg", ".jpg");
		alt = $('#content h1').text();
		$("#placeholder img").replaceWith('<img src="'+img+'" alt="'+alt+'" />');
	});


	$('.track').click(function() {
		clicky.goal('855');
		clearConsole();
	});
});