<!--

$(document).ready(function() {
	$(window).resize();
	
	//cloudInit();
	clouds.init();
});

$(window).resize(function() {
	// adjust size of #content to fill available window height after #nav-main if there would otherwise be blank space in the visible window area
	if($(window).innerHeight() > $('#content').height() + $('#header').height() + $('#nav-main').height())
	{
		$('#content').height($(window).innerHeight() - ($('#header').height() - $('#nav-main').height()));
	}
});

// set initial cloud positions and begin animation
/*
function cloudInit() { 
	var t;
	var l;
	
	// correct vertical positioning of secondary clouds
	$('#cloud_f2').css('top', $('#cloud_f1').offset().top);
	$('#cloud_m2').css('top', $('#cloud_m1').offset().top);
	$('#cloud_n2').css('top', $('#cloud_n1').offset().top);
	
	// move all secondary clouds to just offscreen on the left hand side
	$('#cloud_f2').css('right', $(window).innerWidth());	
	$('#cloud_m2').css('right', $(window).innerWidth());
	$('#cloud_n2').css('right', $(window).innerWidth());
	
	// correct positioning of visible far cloud
	t = $('#cloud_f1').offset().top;
	l = $(window).innerWidth() / 2;
	$('#cloud_f1').offset({top:t,left:l});
	
	// correct positioning of visible mid cloud
	t = $('#cloud_m1').offset().top;
	l = 2 * ($(window).innerWidth() / 3);
	$('#cloud_m1').offset({top:t,left:l});
	
	// correct positioning of visible near cloud 
	t = $('#cloud_n1').offset().top;
	l = $(window).innerWidth() / 3;
	$('#cloud_n1').offset({top:t,left:l});
	
	// start cloud animations
	$('#cloud_f1').stop().animate({left:$(window).innerWidth()}, 16000);
	$('#cloud_m1').stop().animate({left:$(window).innerWidth()}, 14000);
	$('#cloud_n1').stop().animate({left:$(window).innerWidth()}, 10000);
}
*/

getUrlVars = function() { // Example use: var first = getUrlVars()["me"];
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

// [CURRENT] Clouds object with fixed speeds set in the script file, does not utilize input from cloud speed control form
var clouds = {
	init:function() {
		var t;
		var l;
		
		this.resetCloud('#cloud_f2');
		this.resetCloud('#cloud_m2');
		this.resetCloud('#cloud_n2');
		
		// correct positioning of visible far cloud
		t = $('#cloud_f1').offset().top;
		l = $(window).innerWidth() / 2;
		$('#cloud_f1').offset({top:t,left:l});
		
		// correct positioning of visible mid cloud
		t = $('#cloud_m1').offset().top;
		l = 3 * $(window).innerWidth() / 4;
		$('#cloud_m1').offset({top:t,left:l});
		
		// correct positioning of visible near cloud
		t = $('#cloud_n1').offset().top;
		l = $(window).innerWidth() / 8;
		$('#cloud_n1').offset({top:t,left:l});
		
		// animation speeds for cloud objects in seconds per trip across the screen
		speed_f = getUrlVars()["far"]?parseInt(getUrlVars()["far"]):240; // farthest cloud
		speed_m = getUrlVars()["far"]?parseInt(getUrlVars()["mid"]):165; // middle cloud
		speed_n = getUrlVars()["far"]?parseInt(getUrlVars()["near"]):105; // nearest cloud
		
		// start cloud animation loop
		this.animateCloud('#cloud_f1',speed_f * 1000);
		this.animateCloud('#cloud_m1',speed_m * 1000);
		this.animateCloud('#cloud_n1',speed_n * 1000);
	},
	resetCloud:function(cloudname) {
		var cloud = $(cloudname);
		cloud.css('right', $(window).innerWidth());
	},
	animateCloud:function(cloudname,time) {
		var that = this;
		var cloud = $(cloudname);
		if(cloud.offset().left > 0) {
			cloud.stop().animate({left:$(window).innerWidth()}, time * (($(window).innerWidth() - cloud.offset().left) / $(window).innerWidth()), 'linear', function() {
				cloud.css('left', -$(cloud).width() );
				that.animateCloud(cloudname,time);
			});
		} else {
			cloud.stop().animate({left:$(window).innerWidth()}, time, 'linear', function() {
				cloud.css('left', -$(cloud).width() );
				that.animateCloud(cloudname,time);
			});
		
		}
	}
}

// [INACTIVE] This version of the clouds object utilizes input from the cloud speed control form, which was created for testing purposes
/*
var clouds = {
	init:function() {
		var t;
		var l;
		
		this.resetCloud('#cloud_f2');
		this.resetCloud('#cloud_m2');
		this.resetCloud('#cloud_n2');
		
		// correct positioning of visible far cloud
		t = $('#cloud_f1').offset().top;
		l = $(window).innerWidth() / 2;
		$('#cloud_f1').offset({top:t,left:l});
		
		// correct positioning of visible mid cloud
		t = $('#cloud_m1').offset().top;
		l = 3 * $(window).innerWidth() / 4;
		$('#cloud_m1').offset({top:t,left:l});
		
		// correct positioning of visible near cloud
		t = $('#cloud_n1').offset().top;
		l = $(window).innerWidth() / 8;
		$('#cloud_n1').offset({top:t,left:l});
		
		// get speeds defined using URL-passed variables
		var speed_f = getUrlVars()["far"];
		var speed_m = getUrlVars()["mid"];
		var speed_n = getUrlVars()["near"];
		
		// temporarily assume all speeds are defined using URL-passed variables
		var allSpeedsDefined = 1;
		
		// start far cloud animation loop
		if(speed_f != undefined && speed_f != "") {
			this.animateCloud('#cloud_f1',speed_f * 1000);
		} else {
			this.animateCloud('#cloud_f1',36000);
			allSpeedsDefined = 0;
		}		
		
		// start middle cloud animation loop
		if(speed_m != undefined && speed_m != "") {
			this.animateCloud('#cloud_m1',speed_m * 1000);
		} else {
			this.animateCloud('#cloud_m1',32000);
			allSpeedsDefined = 0;
		}
		
		// start near cloud animation loop
		if(speed_n != undefined && speed_n != "") {
			this.animateCloud('#cloud_n1',speed_n * 1000);
		} else {
			this.animateCloud('#cloud_n1',24000);
			allSpeedsDefined = 0;
		}
		
		// show alert if any cloud speeds not explicitly defined using URL-passed variables
		if(allSpeedsDefined == 0) {
			alert("One or more cloud speeds undefined:\n\n FAR(" + speed_f + "), MID(" + speed_m + "), NEAR(" + speed_n + ").\n\nUsing default values for undefined speeds.");
		}
	},
	resetCloud:function(cloudname) {
		var cloud = $(cloudname);
		cloud.css('right', $(window).innerWidth());
	},
	animateCloud:function(cloudname,time) {
		var that = this;
		var cloud = $(cloudname);
		if(cloud.offset().left > 0) {
			cloud.stop().animate({left:$(window).innerWidth()}, time * (($(window).innerWidth() - cloud.offset().left) / $(window).innerWidth()), 'linear', function() {
				cloud.css('left', -$(cloud).width() );
				that.animateCloud(cloudname,time);
			});
		} else {
			cloud.stop().animate({left:$(window).innerWidth()}, time, 'linear', function() {
				cloud.css('left', -$(cloud).width() );
				that.animateCloud(cloudname,time);
			});
		
		}
	}
}
*/

-->
