$(document).ready(function() {
	// rollover effect
	var swap_function = function(obj) {
		var src = obj.attr('src');
		obj.attr('src',obj.attr('hsrc'));
		obj.attr('hsrc',src);
	};
	var init_function = function(obj) {
		if(!$(this).attr('hsrc')) {
			var src = obj.attr('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			obj.attr('hsrc',src.replace(ftype, '_o'+ftype));
		}
		swap_function(obj);
	};
	$('#nav li:not(.active) img').hover(
		function() { init_function($(this)); },
		function() { swap_function($(this)); }
	);
	$('#subnav li:not(.active) img').hover(
		function() { init_function($(this)); },
		function() { swap_function($(this)); }
	);
	
	// fixes anchor tags in the main content (issue with base href)
	$("#content-main a[href^='#']").click(function() {
		document.location.hash = $(this).attr('href');
		return false;
	});
	
	// font size adjuster (+/-)
	var setFontSize = function(size) {
		if(size < 11) {
			size = 11;
		} else if (size > 21) {
			size = 21;
		}
		$('#contents p').css('font-size',size);
		$.cookie("jeffreyhale-font-size",size);
	}
	var fontSize = $.cookie("jeffreyhale-font-size");
	if(fontSize) {
		setFontSize(parseFloat(fontSize,10));
	}
	$('#fontUp').click(function() {
		var cur_size = parseFloat($('#contents p').css('font-size'),10);
		setFontSize(cur_size+2);	
		return false;	
	});
	$('#fontDown').click(function() {
		var cur_size = parseFloat($('#contents p').css('font-size'),10);
		setFontSize(cur_size-2);	
		return false;	
	});
	
	// collapse inactive subnav trees
	$('#sidebar li .subcat').hide();
	$('#sidebar li.selected .subcat').show();
	
	// collapse all subnav trees in main content
	$('#content-main .categories li .subcat').hide();
	
	// all ULs without a class become 'basic'
	$('#content-main ul').each(function() {
		if($(this).attr('class').length == 0) {
			$(this).addClass('basic');
		}
	});
	
	// dev only modification of urls
	$('base').each(function() {
		var base_href = $(this).attr('href');
		$("#content-main a[href^='/assets']").each(function() {
			$(this).attr('href',base_href + $(this).attr('href').replace(/^\//,''));
		});
	});
});