// Number of pixels the top of the bubbles will be above the bottom of the main box
var bubblePlacement = 100;

// Set this to false if you don't want the bubbles to rise up on page load
var animateBubbles = false;

// How long (in seconds) it will take the bubbles to rise to the desired position
var riseDuration = 2;


var msie = $.browser.msie;
var msie6 = msie && $.browser.version < 7;

$(function() {

	$('ul#nav').supersubs({
			minWidth: 6
			// extraWidth: ew
		}).superfish({
			autoArrows: false,
			delay: 100,
			dropShadows: false
		});

	setTimeout(function() {
		positionBubbles(true);
	}, 100);

});

function positionBubbles(startAtBottom) {
	var mainOffset = $('#main-wrapper').offset();
	var mainHeight = $('#main-wrapper').height();
	
	var bkgHeight = 1500, bubbleHeight = 640,
		bkgYPosition;

	var mainBottom = mainOffset.top + mainHeight;

	bkgYPosition = bubbleHeight - bkgHeight + (mainBottom - bubblePlacement);

	// $('#content-wrapper').append('<p>bkgYPosition=' + bkgYPosition + ', mainBottom=' + mainBottom+ 'mainOffset.top=' + mainOffset.top + ', mainHeight=' + mainHeight + '</p>');

	if (!animateBubbles || msie6) $('body').css('background-position', '0 ' + bkgYPosition + 'px');
	else {
		if (startAtBottom) $('body').css('background-position', '0 ' + (bkgYPosition+bubblePlacement+100) + 'px');
		setTimeout(function() {
			$('body').animate({ backgroundPosition: '0 ' + bkgYPosition + 'px' }, riseDuration*1000, 'swing');
		}, 500);
	}
}
