$(document).ready(function()
{
	$('#highlight').innerfade(
	{
		speed: 1000,
		timeout: 6000,
		type: 'sequence',
		containerheight: '300px' 
	});
	
	$(window).keyup(function(event)
	{
		direction = null;
		
		if(event.keyCode == 37)
		{
			direction = "prev";
		}
		else if(event.keyCode == 39)
		{
			direction = "next";
		}
		
		if(direction !== null)
		{
			href = $("#menu a.active").parent()[direction]().find("a").attr("href");
			
			if(href !== null)
				window.location = href;
		}
	});
	
	$("a[href^=http://]").addClass("external").attr({ target: "_blank" });
	
	if(readCookie("notice") != "shown")
	{
		initNotice();
	}
});

function initNotice()
{
	var notice = '\
		<div id="notice">\
			<h2>Welcome at my portfolio,</h2>\
			<p>Try using the arrows on your keyboard to navigate arround. It will make browsing on my portfolio a lot easier!</p>\
			<p class="close">close</p>\
		</div>\
	';
	$("body").append(notice);
	
	$("#notice .close").click(hideNotice);
	setTimeout(showNotice,1000);
	createCookie("notice","shown",7);
}

function showNotice()
{
	$("#notice").animate({"top": "20px"}, 400, function() {
		setTimeout(hideNotice, 10000);
	});
}

function hideNotice()
{
	$("#notice").animate({"top": "-200px"}, 400);
}

function createCookie(name,value,days) {
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
