$(document).ready(function(){
	$(document).pngFix();
	$("a").bind("focus",function(){if(this.blur)this.blur();});
	
	// Newsletter validation
	$('#newsletter-form input:text').focus(function(){
		if ( $(this).attr('value') == $(this).parents().siblings('.msg').text() ){
			$(this).attr('value', '');
		}
	}).blur(function(){
		if ( $(this).attr('value') == null ){
			var msg = $(this).parents().siblings('.msg').text();
			$(this).attr('value', msg);
		}
	});
	
	$.validator.messages.required="";
	$.validator.messages.email="";
	$('#newsletter-form').validate({
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		submitHandler: function(form){
			var options = {
				dataType: 'json',
				clearForm: true,
				url: '/ajax.php?class=news&func=subscribe',
				beforeSubmit: function(){
					$('#newsletter-form input:submit').attr('disabled', 'disabled');
				},
				success: function(json){
					if ( json.error == false ){
						var msg = $('#newsletter .msg').text();
						$('#newsletter-form input:text').val(msg);
						
						$('#newsletter .success').empty().append(json.msg).slideDown(500, function(){
							$(this).animate({opacity: 1}, 6000, function(){
								$(this).slideUp(500, function(){
									$(this).hide();
									$('#newsletter-form input:submit').removeAttr('disabled');
								});
							});
						});
					}
				}
			};
			
			$(form).ajaxSubmit(options);
			return false;
		}
	});
});
