// Set up console logging functions

if (!window.console) console = {};
console.log = console.log || function(){};
console.warn = console.warn || function(){};
console.error = console.error || function(){};
console.info = console.info || function(){};



// Slideshow on home page

$(document).ready(function() {
	$("#slideshow ul").cycle({
		delay: 4000,
		speed: 500,
		timeout: 8000
	});
});



// make tabs have highlight when currently selected

$(document).ready(function() {

	var pathName = parseUri(window.location);
   // console.log("Current page is " + pathName.path);
   // console.log("Current host is " + pathName.host);

   $('a.menulink').each(function() {
      var linkName = parseUri($(this).attr('href'));
      // alert (linkName.host + " : " + pathName.host);
      
     // console.log("Processing: " + linkName.path + " at host " + linkName.host);

      if (linkName.path == pathName.path && (pathName.host == "" || linkName.host == pathName.host)) {
         $(this).addClass("current");
      };
   });

});


// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};


