konami = new Konami()
konami.code = function() {
    setTimeout('startBeingCrazy()',200)
}
konami.iphone.code = function() {
    setTimeout('startBeingCrazy()',200)
}
konami.load()

function timeoutBackground(color,time){

	setTimeout("document.getElementById('sitebody').style.backgroundColor='"+color+"';",time);

}
function startBeingCrazy(){

	timeoutBackground("green",0);

	timeoutBackground("purple",25);

	timeoutBackground("orange",50);

	timeoutBackground("white",75);

	timeoutBackground("yellow",100);

	timeoutBackground("grey",125);

	timeoutBackground("navy",150);

	timeoutBackground("blue",175);	
setTimeout("startBeingCrazy()",200);
}
function PageManager(){
	this.page = "home";;
	var loaded = false;
	var _this = this;
    
	function doLoad(page, callback, form){
		var handle = function(data){
			callback();
			$("#content").html(data);
		}
        
		if(form){
			var action = form.attr("action");
			var postData = form.serialize();
			$.post("/ajax.php?page="+page, postData, handle);
		}else{
			$.post("/ajax.php?page="+page, handle);
		}
	}
    
    
	this.loadPage = function(page, animate){
		if(page == this.page) return;
        
		$("#"+this.page+"-link").removeClass("active");
		$("#"+page+"-link").addClass("active");
        
		this.page = page;
        
		var form = null;
        
		if(page == "insert"){
			form = $("#post_form");
		}
        if(page == "insert_reply"){
			form = $("#reply_form");
		}
		if(animate){
			doLoad(page, function(){
                   if(page == "home"){
                   $("#content").hide("fade", 300, function(){
                         $("#menu").show();
                              $("#menu").animate({
                                   top: '+=300'
                              }, 500, function() {
                              _this.doLoad(page);
                              });
                         });	
                   }else if(!loaded){
                   $("#menu").animate({
                                        top: '-=300'
                                        }, 500, function() {
                                        $("#content").show("fade", 300, function(){
                                                           _this.doLoad(page);
                                                           });
                                        });
                   }
                   loaded = (page == "home") ? false : true;
               }, form);
        }else{
            _this.doLoad(page);
        }
    }
    
    this.doLoad = function(){
        
    }
    return this;
}

manager = new PageManager();
manager.page = "home";
