$(document).ready(function(){
	$.log('Document Ready');
	
	/*
jQuery.each(jQuery.support, function(i, val) {
      $("<div>" + i + " : <span>" + val + "</span>").appendTo(document.body);
    });
*/
	
	$('#nav a').click(function(){
		var position = $(this).position();
		$('h1.destinationtitle').remove();
		var destination = $(this).attr('href');
		$('#content').prepend('<h1 class="destinationtitle ' + $(this).parent().attr('class') + '">' + $(this).html() + '</h1>');
		//$('#content').fadeOut(500);
		$('h1.destinationtitle').css('left', position.left).animate(
			{
		    	left: '676'
		  	}, 
		  	500, 
		  	function() {
		    	window.location = destination;
			}
		);
		return false;
	});
	
	$('#portfolio ul.projects li a').hover(
		function(){
			$('#portfolio ul.projects li a').not(this).find('img.fade').show();
		}, 
		function(){
			$('#portfolio ul.projects li a').not(this).find('img.fade').hide();
		}
	);
	
	$('#home #page').ready(function(){
		$('#intro').show();
		$("#intro").bind("ended", function(){
		   $(this).fadeOut('slow');
		   setCookie('madeitthisfar', 'set', 3650);
		});
	});
	
	$('#portfolio #content').hover(
		function(){
			$('a.previous, a.next').show();
		},
		function(){
			$('a.previous, a.next').hide();
		}
	);
	
});

function setCookie(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 getCookie(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 deleteCookie(name) {
    setCookie(name,"",-1);
}

function explode (delimiter, string, limit) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||
        typeof arguments[1] == 'undefined' ) {
        return null;
    }
 
    if ( delimiter === '' ||
        delimiter === false ||
        delimiter === null ) {
        return false;
    }
 
    if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' ) {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

function count(array){
	var num = 0;
	$.each(array, function(key, value){
		num++;
	});
	return num;
}

function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}
