// JavaScript Document



$(document).ready( function() {
	
	function setcontent(a) {
		var p = document.URL.split("#")[1];
		var c = $('#content_' + p).length;
		
		if(!a&&c==0){
			a = 'home';
			$('.content').hide();
			$('#content_' + a).show();
			var na = a.substr(0,1).toUpperCase() + a.substr(1);
			var t = document.title.split('-')[0];
			var nt = t + ' - ' + na;
			document.title = nt;
		}else if(!a&&c>0){
			a = p;
			$('.content').hide();
			$('#content_' + a).show();
			var na = a.substr(0,1).toUpperCase() + a.substr(1);
			var t = document.title.split('-')[0];
			var nt = t + ' - ' + na;
			document.title = nt;
		}else{
			$('.nav a').css('background-position', '0 0');
			$('.content').fadeOut('slow');
			$('#content_' + a).fadeIn('slow');
			var na = a.substr(0,1).toUpperCase() + a.substr(1);
			var t = document.title.split('-')[0];
			var nt = t + ' - ' + na;
			document.title = nt;
		};
		
		$('#nav_' + a + ' a').css('background-position', '0 44px');
		
	};
	
	function setfooter() {
		
		var limit = 320;
		var dh = $(document).height();
		var rh = $('#upper').height() + $('#footer').height();
		var ch = dh -rh;
		
		if(ch<limit){ ch = limit; };
		
		$('#content').height(ch);
	
	};
	
	$(window).bind('resize', function() { setfooter(); } );
	
	$('.nav a')

		.bind('mouseover', function() {
			 var t = $(this);
			 t.css('background-position', '0 44px');
		})
		.bind('mouseout', function() {
			var t = $(this);
			var r = t.attr('href').split('#')[1];
			var c = $('#content_' + r).css('display');
			
			if(c!='block'){
				t.css('background-position', '0 0');
			}
		})
		.bind('click', function() {
			var t = $(this);
			var a = t.attr('href').substr(1);
			var d = $('#content_' + a).css('display');
			
			if(d!='block'){ setcontent(a); };
		});
	
	
	setfooter();
	setcontent();
	
});
