/*
 * roNav - Dynamic, Ajaxy Navigation for the Random Oddness website.
 *
 * Copyright (c) 2009 Lee Stewart
 *
 */

//###lee - need mainNav and footerNav...

var ronavViewingArticle = false;
jQuery.roNav = {
	init: function(individualArticle) {
		if (individualArticle) {
			ronavViewingArticle = true;
		}
//		$('#main-nav li.ronav').addClass('active');

		$('#main-nav li.ronav').bind('click', function() {
			// If this.class is active, then just return false.
			//###lee - this is a bad check, breaks when viewing single articles...
			if (!ronavViewingArticle && $(this).hasClass('active')) {
				return false;
			}
			ronavViewingArticle = false;

			// Set up the "active" hilight and handle the cursor image:
            $('#main-nav li.ronav').removeClass('active');
			$(this).addClass('active');

            $('#main-nav li.ronav a').css('cursor', 'pointer');		// Hand
			$(this).find('a').css('cursor', 'default');				// Windows Arrow

			//###lee - if this is used, the URL isn't going to work with a mod_rewrite.
			//window.location.hash = $(this).find('a').attr('href');

			var atts = new Object();

			var section = $(this).find('a').text();
			atts['section'] = section.toLowerCase();

			if (section == 'ARCHIVES') {
			    atts['form'] = 'archives_month';
				atts['action'] = 'archives';

			} else if (section == 'WRITINGS') {
			    atts['form'] = 'default';
    			atts['action'] = 'article';

			} else {
			    atts['status'] = 5;
			    atts['form'] = 'static_w_title';
				atts['action'] = 'article';
			}
			$("#content").load("/ajax/", atts, function () {
				newContent();
				$('#content').fadeIn('slow');

			})

			// Remove the old content and put up a spinner.
			$("#content").fadeOut('slow');
//###lee - when the fadeOut() is done, display a spinner
			return false;
		});


	}
};
