var x,y;
var pageTop = 0;
var objHello = 0;
var objWork = 0;
var objAbout = 0;
var objBlog = 0;
var objContact = 0;
var objBye = 0;

/*
 * runOnLoad.js: portable registration for onload event handlers.
 * 
 * This module defines a single runOnLoad() function for portably registering
 * functions that can be safely invoked only when the document is fully loaded
 * and the DOM is available.
 *
 * Functions registered with runOnLoad() will not be passed any arguments when
 * invoked. They will not be invoked as a method of any meaningful object, and
 * the this keyword should not be used.  Functions registered with runOnLoad()
 * will be invoked in the order in which they were registered.  There is no
 * way to deregister a function once it has been passed to runOnLoad().
 *
 * In old browsers that do not support addEventListener() or attachEvent(),
 * this function relies on the DOM Level 0 window.onload property and will not
 * work correctly when used in documents that set the onload attribute
 * of their <body> or <frameset> tags.
 */
function runOnLoad(f) {
    if (runOnLoad.loaded) f();    // If already loaded, just invoke f() now.
    else runOnLoad.funcs.push(f); // Otherwise, store it for later
}

runOnLoad.funcs = []; // The array of functions to call when the document loads
runOnLoad.loaded = false; // The functions have not been run yet.

// Run all registered functions in the order in which they were registered.
// It is safe to call runOnLoad.run() more than once: invocations after the
// first do nothing. It is safe for an initialization function to call
// runOnLoad() to register another function.
runOnLoad.run = function() {
    if (runOnLoad.loaded) return;  // If we've already run, do nothing

    for(var i = 0; i < runOnLoad.funcs.length; i++) {
        try { runOnLoad.funcs[i](); }
        catch(e) { /* An exception in one function shouldn't stop the rest */ }
    }
    
    runOnLoad.loaded = true; // Remember that we've already run once.
    delete runOnLoad.funcs;  // But don't remember the functions themselves.
    delete runOnLoad.run;    // And forget about this function too!
};

// Register runOnLoad.run() as the onload event handler for the window
if (window.addEventListener)
    window.addEventListener("load", runOnLoad.run, false);
else if (window.attachEvent) window.attachEvent("onload", runOnLoad.run);
else window.onload = runOnLoad.run;


function init()
{
	pageTop = document.documentElement.scrollTop;
	objHello = document.getElementById("sctoHello").offsetTop-30;
	objWork = document.getElementById("sctoWork").offsetTop-30;
	objAbout = document.getElementById("sctoAbout").offsetTop-30;
	objBlog = document.getElementById("sctoBlog").offsetTop-30;
	objContact = document.getElementById("sctoContact").offsetTop-30;
	objBye = document.getElementById("sctoBye").offsetTop-30;			
	
	switchCol();
	setBye();
}

function switchCol()
{
	if (document.documentElement.scrollTop) // all except Explorer
	{
		pageTop = document.documentElement.scrollTop;
	}
	else // other Explorers
	{
		pageTop = document.body.scrollTop;
	}
	
	if (pageTop <= objWork)
	{
		$("#header").css("background-color","#cea8ce");
	}
	else if ((pageTop >= objWork) && (pageTop <= objAbout))
	{
		$("#header").css("background-color","#f6a0a6");
	}
	else if ((pageTop >= objAbout) && (pageTop <= objBlog))
	{
		$("#header").css("background-color","#fbb160");
	}
	else if ((pageTop >= objBlog) && (pageTop <= objContact))
	{
		$("#header").css("background-color","#d5e04d");
	}
	else if ((pageTop >= objContact) && (pageTop <= objBye))
	{
		$("#header").css("background-color","#9fcf67");
	}
	else if (pageTop >= objBye)
	{
		$("#header").css("background-color","#79ccc8");
	}
}

function setBye()
{
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	$("#sctoBye").height(y-330);
}


runOnLoad(init);
$(window).scroll(switchCol);
$(window).resize(setBye);