var tweetloaded = false;

$(document).ready(function() {
	$('#networklist li, #contactlist li').each(function (idx,e) {
		$(e).animate({
			opacity: 0.8
		}, 250);
		$(e).hover(
			function() {
				$(this).animate({
					opacity: 1,
					marginLeft: "20px",
				}, 250 );
			},
			function() {
				$(this).animate({
					opacity: .8,
					marginLeft: "0px"
				}, 250 );
			}
		);
	});
	
	$('#c-contact p').hover(
		function() {
			$(this).animate({
				opacity: 1,
			}, 250 );
		},
		function() {
			$(this).animate({
				opacity: .6,
			}, 250 );
		}
	);
	
	$('.vcard-link').hover(
		function() {
			$('.vcard-tooltip').animate({opacity: 0.7}, 250);
		},
		function() {
			$('.vcard-tooltip').animate({opacity: 0}, 250);
		}
	);
	
	$('#nav li a').each(function () {
		$(this).mousedown(function(){
			$(this).animate({
				color: '#aaa',
				marginTop: '1px'
			}, 100);
		});
		$(this).mouseup(function(){
			$(this).animate({
				color: '#fff',
				marginTop: '0px'
			}, 100);
		});

		$(this).click(function() {
			return false;
		});
		$(this).click(function() {
			toggleContent(this.rel);
		});
	});

	var qhash = window.location.hash
	toggleContent(qhash.replace(/#/,''));
	
	$('a').each( function() { $(this).attr('target', '_blank') });
});

var toggleContent = function (area) {
	offset = 0;
	if (area == '') area = 'networks';
	
	switch (area) {
		case "networks":
			document.title = "Networks of Stefan Pasch";
			break;
		case "about":
			document.title = "About Stefan Pasch";
			offset = 450;
			
			if (tweetloaded == false)
			{
				// load last tweet
				$.ajax({ url: "last-tweet.php", context: $('.tweet'), success: function(d, t, x){
					$(this).html(d);
					$(this).animate({
						opacity: 1
					}, 400);
				}});
				tweetloaded = true;
			}
			break;
		case "contact":
			document.title = "Contact Stefan Pasch";
			offset = 900;
			break;
		default:
			document.title = "Stefan Pasch";
			break;
	}
	
	$('#inner').animate({
		top: '-' + offset + 'px'
	}, 900, 'easeOutElastic');
	
	window.location.hash = area;
	
	// set correct nav item
	$('#nav li a').each(function () {		
		$(this).removeClass('active');
	});
	$('#navitem-'+area).addClass('active');
}
