// Preloads the Landing image
$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}

// Function for fading in the text
var nextStep = function()
{
	$('#landing-text').fadeIn(500, finalStep);
}

// Function for fading out the intro and fading in the page and setting cookie for 60days
var finalStep = function()
{
	setTimeout(
		function()
		{
			$('#landing').fadeOut(1500);
			setCookie('sawIntro', 'yes', 60);
		},
		2000
	);
}

// Kick it off, sucka.
$(document).ready(
	function() {
		$('#landing-image').hide();
		$(['images/landing-tango.jpg']).preload();
		// If they already saw the intro, why would they want to see it again!?
/*		if (getCookie('sawIntro') == 'yes')
		{
			$('#landing').hide();
		} else {*/
			// Hide the text
			$('#landing-text').hide();
			
		    // Run the image fade in
		    setTimeout(
		    	function()
		    	{
		    		$('#landing')[0].style.opacity       = "1";
			    	$('#landing-image')[0].style.opacity = "1";
			    	$('#landing-image').show('drop', { direction: 'up' }, 500, nextStep);
		    	},
		    	3000
		    );
//		}
	}
);


//  This is the cookie stuff not included in the jQuery Library but that we NEED!
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);
}
/*
  Changed function names from readCookie(), createCookie()
  and eraseCookie() to getCookie(), setCookie() and
  deleteCookie().
*/
