$(document).ready(function() {
	init_postit();
});

//////////////////////////////////////////
//POSTIT
// waits x seconds and slides a postit note onto the screen
// after the note is closed by the user a cookie is set
// which causes it not to be shown again
// all times are in milliseconds
//////////////////////////////////////////
// config
postit_waittime = 5000;
postit_animatetime = 3000;
postit_timebeforeclose = 10000;
////
function init_postit() {
	hidepostit = readCookie("hidepostit");
	if ( hidepostit == null || hidepostit != "true" ){
		//POSTIT REVEAL
		if ( $("#postit").css("display") != "none" ){
			//$("#postit").css("display",""); //unhide postit
			//slide in
			$("#postit").animate({ left: '-500px' } ,postit_waittime)
					.animate({ left: '460px' } ,postit_animatetime, function() {
						setTimeout("closepostit()",postit_timebeforeclose);
					}
			);
		}
		//END POSTIT REVEAL	
	}
}

//close postit display
function closepostit(){
	$("#postit").css("display","none");
	return false;
}
function closepostitwcookie(){
	createCookie("hidepostit","true",7,0);
	$("#postit").css("display","none");
	return false;
}

function createCookie(name,value,days,hours) {
	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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

