function SiteNav (options) { //anchor_selector, url, content_selector, load_img_src) {
	this.url = options.url;
	this.content_selector = options.content_selector || 'div#content';
	this.anchor_selector = options.anchor_selector || 'ul#nav li a';
	this.load_img_src = options.load_img_src || false;
	this.selected_class = options.selected_class || 'selected';
	this.onPageLoad = options.onPageLoad || new Object();
	
	if ( this.load_img_src ) {
		this.load_img = $('<img src="'+this.load_img_src+'" />');
		$('body').prepend('<div style="display: none"><img src="'+this.load_img_src+'" /></div>');
	}
}
SiteNav.prototype.init = function () {
	var _this = this;
	$(_this.anchor_selector).click(function () {
		var pageName = $(this).attr('href').replace('#', '');
		_this.changePage(pageName);
		$(this).parents('ul').find('a').removeClass(_this.selected_class);
		if ( $(this).parents('ul:first').hasClass('sub-nav') ) {
			$(this).parents('ul:first').prev('a').addClass(_this.selected_class);
		} else {
			$(this).addClass(_this.selected_class);
		}
	});
	$('ul.sub-nav').each(function () {
		$(this).parent().eq(0).hoverIntent({
			timeout: 100,
			over: function () {
				var current = $('.sub-nav:eq(0)', this);
				current.slideDown(300);
				current.css('opacity', .85);
			},
			out: function () {
				var current = $('.sub-nav:eq(0)', this);
				current.fadeOut(400);
			}
		});
		$(this).find('li a').hover(function () {
				$(this).animate({'font-size': '17px'}, 200);
			}, function () {
				$(this).animate({'font-size': '14px'}, 200);

		}).click(function () {
			$(this).parents('ul').eq(0).slideUp();	
		});
	});
}

SiteNav.prototype.changePage = function (pageName) {
	var _this = this;

	var params = {
		action: 'page',
		page_name: pageName
	};
	
	$(_this.content_selector).slideUp(500, function () {
		$(_this.content_selector).css('display', 'none').html('').append(_this.load_img).slideDown(500, function () {
			$.post(_this.url, params, function (response) {
				$(_this.content_selector).slideUp(500, function () {
					$(_this.content_selector).html(response).slideDown(500, function () {
						if ( 'function' == typeof _this.onPageLoad[pageName] ) {
							_this.onPageLoad[pageName](_this.content_selector);
						}
					});
				});
			});
		});
	});
}

