$(document).ready(function() {
	$('#newsletter_cont_high').corner({tl: false, tr: false, bl: { radius: 16 }, br: { radius: 16 }});	
	$('#email_saving_confirmation').corner();

	$('.join_newsletter_button').click(function(){
		var email, instance; 
		var pos,x, y;
		if ($(this).attr('id') == 'join_newsletter_button')	{	
			instance = 'bot';
			email = STrim($('#newsletter_email').val());
			pos = $('#newsletter_email').position();
			x = pos.left + 191; 
			y = pos.top - 139;
		}
		if ($(this).attr('id') == 'join_newsletter_button_high'){	
			instance = 'top';
			email = STrim($('#newsletter_email_high').val());
			pos = $('#newsletter_email_high').position();	
			x = pos.left + 384; 
			y = pos.top + 39;
			var isSafari3 = false;
			if(window.devicePixelRatio) isSafari3 = true;
			if (isSafari3) y = y + 4;
		}
		
		if (!email) return false;
		$.ajax({
		   type: "GET",
		   url: (window.location.protocol  + '//' + window.location.host + '/newsletter.php'),
		   data: "newsletterEmail=" + email,		   
		   success: function(data){	
				if (data != 1 || !pos) return false;				
				$('.email_saving_confirmation').css('position', 'absolute'); 
				$('#email_saving_confirmation').css('left', x).css('top', y); 				
				if (instance == 'top'){
					$('#close_newsletter_cont_high').click();
					$('#confirm_instance_of_caller').val('top');
				}
				if (instance == 'bot'){
					$('#confirm_instance_of_caller').val('bot');
				}
				$('#email_saving_confirmation').fadeIn(1500);
		   }		 
		 });
		 return false;
	});
	
	$('#newsletter_email').keydown(function(event){
		//if (event.keyCode == 13){
		//	$('.join_newsletter_button').click();			
		//}
	});
	
	$('.close_newsletter_confirm').click(function(){	
		$('.newsletter_email').val('');
		$('.email_saving_confirmation').fadeOut(1000);
	});		
		
	$('#newsletter_signup_high').click(function(){	
		$('#newsletter_email').val('');
		$('.close_newsletter_confirm').click();
		var pos = $(this).position();		
		$('#newsletter_cont_high').css('position', 'absolute').css('left', pos.left + 231 + 'px').css('top', pos.top + 65 + 'px').slideDown(500);	
		return false;
	});
	
	$('#close_newsletter_cont_high').click(function(){	
		$('#newsletter_cont_high').slideUp(500);
	});	
});