/*
-----------------------------------------------------------------------------
TinyDucky.com JAVASCRIPT Styles

updated:		26 May 2009 
code author:	Clayton Farr
email:			contact@claytonfarr.com
-----------------------------------------------------------------------------*/

// columnize resources content (uses http://welcome.totheinter.net/columnizer-jquery-plugin/)
$(document).ready(function() {
	$('.favorites-group').addClass('dontsplit');
	$('.favorites div.favorites').columnize({columns: 3, lastNeverTallest: true });
	$('#recommended-reads .post').addClass('dontsplit');
	$('.recommended #recommended-reads').columnize({columns: 2, lastNeverTallest: true });
});

/* add active class ('current') to currently displayed page */
$(function() {
	// Figure out the location based on the browser URL
	var path = location.pathname;

	// Set your homepage path here, eg. /index.php or /
	var home = "/";
	// Check the home link against the path and set the navigation accordingly. 
	if (path == home || path == "/") {
		// Note that the jQuery selector matches *only* the home link
		var $nav = $('.nav a[@href="' + home + '"]');
	} else {
		var $nav = $('.nav a[@href$="' + path + '"]');
	}

	// Add class to the current anchor and parent <li> elements
	$nav.addClass('current');
	$nav.parents("li").addClass('current-li').children("a").addClass('current');
});


/* add current page class(es) to the body element
(requires jQuery URL Parser plugin - http://projects.allmarkedup.com/jquery_url_parser/)*/
$(document).ready(function () {
	// grab url segments (= preceeding sections; currently hardcoded 6 levels deep)
	var segment1 = jQuery.url.segment(0); if (segment1 == null || segment1.match(".php" || ".html" || ".htm")) { var segment1 = ""};
	var segment2 = jQuery.url.segment(1); if (segment2 == null || segment2.match(".php" || ".html" || ".htm")) { var segment2 = ""};
	var segment3 = jQuery.url.segment(2); if (segment3 == null || segment3.match(".php" || ".html" || ".htm")) { var segment3 = ""};
	var segment4 = jQuery.url.segment(3); if (segment4 == null || segment4.match(".php" || ".html" || ".htm")) { var segment4 = ""};
	var segment5 = jQuery.url.segment(4); if (segment5 == null || segment5.match(".php" || ".html" || ".htm")) { var segment5 = ""};
	var segment6 = jQuery.url.segment(5); if (segment6 == null || segment6.match(".php" || ".html" || ".htm")) { var segment6 = ""};

	// grab file name if present
	var page = jQuery.url.attr("file");
 	if (page == null) { var page = ""};
	var page_name_length = page.indexOf(".php" || ".html" || ".htm");
	var page_name = page.slice(0,page_name_length);

	// add classes
	var home = "/";
	if (home == jQuery.url.attr("path")) {
		// add 'home' class if at base level
	    $("body").addClass("home");
	} else {
		// add section and page class(es) as needed
	    $("body").addClass(segment1 + ' ' + segment2 + ' ' + segment3 + ' ' + segment4 + ' ' + segment5 + ' ' + segment6 + ' ' + page_name);
	}
});
