// Create a new instance of debug
debug = new Debug();

// Create a global instance of Omniture tracking
var omnitureTracking;
var windowLoaded = false;

$(window).load(function(){

	windowLoaded = true;

});

// Redirect to mobile site ASAP (if applicable)
$.getJSON('/handsetDetection', {}, function(data){

	// If is a mobile site
	if( true == data.mobile )
	{
		// Declare variables
		var url = window.location.toString();

		url = url.replace('http://www.', 'http://m.');

		window.location = url;
	}

});

// Document ready actions
$(document).ready(function()
{
	// Create a new instance of Omniture tracking
	omnitureTracking = new OmnitureTracking(s);

	//
	// Apply some styling updates
	//

	// If an accessible form container exists, position it in the center of the viewport using the jquery.center plugin.
	// http://andreaslagerkvist.com/jquery/center/
	$("div.accessibleFormContainer").center(true);
});

function centerPanel(obj)
{
	// Declare variables
	var left = 0;
	var top = 0;

	left = (($('#flashContainer').width() - obj.width()) / 2);
	top = (($('#flashContainer').height() - obj.height()) / 2);

	// Re-adjust
	left -= 40;
	top -= 25;

	obj.css({
		left: left + 'px',
		top: top + 'px'
	});
}


/**
 * Searches for all QuickForm error divs on the page and moves
 * their location to be beneath their associated form field.
 */
function updateQuickFormErrorDisplay()
{
	// Move each of the error divs to be after the form field
	$.each($("div[id$='_errorDiv']"), function(index, element)
	{
		var parent = $(element).parent();
		$(parent).append(element);
	});

	return false;
}
