function show_tab()
{
	key = "tab" + this.firstChild.nodeValue;
	
	// find the previously selected tab and de-select it
	$('#sidebar_tabs li.selected').removeClass('selected');
	$('#sidebar_content div.selected_content').attr('class', 'content');
	
	// set the tab to selected
	$('#' + key).attr('class', 'selected_content');
	
	$(this).parent().attr('class', 'selected');
	return false;
}

function increase_font() // aka large
{
  $('body').addClass('largeFont');
	set_font_size(1.2);
	return false;
}

function increasemore_font() // aka medium
{
  $('body').removeClass('largeFont');
	set_font_size(1.3);
	return false;
}
function reset_font() // aka medium
{
  $('body').removeClass('largeFont');
	set_font_size(1);
	return false;
}
function set_font_size(f)
{
 // if (parseInt(f) < 1) {
//    f = 1;
 // }
/*	document.documentElement.style.fontSize = f;
	document.body.style.fontSize = f;*/
	$('body').css('font-size', f + 'em');
	createCookie('font_size', f, 365);
}

/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/

function switchStylestyle(styleName)
{
	$('link[@rel*=style][@title]').each(function(i) {
		this.disabled = true;
		if (this.getAttribute('title') == styleName) this.disabled = false;
	});
	createCookie('style', styleName, 365);
}

$(function() {
	var p = location.pathname.split('/');
	
  if (location.pathname == '/') {
	  $('#navigation li:first').addClass('selected');
	} else {  	
  	// side nav
  	$('#sidebar_tabs A').each(function(){ 
  	  if (this.pathname == '/' || !this.pathname) return;
  	  if (location.href == this.href) {
  	    $(this).parent('li').addClass('selected');
  	  }
  	}); 
	}
	
	
	// preloaded style
	var c = readCookie('style');
	if (c) switchStylestyle(c);
	var f = readCookie('font_size');
	if (f) set_font_size(f);
	if (f && f > 1) $('body').addClass('largeFont');

	// click hooks
	$('#ctlIncreaseFont').click(increase_font);
	$('#ctlDecreaseFont').click(increasemore_font);
	
	$('a.ctlStyleSwitcher').click(function(){ 
	  switchStylestyle(this.getAttribute("rel")); 
	  return false;	
  });
  
  $('#logo').click(function() { window.location = '/'; });
  $('label.over').labelOver();  
 // $('#projectImages').miniGallery({ x: 200, y: 25, width: 43, height: 42 });
});

jQuery.fn.labelOver = function() {
	return this.each(function(){
		var t = $(this);
		var f = t.attr('for');
		if (f) {
			var input = $('#' + f);
			var inputE = input[0];
			var tE = this;
						
			t.width('0px');
			// float to the right to allow the input box to take the label's place
			t.css('float', 'right'); 
			
			var left = inputE.offsetLeft - tE.offsetLeft + 2;
			
      // handle padding and borders - don't look at margin since this is outside			
			var pl = parseFloat(input.css('padding-left'));
			var bl = parseFloat(input.css('border'));
			
			if (pl.toString() != 'NaN') left += pl;
			
			// FIXME - can't read borders...
      // if (bl.toString() != 'NaN') left += bl;
			
			t.css({ 
				left: left,
				top: '3px',
				'font-size': '90%',
				position: 'relative',
				'margin-top': parseFloat(input.css('padding-top')) });
			
			input.focus(function() {
				t.css({ left: -10000 });
			});
			
			t[0].onclick = function() { input.focus(); };

			input.blur(function() {
				if (inputE.value == '') {
					t.css({ left: left });
				}
			});
			
			if (inputE.value != '') t.css({ left: -10000 });
		}
	});
};