jQuery.preloadImages = function(){
	for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);
	}
}
$(document).ready(function(){
	$.preloadImages('gfx_4b/foot_logo1_h.png','gfx_4b/foot_logo2_h.png','gfx_4b/foot_logo3_h.png','gfx_4b/foot_logo4_h.png','gfx_4b/foot_logo5_h.png','http://www.fly-high.pl/gfx_www/fly_cms_small.png','/gfx/loader.gif');

	$('.zajawka span').click(function(){
		$(this).parent().prev().slideDown();
		$(this).parent().hide();
	});
	$('.full span.zwin').click(function(){
		$(this).parent().slideUp();
		$(this).parent().next().show();
	});
	$('#fly').mouseover(function(){
		$('#fly img').attr('src','http://www.fly-high.pl/gfx_www/fly_cms_small.png');
	});
	$('#fly').mouseout(function(){
		$('#fly img').attr('src','http://www.fly-high.pl/gfx_www/fly_cms_small_bw.png');
	});

	$('#main-menu a').mouseover(function(){
		if(!$(this).hasClass('selected')){
			$('#main-menu a').removeClass('selected');
		}
	});

	$('#zapytaj').click(function(){
		var tresc = $('#tresc').val();
		var email = $('#email').val();
		var telefon = $('#telefon').val();
		var nazwa = $('#nazwa').val();

		if(tresc == '' || email == '' || telefon == '' || nazwa == ''){
			$('#kontakt-error').html('Wypełnij wymagane pola!');
			$('#kontakt-error').fadeIn("slow");
			return false;
		}
		if(!echeck(email)){
			$('#kontakt-error').html('Nieprawidłowy adres e-mail!');
			$('#kontakt-error').fadeIn("slow");
			return false;
		}
		if(telefon.length < 9){
			$('#kontakt-error').html('Nieprawidłowy numer telefonu!');
			$('#kontakt-error').fadeIn("slow");
			return false;
		}

		$('#kontakt-inputs').hide();
		$('#kontakt-error').hide();
		$('#kontakt-progress').fadeIn("slow");

		$.post("index.php", {
			email: email,
			nazwa: nazwa,
			telefon: telefon,
			zapytaj_spolki: 1,
			tresc: tresc
			}, function(response){
				$('#kontakt-progress').hide();

				if(response == 'OK'){
					$('#kontakt-success').fadeIn("slow");
				}
				else{
					$('#kontakt-error').html(unescape(response));
					$('#kontakt-error').fadeIn("slow");
				}
			});
		return false;
	});
});
