/*
 * Common Javascript functions for LINGUIST web site
 * Written by Joshua M. Thompson <joshua@linguistlist.org>
 *
 * Please make sure any functions you add here are added under
 * the LINGUIST namespace.
 */

// Generate our namespace if it doesn't exist already

Ext.namespace('LINGUIST');

// Page initialization function, called when document first loads.

LINGUIST.init = function() {
	var el = Ext.get('breadcrumbs');

	if (el != null) {
		this.dropCrumbs(el);
	}
}

// Generate breadcrumbs and set them as the new content for the passed element

LINGUIST.dropCrumbs = function(el) {
	var loc	   = document.location;
	var path   = loc.pathname.split('/');
	var url	   = loc.protocol + '//' + loc.hostname;
	var crumbs = new Array();

	// If pathname has a trailing slash (including the case where the pathname
	// is simply "/") then there will be an unwanted empty string at the end of
	// the path array. This removes it.

	/* if (path[path.length - 1] == '') {
		path.pop();
	}

	// Now we just loop through the elements of the pathname and generate a
	// crumb for each one.

	for (var i = 0 ; i < path.length ; i++) {
		var page = path[i];
		var title;

		if (page == '') {
			title = 'Home';
		} else {
			title = page;

			url = url + '/' + page;
		}

		crumbs.push('<a href="' + url + '">' + title + '</a>');
	}

	el.update('<span class="breadcrumbs">' + crumbs.join('&nbsp;&gt;&nbsp;') + '</span>');*/
}

Ext.onReady(LINGUIST.init, LINGUIST, true);
