$(document).ready(function() {
	$('a#wishlist_cancel').click(function() {
		wishlistCancelNow();
		return false;
	});
	$('a#wishlist_send').click(function() {
		wishlistSendNow();
		return false;
	});
	$('input#wishlist_parent_email,input#wishlist_from').keypress(function(e) {
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
			wishlistSendNow();
			return false;
		}
	});
	$('a.arrow-button').mouseenter(function() {
		setTimeout(function() {
			Cufon.replace("a.arrow-button div.center-arrow-button");
		},20);
		return false;
	});
	$('a.arrow-button').mouseleave(function() {
		setTimeout(function() {
			Cufon.replace("a.arrow-button div.center-arrow-button");
		},20);
		return false;
	});
	$('a#nav_newsletter,a#sign_up_now').click(function() {
		openPositionedWindow(this.href, 'sign_up_now', 460, 490, 0, 0, true, true);
		return false;
	});
	$('a.lpso_newsletter_signup_link').click(function() {
		openPositionedWindow(this.href, 'lpso_newsletter_popup', 690, 645, 0, 0, true, true);
		return false;
	});
	// Click select language drop down
	$('#header #language_selector').click(function() {
		if ($('#header #language_options').css('display') == 'none')
			$('#header #language_options').show('fast');
		else
			$('#header #language_options').fadeOut('fast');
	});
	// LOCALE HANDLING ######################
	var enabledLocaleCount = $('#language_list li').length;
	var urlLanguage = getQueryVariable('locale');
	if (enabledLocaleCount <= 1)
	{
		$.cookie('selectedLanguage','en_US');
	}
	// 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')).text() != "")
		{
			$('#language_options_active').html($('#lang_' + $.cookie('selectedLanguage')).text());
		}
	}
	else
	{
		// Cookies not functioning
		if (!urlLanguage)
		{
			urlLanguage = "en_US";
		}
		if ($('#lang_' + urlLanguage).text() != "")
		{
			$('#language_options_active').html($('#lang_' + urlLanguage).text());
		}
	}
	// END LOCALE HANDLING ######################
});
function wishlistSendNow()
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test($('#wishlist_parent_email').val()) == false)
	{
		omniCall(this,'wishlist_send_error');
		$('#wishlist_error').show('fast');
		$('input#wishlist_parent_email').focus();
	}
	else
	{
		omniCall(this,'wishlist_send_success');
		$.post('ea/services/sendEmail.php',{locale: $('#current_language_code').val(), type: 82372340, from: $('#wishlist_from').val(), subject: "emailSubject", body: "emailBody", toemails: $('#wishlist_parent_email').val()});
		wishlistCancelNow();
	}
}
function wishlistCancelNow()
{
	omniCall(this,'wishlist_cancel');
	$('div#wishlist').fadeOut('fast',function() {
		$('input#wishlist_parent_email').val('');
		$('input#wishlist_from').val('');
		$('#wishlist_error').css('display','none');
	});
}
function omniCall(element, omniTag)
{
	setOmniValues(element,'o',omniTag,'','','',0,'','');
	return false;
}

function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
	openPopup(url, name, width, height, status, scrollbars, moreProperties);
}
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;
}
/* FLASH FUNCTIONS */
function home(str){
	if (document.getElementById("LPSO_SiteLoader")) { 
		document.getElementById("LPSO_SiteLoader").home(str);
	}
}

function meet(str){
	if (document.getElementById("LPSO_SiteLoader")) { 
		document.getElementById("LPSO_SiteLoader").meet(str);
	}
}

function explore(str){
	if (document.getElementById("LPSO_SiteLoader")) { 
	document.getElementById("LPSO_SiteLoader").explore(str);
	}
}

function play(str){
	if (document.getElementById("LPSO_SiteLoader")) { 
		document.getElementById("LPSO_SiteLoader").play(str);
	}
}

function video(str){
	if (document.getElementById("LPSO_SiteLoader")) { 
		document.getElementById("LPSO_SiteLoader").video(str);
	}
}
function getWishlist(id,url){
	$('div#wishlist').fadeIn('fast',function() {
		$('input#wishlist_parent_email').focus();
		setTimeout(function() {
			$('input#wishlist_parent_email').focus();
		},150);
	});
}

function downloadWallpaper(id,url){
	return acceptLegalDownload(url);
}

function downloadScreensaver(id,url){
	return acceptLegalDownload(url);
}

function flashOmniPage(pagename){
	omniCall('flash_page', pagename);
}

function flashOmniClick (clicktagname){
	omniCall('flash_link', clicktagname);
}

function acceptLegalDownload(url){
	var legalConfirmation = confirm($('#legal_agreement').text());
	if (legalConfirmation)
	{
		window.location = url;
		return true;
	}
	else
	{
		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];
  }
 }
}
