function isValidEmailAddress(emailAddress){
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}


$(document).ready(function(){


// left menu onhover
	$('#menu_sidebar ul li a, #homebutton a').hover(
	function () {
		$(this).stop().animate({paddingLeft: '9px', paddingRight: '9px'}, 200);
	},
	function () {
		$(this).stop().animate({paddingLeft: '5px', paddingRight: '5px'}, 200);
		}
	);



// newsletter
	$(function() {
		$.ajaxSetup ({
			cache: false
		});

		$("#nl_form #submit").click(function(event) {
			event.preventDefault();
			var email = $("#nl_form #email").val();


			if (!isValidEmailAddress(email)) {
				alert($('#wrongemail').attr('title'));
				$("#nl_form #email").focus();
				return false;
	    	}

 			if (!confirm($('#newsletteraggreement').attr('title'))) return false;

			var email = 'email=' + email;

			$.ajax({
				type: "POST",
				url: "/inc/newsletter.php",
				data: email,
				dataType: "html",
				async: false,
				success: function(data) {
					alert(data);
					$("#nl_form #email").val($("#nl_form #email").attr('title'));
				}
			});
		});
	});






// f11 button z prawej na startowej
	$(function(){
		$("#czteryef").after("<img src=\"/img/f11.png\" id=\"f11\" style=\"cursor:help; position:fixed; right:-91px; top:400px; display:none;\" />");
		if($(window).height() < 800){
			$('#f11').show('slow');
			$('#f11').hover(
				function(){
					$(this).stop().animate({
						right: '0px'
					}, 200);
				},
				function(){
					$(this).stop().animate({
						right: '-91px'
					}, 200);
				}
			);
		}
		$('#f11').live('click', function(){
			var q = $(this).attr('rel');
			alert($('#f11txt').attr('title'));
			$(this).css('opacity', '.5');
		});
	});


// klikalne elementy z clasą a
	$(".a").click(function(){
		window.location = $(this).find("a").attr("href");
		return false;
	});


// usun link z img
	$('img').closest('a').addClass('nohover');


// newsletter, znikający tekst
	$('.inputfocustxt').focus(function(){
		if ($(this).val() == $(this).attr("title")){
			$(this).val("");
		}
	}).blur(function(){
		if ($(this).val() == ""){
			$(this).val($(this).attr("title"));
		}
	});

});



$(window).load(function(){});



$(window).resize(function(){

	// f11 button z prawej pokazuj jak mala rozdz
	$(function(){
		if($(window).height() < 800){
			$('#f11').show('slow');
		}
		else {
			$('#f11').hide('slow');
		}
	});

});
