$(document).ready(function() {
	var queryhash = window.location.hash
	switch (queryhash) {
		case "#social":
			document.title = "Benoit Pohl - Social";
			initialShowSocial();
			break;
		case "#about":
			document.title = "Benoit Pohl - About";
			initialShowAbout();
			break;
		default:
			initialShowSocial();
			break;
	}
	
	setInterval("settimer()", 1000);
	
	$("h2").hide();
	$("#vcard a").hover(showVcardLabel, hideVcardLabel);
	$("#nav-about a").click(showAbout);
	$("#nav-social a").click(showSocial);
});

function showVcardLabel() {
	$("#vcard a span").show();
	$("#vcard a span").animate({
		top: "-40px",
		opacity: 1
	}, 250 );
}

function hideVcardLabel() {
	$("#vcard a span").animate({ 
		top: "-35px",
		opacity: 0
	}, 250 );
	setTimeout("$('#vcard a span').hide();", 250);
	$("#vcard a span").animate({ 
		top: "-45px",
	}, 250 );
}

function initialShowSocial() {
	$("#content").hide();
	$("#benoitpohl").removeClass();
	$("#benoitpohl").addClass("social");
	$(".node").hide();
	$("#social").show();
	setTimeout("$('#content').slideDown('slow');", 1000);
}

function initialShowAbout() {
	$("#content").hide();
	$("#benoitpohl").removeClass();
	$("#benoitpohl").addClass("about");
	$(".node").hide();
	$("#about").show();
	setTimeout("$('#content').slideDown('slow');", 1000);
}

function showAbout() {
	if ($("#benoitpohl").hasClass("about")){ }
	else {
		document.title = "Benoit Pohl - About";
		$("#content").slideUp(500);
		$(".node").fadeOut(500);
		setTimeout("$('.node').hide();", 500);
		setTimeout("$('#about').show();", 500);
		$("#content").slideDown(500);
		$("#benoitpohl").removeClass();
		$("#benoitpohl").addClass("about");
	}
}

function showSocial() {
	document.title = "Benoit Pohl - Social";
	if ($("#benoitpohl").hasClass("social")){ }
	else {
		$("#content").slideUp(500);
		$(".node").fadeOut(500);
		setTimeout("$('.node').hide();", 500);
		setTimeout("$('#social').show();", 500);
		$("#content").slideDown(500);
		$("#benoitpohl").removeClass();
		$("#benoitpohl").addClass("social");
	}
}

function calcTime(city, offset) {

    d = new Date();
   
    // convert to msec
    // add local time zone offset
    // get UTC time in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
   
    // create new Date object for different city
    nd = new Date(utc + (3600000*offset));
   
    // return time as a string
    return nd; //"The local time in " + city + " is " + nd.toLocaleString();

}

function displayDate(curtime, seconds)
{
	var curhour = curtime.getHours();
	var curmin = curtime.getMinutes();
	var cursec = curtime.getSeconds();
	var time = "";
	
	if(curhour == 0) curhour = 12; 
	return (curhour > 12 ? curhour - 12 : curhour) + ":" +
	       (curmin < 10 ? "0" : "") + curmin + 
	       (seconds ? ":" + (cursec < 10 ? "0" : "") + cursec : "") + " " +
	       (curhour > 12 ? "PM" : "AM");
}

function settimer() {
 
	// get Paris time
	var paris = (calcTime('Paris', '+2'));
		// get Melbourne time
	var melbourne = (calcTime('Melbourne', '+10')); 
	
  	$("#userClock").text(displayDate(new Date(), true));
  	$("#parisClock").text(displayDate(paris, false));
  	$("#melbourneClock").text(displayDate(melbourne, false));
}



