var Ruben = Ruben ? Ruben : function() {
	var speed = 600;

	var padNumber = function(num) {
		return (num <= 9) ? "0"+num : num;
	}

	function loadAgenda() {
		// build query for agenda
		var query = new google.gdata.calendar.CalendarEventQuery("http://www.google.com/calendar/feeds/rubenverkuylen@gmail.com/public/full");
		query.setOrderBy("starttime");
		query.setSortOrder("ascending");
		query.setFutureEvents(true);

		// send query to calendar service
		var service = new google.gdata.calendar.CalendarService("rubenverkuylen-agenda-1");
		service.getEventsFeed(query, function(r) {
			$.each(r.feed.getEntries(), function() {
				var start = this.getTimes()[0].getStartTime().getDate();
				var time = padNumber(start.getDate()) + "/" + padNumber(start.getMonth()+1) + "/’" + start.getFullYear().toString().substr(2,2);
				$("#dj").next().find("table").append("<tr><td>" + time + "</td><td>" + this.getTitle().$t + "</td><td>" + this.getLocations()[0].getValueString() + "</td></tr>");
			});
		}, function() {});
	}

	return {
		Init: function() {
			$("div").css({display: "none", opacity: 0, left: "270px"}); // make sure portfolio is hidden

			$("#logo,#ikben").click(function(event) { // click logo and title...
				window.location.hash = "#"; // ... go to root
			});

			$("a[href^='#']").click(function(event) {
				if (window.location.hash == $(event.target).attr("href")) { // if click on current content...
					window.location.hash = "#"; // ... go to root
					event.preventDefault(); // but don't click
				}
			});

			$("div").click(function(event) {
				window.location.hash = "#ontwerper"; // go back from portfolio
			});

			$.address.change(function(event) {
				var which = window.location.hash;
				if (which != "#portfolio") {
					$("div").animate({opacity: 0, left: "210px"}, speed*1.4, function(event) { // fade out portfolio
						$("div").css({display: "none", left: "270px"});
					});
					$("h1").not(which).next().slideUp(speed); // slide up all content, except...
					$(which).next().slideDown(speed); // ... the one which slides down
				} else {
					$("div").css({display: "block"}).animate({opacity: 1, left: "240px"}); // fade in portfolio
				}
			});

			loadAgenda();

			$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target", "_blank");
		},

		InitOld: function(h) {
			$("div").css({display: "none", opacity: 0, left: "270px"});

			$("#logo,#ikben").click(function(event) {
				window.location.hash = "#";
				$("h1").next().slideUp(speed);
			});

			// if href starts with #, href is internal url
			$("a[href^='#']").not("a[href='#portfolio']").click(function(event) {
				var which = $(event.target).attr("href");
				$("h1").not(which).next().slideUp(speed);
				$(which).next().slideToggle(speed);
			});

			$("a[href='#portfolio']").click(function(event) {
				$("div").css({display: "block"}).animate({
					opacity: 1,
					left: "240px"
				});
			});

			$("div").click(function(event) {
				$("div").animate({
					opacity: 0,
					left: "210px"
				}, speed*1.4, function(event) {
					$("div").css({
						display: "none",
						left: "270px"
					});
				});
				window.location.hash = "#ontwerper";
			});

			if (h == "#portfolio") {
				$("a[href='#ontwerper']:first").click();
				$("a[href='#portfolio']:first").click();
			}
			else {
				$("h1").not(h).next().slideUp(speed);
				$(h).next().slideToggle(speed);
			}
		}
	}
}();
