$.fn.equals = function(compareTo)
{
	if (!compareTo || !compareTo.length || this.length!=compareTo.length)
	{
		return false;
	}
	for (var i=0; i<this.length; i++)
	{
		if (this[i]!==compareTo[i])
		{
			return false;
		}
	}
	return true;
}

jQuery(document).ready(function()
{
	jQuery(".navigation").each(function()
	{
		jQuery(this).find("ul ul").parent().addClass("subnav");
		jQuery(this).find("ul li.subnav").each(function()
		{
			jQuery(this).find("a:first").bind("click", function() { return false; });
		});
		jQuery(this).find("ul li.subnav:not(ul ul li)").append("<span class='downarrow'></span>");
		jQuery(this).find("ul li.subnav li.subnav").append("<span class='expandarrow'></span>");
		jQuery(this).find("ul li.subnav li:not(.subnav)").append("<span class='singlearrow'></span>");
	});
	
	jQuery(".sidebar").each(function()
	{
		jQuery(this).find("ul li ul").each(function()
		{
			jQuery(this).parent().find("a:first").click(function() { jQuery(this).parent().toggleClass("current_page_ancestor"); return false; })
		});
		
		jQuery(this).find(".archive li.current_page_item").parent().parent().addClass("current_page_ancestor");
	});
	
	jQuery("a.print_this_page").click(function()
	{
		window.print();
		return false;
	});
	
	jQuery(".breadcrumbs a").not(":first").each(function()
	{
		jQuery(this).click(function()
		{
			return false;
		});
	});
	
	if (jQuery.browser.msie && jQuery.browser.version.substr(0,1) < 7)
	{
		jQuery(this).find("ul ul ul li .singlearrow").remove();
		jQuery(".navigation ul ul:not(ul ul ul)").each(function()
		{
			jQuery(this).width(jQuery(this).parent().width());
		});
		
		jQuery(this).find("ul ul li").hover(
			function()
			{
				jQuery(this).find("a:first").addClass("ie6hover");
			},
			function()
			{
				jQuery(this).find("a:first").removeClass("ie6hover");
			}
		);
	}
	
	jQuery('a[href*=#]').click(function()
	{
		// duration in ms
		var duration=1000;
	
		// easing values: swing | linear
		var easing='swing';
	
		// get / set parameters
		var newHash=this.hash;
		var target= 0; //jQuery(this.hash).offset().top;
		var oldLocation=window.location.href.replace(window.location.hash, '');
		var newLocation=this;
	
		// make sure it's the same location      
		if(oldLocation+newHash==newLocation)
		{
			// animate to target and set the hash to the window.location after the animation
			jQuery('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
	
				// add new hash to the browser location
				window.location.href=newLocation;
			});
	
			// cancel default click action
			return false;
		}
	});
});