var clickedmenuitem = '';
var basetitle = '';
var fxeasing = 'easeInOutExpo';
var fxspeed = 800;

//normal, hover, selected
var menucolors = ["#111b2d","#263a5d","#5a1c29"];

initUI = function(item) {
	$('#menu').slideDown(fxspeed*1,fxeasing);
	$(item).show();
	$("#content").slideDown(fxspeed*1,fxeasing);
	
	clickedmenuitem = item;	
	//$("#menu ul li a[href="+item+"]").parent().css({'background-position': '0px -56px'});
	$("#menu ul li a[href="+item+"]").css({'background-color': menucolors[2]});
}

_slideContentDown = function(sel) { 
	($('#networks').css('display') != 'none') && $('#networks').hide();
	($('#contact').css('display') != 'none') && $('#contact').hide();
	($('#about').css('display') != 'none') && $('#about').hide();
	($('#twitter').css('display') != 'none') && $('#twitter').hide();
	($('#resume').css('display') != 'none') && $('#resume').hide();
	$(sel).show();
	$('#content').slideDown(fxspeed,fxeasing);
}

slideContentDown = function(sel) {
	$('#content').slideUp(fxspeed,fxeasing);
	setTimeout('_slideContentDown("'+sel+'")',fxspeed);
	switch (sel) {
		case "#contact":
			document.title = basetitle + ' :: Contact Information';
			break;
		case "#networks":
			document.title = basetitle + ' :: Social Networking';
			break;
		case "#twitter":
			document.title = basetitle + ' :: Twitter Feed';
			break;
		case "#resume":
			document.title = basetitle + ' :: R\u00E9sum\u00E9';
			break;
		case "#about":
		default:
			document.title = basetitle + ' :: About';
			break;
	}
}
menubtn_Hover = function() { 
	//if ($(this).attr('href') != clickedmenuitem) $(this).parent().css({'background-position': '0px -28px'});
	if ($(this).attr('href') != clickedmenuitem) $(this).stop().animate({backgroundColor: menucolors[1]},fxspeed/2,fxeasing);
}
menubtn_Out = function() { 
	//if ($(this).attr('href') != clickedmenuitem) $(this).parent().css({'background-position': '0px 0px'});
	if ($(this).attr('href') != clickedmenuitem) $(this).stop().animate({backgroundColor: menucolors[0]},fxspeed/2,fxeasing);
}
menubtn_Click = function() {
	$('li[id*=menu] a').each(function() {
		//$(this).parent().css({'background-position': '0px 0px'});
		//$(this).animate({backgroundColor: '#111b2d'},fxspeed/2,fxeasing);
		$(this).css({'background-color': menucolors[0]});
	});
	slideContentDown($(this).attr('href')); 
	//$(this).parent().css({'background-position': '0px -56px'});
	//$(this).animate({backgroundColor: '#5a1c29'},fxspeed/2,fxeasing);
	clickedmenuitem = $(this).attr('href');
	$(this).stop().css({'background-color': menucolors[2]});

}

$(document).ready(function() {
	//these are set up this way so the page is still understadable for people *without* javascript	
	$('#about').hide();
	$('#networks').hide();
	$('#twitter').hide();
	$('#contact').hide();
	$('#resume').hide();
	$('#content').hide();
	$('#resume .section .data').hide();
	//$('#resume .section .title').css({'cursor':'pointer'}).click(function() { $(this).next().slideToggle(fxspeed,fxeasing); });
	$('#resume .section h2').css({'cursor':'pointer'}).click(function() { $(this).next().toggle(); });
	$('#logotext').css({'background-position': '-173px 0px'});
	$('#logotext').animate({backgroundPosition: '0px 0px'},fxspeed,fxeasing);
	$('#logoselfpic').css({'opacity':'0'});
	$('#logoselfpic').animate({opacity: '100'},fxspeed*2,'easeInQuint');
	
	//For anyone reading my code, if you want the above opacity easing support for internet
	//explorer, you would need to enable these two lines. it's disabled due to my design using
	//a transparent PNG image, which leaves visible artifacts when using IE's filters.
	//This is a known bug from Microsoft. Hey, at least they DID add PNG transparency support, we 
	//cannot complain :)
	//$('#logoselfpic').css({'filter':'alpha(opacity = 0)'});
	//$('#logoselfpic').animate({filter: 'alpha(opacity = 100)'},fxspeed*2,'easeInQuint');
	
	switch (window.location.hash) {
		case '#about':
		case '#networks':
		case '#contact':
		case '#twitter':
		case '#resume':
			setTimeout('initUI("'+window.location.hash+'")',1200);
			break;
		case '': //landed somewhere else, unsupported. fallback to default
		default: 
			setTimeout('initUI("#about")',1200);
	}
	basetitle = document.title;
	$('li[id*=menu] a').click(menubtn_Click).hover(menubtn_Hover,menubtn_Out);
	$('a[class=inpagelink]').click(function() {
		var href = $(this).attr('href');
		$('li[id*=menu] a').each(function() {
			if ($(this).attr('href') == href) { 
				//$(this).parent().css({'background-position': '0px -56px'});
				$(this).css({'background-color': menucolors[2]});
			}
			else { 
				//$(this).parent().css({'background-position': '0px 0px'});
				$(this).css({'background-color': menucolors[0]});
			}
		});
		slideContentDown($(this).attr('href')); 
		clickedmenuitem = $(this).attr('href');
	});
	$('#twitter_div').append('<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script><script type="text/javascript" src="http://twitter.com/statuses/user_timeline/bilange.json?callback=twitterCallback2&count=20"></script>');
});

