(function($){
	
	$.fn.extend({
		
		rollover: function( overSuffix ) {
			
			var overSuffix = overSuffix || '_ov';
			
			this.each(function(){
				var src = $(this).attr('src');
				var osrc = src.replace(/(\.[a-z]+?$)/, overSuffix + '$1');
				(new Image).src = osrc;
				$(this).bind('mouseover.rollover', function(){
					$(this).attr('src', osrc);
				}).bind('mouseout.rollover', function(){
					$(this).attr('src', src);
				})
				.parent('a').bind('focusin.rollover', function(){
					$(this).find('img').attr('src', osrc);
				}).bind('focusout.rollover', function(){
					$(this).find('img').attr('src', src);
				});
			});
			
			return this;
		},
		
		smoothScroll: function( animateOptions ) {
			
			var top = 0;
			
			// from jQuery Easing
			// http://gsgd.co.uk/sandbox/jquery/easing/
			$.easing.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;
			};
					
			var animateOptions = $.extend({
				duration: 420,
				easing: 'easeInOutExpo'
			}, animateOptions);
			
			this.each(function(){
				$(this).bind('click.somoothScroll', function(){
					if ( top == 0 && $(window).scrollTop() == 0 ) return false;
					var hash = $(this).attr('href');
					if ( hash.match(/^#/) ) {
						var elemTop = $(hash).offset().top;
						var winHeight = $(window).height();
						var bodyHeight = $(document).height();
						if ( elemTop + winHeight > bodyHeight ) {
							var top = bodyHeight - winHeight;
						} else {
							var top = elemTop;
						}
						animateOptions.complete = function() {
							if ( $(window).scrollTop() == 0 || hash == "#pageTop" ) {
								location.hash = '';
							} else {
								location.hash = hash;
							}
						};
						$('html, body').animate({'scrollTop': top}, animateOptions);
						return false;
					} else {
						return true;
					}
				});
			});
			
			return this;
		}
		
	});
	
	$(function(){
	
		$('.rollover').rollover();
		$('#toPageTop a, .pageNav a, a.smoothScroll').smoothScroll();
		
		if ( $.cookie ) {
			// change font size
			if( $.cookie('fontSize') ){
				fontSizer($.cookie('fontSize'));
			}
			$('#fontSizer a').click(function(){
				var size = this.href.match(/=(.+$)/)[1];
				fontSizer(size);
				return false;
			});
			function fontSizer( size ) {
				$('link[rel^=alternate]').each(function(){
					this.disabled = true;
				});
				$('link[title='+size+']')[0].disabled = false;
				$.cookie('fontSize', size, { expires: 30, path: '/' });
			}
		}
		
		if ( $.browser.msie && $.browser.version <= 8.0 ) {
			$('.link-blank').removeClass('link-blank')
				.append('<span class="link-blank msie">&nbsp;</span>');
		}
	});
	
})(jQuery);






