
$(document).ready( function() {
	
	/* COUNTRY SELECTOR */
	
	$('#current_flag').toggle(function() {
		$('#country_dd').css('visibility', 'visible');
		return false;
	}, function() {
		$('#country_dd').css('visibility', 'hidden');
		return false;			
	});
	
	
	
	
	
	
	
	/* SIGN UP FUNCTIONS */
		$('#signup_button').click(function() {
			//$('#signup_container').animate( {height:50}, 300);
			$('#signup_inner').animate( {bottom:0}, 300);	
			$('#signup_button').addClass('active');
			return false;
		});
		
		$('.close_signup').click(function() {
			//$('#signup_container').animate( {height:0}, 300);
			$('#signup_inner').animate( {bottom:-70}, 300);
			$('#preorder_inner').animate( {bottom:-70}, 300);
			$('#signup_button').removeClass('active');
			return false;
		});
		
		
		// Email field focus/blur
		$('#email_field').focus(function() {
										 
			var val = $(this).attr('value');
			
			if (val == email_enter)
				val = '';
			
			$(this).attr('value', val);
			
		}).blur( function() {
			
			var val = $(this).attr('value');
			
			if (val == '') {
				val = email_enter;
				$('#signup_content .msg').html('');
			}
			
			$(this).attr('value', val);
			
		});
		
		
		/* SUBMIT NEWSLETTER EMAIL */
		$('#signup_form').submit(function() {
		
			var email = $('#email_field').attr('value');
			
			$.ajax({
        		type: "POST",
        		url: "/index.php/en/signup/subscribe/",
				data: "email="+email,
        		dataType: "text",
        		success: function(data) {
					
					// success
					if (data == 'true') {
						$('#signup_content .msg').html(email_submitted);
					}
					// invalid email
					else if (data == 'invalid') {
						$('#signup_content .msg').html(email_invalid);
					}
					// existing email
					else if (data == 'exist') {
						$('#signup_content .msg').html(email_existing);
					}
					
				},
        		error: function(xhr, textStatus, error) {
            		//alert("Sorry, there was a problem loading:" + xhr.status);
        		}
    		});
	
	
			return false;
		
		});
	/* END SIGNUP */

});






function initTheGameDropdown(h, lang)
{
	
	// trigger dropdown
	$('#topNav_thegame').hover( function(e) {
		
		e.stopPropagation();
		
		$('#dd_the_game').delay(500).stop(true).animate( {height:h+'px'}, 500);
		$('#dd_the_game ul').delay(500).stop(true).animate( {top:0}, 500);
		
	}, function(e) {
		
		$('#dd_the_game').stop(true).animate( {height:0}, 500);
		$('#dd_the_game ul').stop(true).animate( {top:'-'+h+'px'}, 500);
		
	});
	
	// image swqp for dropdown
	$('#dd_the_game a' ).hover( function() {
		
		var t = $(this).children('img').attr('src');
		$(this).children('img').attr('src', t.replace('-'+lang+'.png', '_over-'+lang+'.png'));
		
	},
	function() {
		
		var t = $(this).children('img').attr('src');
		$(this).children('img').attr('src', t.replace('_over-'+lang+'.png', '-'+lang+'.png'));
		
		
	});
	
}

