$(document).ready(function()
{
	// clone the nav and rename it
	var clonenav = $('ul#nav-main').clone();
	clonenav.attr('id','nav-decoration');
	$('ul#nav-main').before(clonenav);
	
	// add the main nav hover states
	var navover = function(e)
	{
		var t = e.target;
		if(t.nodeName.toLowerCase() == 'a')
		{
			var p = $(t);
			var classname = p.attr('class');
			$('ul#nav-decoration li').removeClass('falsehover');
			$('ul#nav-decoration li.'+classname).addClass('falsehover');
		}
	}
	var navout = function(e)
	{
		var t = e.target;
		if(t.nodeName.toLowerCase() == 'a')
		{
			var p = $(t);
			var classname = p.attr('class');
			$('ul#nav-decoration li.'+classname).removeClass('falsehover');
		}
	}
	$('ul#nav-main a').hover(navover,navout);
	
	// add the additional elements to the cloned nav
	$('li a',clonenav).append('<span class="nav-dec dec-left">&nbsp;</span>');
	$('li a',clonenav).append('<span class="nav-dec dec-right">&nbsp;</span>');
	clonenav.append('<li class="nav-dec dec-left">&nbsp;</li>');
	clonenav.append('<li class="nav-dec dec-right">&nbsp;</li>');
	clonenav.append('<li class="nav-dec-overlay">&nbsp;</li>');
	clonenav.wrap('<div class="decoration-holder" />');
	
	// add captions to article images with alt text
	$('div.article-content > img, div.article > img, div.article-content > p > img, div.article > p > img').each(function()
	{
		var op = $(this);
		if(!op.hasClass('nowrap'))
		{
			var wrapper = $('<div class="wrapper-article-image '+(op.attr('className'))+'"/>');
			op.attr('className','');
			var img = op.wrap(wrapper);
			wrappercopy = img.parent();
			
			wrappercopy.hide();
			wrappercopy.width(wrappercopy.parent().width());
			wrappercopy.show();
			
			if(op.attr('alt') != '')
			{
				img.after('<span>'+op.attr('alt')+'</span>');
			}
		}
	});
	
	// set up the galleries
	$('ul.menu-gallery').SaltGallery({speed: 1000, easing: 'easeInOutQuint'});
	$('ul.hp-gallery').SaltGallery({
				speed: 2000,
				autorun: true,
				timeout: 3000});
	
	// wrap all HRs
	$('hr').wrap('<div class="hr">&nbsp;</div>');
});















jQuery.extend( jQuery.easing,
{
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	}
});
