var wHt = 0;					// height of browser viewport
var docHt = 0;					// height of HTML document
var wWd = 0;
var docWd = 0;
var currentId = "none";
var haveContact = false;	// has the contact form been activated?
var cache = [];				// For preloading images
var revealed = false;		// Has the site been revealed, ie the cube clicked on?
var fadeIn = true;			// Fading blue planet in or out?

function CubeOver()
{
	var cssObj = { 'cursor' : 'pointer' };
	$("#id_cube").css(cssObj);
}
function CubeOut()
{
	var cssObj = { 'cursor' : 'default' };
	$("#id_cube").css(cssObj);
}
function CubeClick()
{
	revealed = true;
	$("#id_cube").animate(
	{ 
		left: 360,
		top: wHt * 1.2
	}, 1500, 
		function() { RevealGray(); } );
}
function RevealGray()
{
	$("#id_gray").slideDown(1200, 
		function() { RevealLogo(); } );
}
function RevealLogo()
{
	$("#id_logo").animate(
		{ left: 60 }, 1200,
		function() { CubeIn(); } );
}
function CubeIn()
{
	$("#id_cubeImg").attr(
	{
		height: 46,
		width: 46
	});
	$("#id_cube").animate(
	{ 
		left: 124,
		top: 352,
		opacity: 1.0,
		height: 50,
		width: 50
	}, 1200,
		function() 
		{ 
			$("#id_mid").show("drop", { direction: "down" }, 1000); 
			$("#id_links").show("drop", { direction: "up" }, 1000); 
		});
}

function Link( theId )
{
	if ( currentId != "none" )
	{
		// Slide the current content off to the right
		$(currentId).hide("blind", { direction: "horizontal" }, 1500,
			function() 
			{
				$(theId).show("blind", { direction: "horizontal" }, 1500);
			});
	}
	else		
	{
		$(theId).show("blind", { direction: "horizontal" }, 1500);
	}	
	currentId = theId;		
}
function FormClear()
{
	$("#id_name").val('');
	$("#id_email").val('');
	$("#id_inquiry").val('');
	$("#id_emailResponse").html('');	
}
function Email()
{
	fEmail.submit();
}
function LinkOver(what)
{
	var theId = '#' + what.id;
	var cssObj = { 'color' : '#103E95' };
	$(theId).css(cssObj);
}
function LinkOut(what)
{
	var theId = '#' + what.id
	var cssObj = { 'color' : 'white' };
	$(theId).css(cssObj);
}
(function($) 
{
  // Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
	var args_len = arguments.length;
	for (var i = args_len; i--;) 
	{
		var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
   }
  }
})(jQuery)

$(document).ready(function() 
{
	// Put all your jQuery goodness in here.
	window.name = "miD";	
	wHt = $(window).height();				// height of browser viewport
	docHt = $(document).height();			// height of HTML document
	wWd = $(window).width();
	docWd = $(document).width();
	FormClear();
	
	// AJAX form options
	// Documentation: http://jquery.malsup.com/form
	var options = 
	{ 
		target:		'#id_emailResponse',		// target element(s) to be updated with server response 
		//beforeSubmit:	showRequest,			// pre-submit callback 
		success:		Success							// post-submit callback 
 
		// other available options: 
		//url:       url         // override for form's 'action' attribute 
		//type:      type        // 'get' or 'post', override for form's 'method' attribute 
		//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
		//clearForm: true        // clear all form fields after successful submit 
		//resetForm: true        // reset the form after successful submit 
 
		// $.ajax options can be used here too, for example: 
		//timeout:   3000 
	};  
	// bind form using 'ajaxForm' 
	$('#id_fEmail').ajaxForm(options); 
	setTimeout( "Reveal()", 9000 );
	FadeBluePlanet( fadeIn );
});

// If the user hasn't clicked on the cube to reveal our content, do it for him.
function Reveal()
{
	if ( !revealed )
		CubeClick();
}

function FadeBluePlanet()
{
	if ( fadeIn )
	{
		$('#id_bluePlanet').fadeIn( 3000);
		fadeIn = false;
	}
	else
	{
		$('#id_bluePlanet').fadeOut( 3000 );
		fadeIn = true;
	}
	setTimeout( "FadeBluePlanet()", 1000);
}

function Success(responseText, statusText)  
{ 
	$("#id_emailResponse").show( "slow", 
		function()
		{
			setTimeout( "HideMailMsg()", 5000 );
		});
} 
function HideMailMsg()
{
	$("#id_emailResponse").hide( "slow" );
}
function OnLoad()
{
	jQuery.preLoadImages( "static/images/blackflare_bg.gif" );
}

