$(document).ready(function() {
	jQuery.preloadCssImages();
	$('#header #language_selector').click(function() {
		if ($('#header #language_options').css('display') == 'none')
			$('#header #language_options').show('fast');
		else
			$('#header #language_options').fadeOut('fast');
	});
	$('#content,#footer').click(function() {
		$('#header #language_options').fadeOut('fast');
	});
	$('a.newsletter_signup_link').click(function() {
		openPositionedWindow(this.href, 'tos', 685, 604, 0, 0, true, true);
		return false;
	});
	
	// LOCALE HANDLING ######################
	var urlLanguage = getQueryVariable('locale');
	// Set test cookie
	$.cookie('cookiesEnabled','1');
	if ($.cookie('cookiesEnabled') == '1')
	{
		// Cookies functioning
		if (urlLanguage != '')
		{
			$.cookie('selectedLanguage',urlLanguage);
		}
		if ($.cookie('selectedLanguage') == null)
		{
			$('#language_select').show('fast');
		}
		if ($('#lang_' + $.cookie('selectedLanguage')).length != 0)
		{
			$('body.main #language_options_active').html($('#lang_' + $.cookie('selectedLanguage')).text());
		}
	}
	else
	{
		// Cookies not functioning
		if (!urlLanguage)
		{
			urlLanguage = "en_US";
		}
		$('body.main #language_options_active').html($('#lang_' + urlLanguage).text());
	}
	// END LOCALE HANDLING ######################
});
/*
function showBlueBox(elementId)
{
	var elementId = (elementId == null) ? 2 : elementId;
	$('#real_content div.medium_box div.box_content').fadeOut('fast');
	setTimeout(function() {
		$('#real_content div.medium_box div.box_content:nth-child(' + elementId + ')').fadeIn('fast');
	},400);
	
}*/
function omniCall(element, omniTag)
{
  // Some special links need to have the current pagename appended
	var modifiedTag = omniTag;
	/*switch(omniTag){
		case 'preorder_link_click':
		case 'newsletter_link_click':
			modifiedTag = getPageName() + "_" + omniTag;
			break;
	}*/
	setOmniValues(element,'o',modifiedTag,'','','',0,'','');
	return false;
}

function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
	openPopup(url, name, width, height, status, scrollbars, moreProperties);
}

// GLOBAL WINDOW POPUP (Used everywhere there's a popup.)
function openPopup(url, name, width, height, status, scrollbars, moreProperties) {
	var agent = navigator.userAgent.toLowerCase();
	var x, y = 0;
	if (screen) {
      x = (screen.availWidth - width) / 2;
      y = (screen.availHeight - height) / 2;
   }
   if (!status) status = '';

	// Adjust width if scrollbars are used (pc places scrollbars inside the content area; mac outside) 
	width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;

	var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
   
	window.open(url, name, properties);
	return false;
} 
function getQueryVariable(variable) 
{
 var query = window.location.search.substring(1);
 var vars = query.split("&");
 for (var i=0;i<vars.length;i++) 
 {  
 var pair = vars[i].split("=");
  if (pair[0] == variable) 
  {
  return pair[1];
  }
 }
}
