window.log = function(){
  log.history = log.history || [];  
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});


// jQuery plugin for setting the class of a particular element to "current" based on the current page.
// Useful for navigation menus that are part of a server side include for the whole site.
//
// By Rob Watts, http://tractionsys.com
// Version 1.3, May 10, 2011
// Provided under the MIT license. Feel free to use it however you like.
//
// Example:
// $("ul.nav a").currentPage();
//
// To override defaults, pass in a defaults object:
// $("ul.nav a").currentPage({
//    attr: "href",
//    defaultClass: "selected",
//    indexPage: ""
// });

function getPage() {
  var href = window.location.href;
  var host = window.location.host;
  var pos = href.indexOf(host);
  var url = href.substring(pos + host.length);


  if ( url.charAt(0) == "/" )
    url = url.substring(1, url.length);

  return url;
}


jQuery.fn.currentPage = function(options) {
  var currentPage = "";
  var thisClass = "";
  var thisHref = "";
  var settings = jQuery.extend({
    defaultClass: "current",       // Default class to add to current link
	attr: "href",              // Default attribute to compare with current page URL (not usually used)
	appendToFirstClass: false, // Append the defaultClass to the first class on the element.
	                              // E.g. class="monkey" becomes class="monkey monkeycurrent"
	indexPage: "/",            // Default index page (to make current when page is not shown in URL)
	anyPath: false             // Ignore the path (supports pages in subfolders, and triggers on filename alone)
	}, options);
  
  currentPage = getPage();

  if ( (currentPage == "") || ( settings.anyPath && (currentPage.indexOf("/") == currentPage.length-1) ) )
    currentPage = settings.indexPage;

  this.each(function() {
      thisHref = $(this).attr(settings.attr);
      thisClass = "";

      if ( (thisHref == currentPage) || ( settings.anyPath && ( ( currentPage.indexOf(thisHref) > -1 ) && ( currentPage.indexOf(thisHref) + thisHref.length == currentPage.length ) ) ) ) {
	if (settings.appendToFirstClass) {
	  if ( $(this).attr("class") )                        // Conditional to support jQuery 1.6
	    thisClass = $(this).attr("class").split(" ")[0];  // Choose the first class (if multiple classes defined)
	  thisClass = thisClass + settings.defaultClass;      // Append the default current class to the first class class
	}
	else 
	  thisClass = settings.defaultClass;

	$(this).addClass(thisClass);
      }
    });
};
