$(document).ready(function(){
	
	Cufon.replace(['.box > .f27'],	 { fontFamily: 'Georgia', textShadow: '0px 1px rgba(250, 250, 250, 0.4)', hover: true });
	Cufon.replace(['.cufonIt, .mainMenu li, .title'],	 { fontFamily: 'Georgia', hover: true });
	
	$("a img, input[type=image]").hover(
	  function () {
		$(this).fadeTo("fast", 0.7);
	  }, 
	  function () {
		$(this).fadeTo("fast", 1);
	  }
	);	
	
	$(".mainMenu li:last-child").not(".active").addClass("last");
	$(".sideRight > .menu > li > ul > li:last-child, .breadcrumb a:last-child").addClass("last");
	$(".nodeWork:last").addClass("lastWork");
	$('.gridList li:nth-child(4n)').addClass('fourth');
	//$('.gridList li > div:not(:has(p))').parent().addClass('empty');
	
	
    $('.sPortfolio01').mouseover(function(){
        $(this).stop(true,false).animate({left:15,top:33},500);
    });
    $('.sPortfolio01').mouseleave(function(){
        $(this).stop(true,false).animate({left:13,top:25},500);
	});

    $('.sPortfolio02').mouseover(function(){
        $(this).stop(true,false).animate({left:22,bottom:26},500);
    });
    $('.sPortfolio02').mouseleave(function(){
        $(this).stop(true,false).animate({left:18,bottom:18},500);
	});

    $('.sPortfolio03').mouseover(function(){
        $(this).stop(true,false).animate({right:20,top:20},500);
    });
    $('.sPortfolio03').mouseleave(function(){
        $(this).stop(true,false).animate({right:15,top:10},500);
	});
	
    $('.sPortfolio04').mouseover(function(){
        $(this).stop(true,false).animate({right:6,bottom:25},500);
    });
    $('.sPortfolio04').mouseleave(function(){
        $(this).stop(true,false).animate({right:1,bottom:35},500);
	});

    $('.sPortfolioMain').mouseover(function(){
        $(this).stop(true,false).animate({left:185,top:55},500);
    });
    $('.sPortfolioMain').mouseleave(function(){
        $(this).stop(true,false).animate({left:180,top:50},500);
	});
	

	$('.nodeTeam dl:nth-child(3n);').addClass('teamMemberOdd');
	
	if($('.sideRight').height()>$('.node').height()) {  $('.node').css("min-height", $('.sideRight').height()); }
	
	$('.node p, .node li').not('.node p.noScript, .node .gridList li, .node .formStandard, .node .title, .node .cufonIt, .node .picTeam, .node dl p').singleLetter();

 $(function(){	
	var validator = $(".formContact").validate({
		rules: {
			fName: {
				required: true,
				minlength: 3
			},
			fName2: {
				required: true,
				minlength: 2
			},
			fCaptcha: {
				required: true,
				minlength: 6
			},
			fPhone: {
				required: true,
				minlength: 7
			},
			fMail: {
				required: true,
				email: true
			},
			fMessage: {
				required: true,
				minlength: 10
			}
		},
		messages: {
			fName: {
				required: "Podaj proszę swoje imię i nazwisko",
				minlength: "Twoję imię musi mieć co najmniej 3 litery"
			},
			fName2: {
				required: "Podaj proszę nazwę firmy",
				minlength: "Nazwa firmy musi mieć co najmniej 2 litery"
			},
			fCaptcha: {
				required: "Przepisz kod z obrazka",
				minlength: "Kod z obrazka ma 6 liter"
			},
			fPhone: {
				required: "Podaj proszę kontaktowy numer telefonu",
				minlength: "Numer telefonu powinien zawierać co najmniej 7 cyfr"
			},
			fMail: {
				required: "Wprowadź proszę poprawny adres e-mail",
				email: "Wprowadź proszę poprawny adres e-mail"
			},
			fMessage: {
				required: "Wpisz proszę wiadomość",
				minlength: "Twoja wiadomość musi składać się co najmniej z jednego wyrazu"
			}
		},
		errorPlacement: function(error, element) {
			error.appendTo(".errors");
		},
		errorElement: "p",
		errorClass: "error",
		invalidHandler: function(form) {
		  $.scrollTo('.formContact',400);
		},
		submitHandler: function(form) {
			$(".formStandard").removeClass("clearInputs");
			$.ajax({
				type: "POST",
				data: { fName : $("input[name=fName]").val(),
						fName2 : $("input[name=fName2]").val(),
						fTarget : $("input[name=fTarget]").val(),
						fSubject : $("input[name=fSubject]").val(),
						fDate : $("input[name=fDate]").val(),
						fNumber : $("input[name=fNumber]").val(),
						fMail : $("input[name=fMail]").val(),
						fPhone : $("input[name=fPhone]").val(),
						fCaptcha : $("input[name=fCaptcha]").val(),
						fMessage : $("textarea[name=fMessage]").val()
						},
				url: '/flymail.php',
				error: function(msg){
					alert( "ERROR: " + msg );
				},
				beforeSend: function(){
					$(".ajax").show();
				},
				success: function(msg){
					$(".message").html(msg);
					$(".success").parent().parent().prev().remove();
					$.scrollTo('.message',400);
					$(".ajax").hide();			
				}
			});
		}
	  });
	});
	
$(function(){	
	var validator = $(".formNewsletter").validate({
		rules: {
			fName: {
				required: true,
				minlength: 3
			},
			fCaptcha: {
				required: true,
				minlength: 6
			},
			fPosition: {
				required: true,
				minlength: 3
			},
			fMail: {
				required: true,
				email: true
			}
		},
		messages: {
			fName: {
				required: "Podaj proszę swoje imię i nazwisko",
				minlength: "Twoję imię musi mieć co najmniej 3 litery"
			},
			fCaptcha: {
				required: "Przepisz kod z obrazka",
				minlength: "Kod z obrazka ma 6 liter"
			},
			fPosition: {
				required: "Podaj proszę swoją pozycję w firmie",
				minlength: "Tytuł stanowiska musi mieć co najmniej 2 litery"
			},
			fMail: {
				required: "Wprowadź proszę poprawny adres e-mail",
				email: "Wprowadź proszę poprawny adres e-mail"
			}
		},
		errorPlacement: function(error, element) {
			error.appendTo(".errors");
		},
		errorElement: "p",
		errorClass: "error",
		invalidHandler: function(form) {
		  $.scrollTo('.formContact',400);
		},
		submitHandler: function(form) {
			$(".formNewsletter").removeClass("clearInputs");
			$.ajax({
				type: "POST",
				data: { fName : $("input[name=fName]").val(),
						fPosition : $("input[name=fPosition]").val(),
						fName2 : $("input[name=fName2]").val(),
						wojewodztwo : $("select[name=wojewodztwo] option:selected").text(),
						fMail : $("input[name=fMail]").val(),
						fCaptcha : $("input[name=fCaptcha]").val(),
						akcja : '1'
						},
				url: '/iberomail.php',
				error: function(msg){
					alert( "ERROR: " + msg );
				},
				beforeSend: function(){
					$(".ajax").show();
				},
				success: function(msg){
					$(".message").html(msg);
					$(".success").parent().parent().prev().remove();
					$.scrollTo('.message',400);
					$(".ajax").hide();			
				}
			});
		}
	  });
	});
	
$(function(){	
	var validator = $(".formNewsletterOut").validate({
		rules: {
			fCaptcha: {
				required: true,
				minlength: 6
			},

			fMail: {
				required: true,
				email: true
			}
		},
		messages: {
			fCaptcha: {
				required: "Przepisz kod z obrazka",
				minlength: "Kod z obrazka ma 6 liter"
			},

			fMail: {
				required: "Wprowadź proszę poprawny adres e-mail",
				email: "Wprowadź proszę poprawny adres e-mail"
			}
		},
		errorPlacement: function(error, element) {
			error.appendTo(".errors");
		},
		errorElement: "p",
		errorClass: "error",
		invalidHandler: function(form) {
		  $.scrollTo('.formContact',400);
		},
		submitHandler: function(form) {
			$(".formNewsletter").removeClass("clearInputs");
			$.ajax({
				type: "POST",
				data: {
						fMail : $("input[name=fMail]").val(),
						fCaptcha : $("input[name=fCaptcha]").val(),
						akcja : '2'
						},
				url: '/iberomail.php',
				error: function(msg){
					alert( "ERROR: " + msg );
				},
				beforeSend: function(){
					$(".ajax").show();
				},
				success: function(msg){
					$(".message").html(msg);
					$(".success").parent().parent().prev().remove();
					$.scrollTo('.message',400);
					$(".ajax").hide();			
				}
			});
		}
	  });
	});
	
 $(function(){	
	var validator = $(".formShare").validate({
		rules: {
			fName: {
				required: true,
				minlength: 3
			},
			fName2: {
				required: true,
				minlength: 2
			},
			fCaptcha: {
				required: true,
				minlength: 6
			},
			fMail: {
				required: true,
				email: true
			},
			fMail2: {
				required: true,
				email: true
			},
			fMessage: {
				required: true,
				minlength: 10
			}
		},
		messages: {
			fName: {
				required: "Podaj proszę swoje imię i nazwisko",
				minlength: "Twoję imię musi mieć co najmniej 3 litery"
			},
			fName2: {
				required: "Podaj proszę imię i nazwisko znajomego",
				minlength: "Imię znajomego musi mieć co najmniej 3 litery"
			},
			fCaptcha: {
				required: "Przepisz kod z obrazka",
				minlength: "Kod z obrazka ma 6 liter"
			},
			fMail: {
				required: "Wprowadź proszę poprawny adres e-mail",
				email: "Wprowadź proszę poprawny adres e-mail"
			},
			fMail2: {
				required: "Wprowadź proszę poprawny adres e-mail",
				email: "Wprowadź proszę poprawny adres e-mail"
			},
			fMessage: {
				required: "Wpisz proszę wiadomość",
				minlength: "Twoja wiadomość musi składać się co najmniej z jednego wyrazu"
			}
		},
		errorPlacement: function(error, element) {
			error.appendTo(".errors");
		},
		errorElement: "p",
		errorClass: "error",
		invalidHandler: function(form) {
		  $.scrollTo('.formShare',400);
		},
		submitHandler: function(form) {
			$(".formStandard").removeClass("clearInputs");
			$.ajax({
				type: "POST",
				data: { fName : $("input[name=fName]").val(),
						fName2 : $("input[name=fName2]").val(),
						fMail : $("input[name=fMail]").val(),
						fMail2 : $("input[name=fMail2]").val(),
						fCaptcha : $("input[name=fCaptcha]").val(),
						fMessage : $("textarea[name=fMessage]").val()
						},
				url: '/share.php',
				error: function(msg){
					alert( "ERROR: " + msg );
				},
				beforeSend: function(){
					$(".ajax").show();
				},
				success: function(msg){
					$(".message").html(msg);
					$(".success").parent().parent().prev().remove();
					$.scrollTo('.message',400);
					$(".ajax").hide();			
				}
			});
		}
	  });
	});	
	
	$('.nodeList2 .more a').click(function() {
		//$('.nodeList2 .hidden').not($(this).parent().parent().next('.hidden')).hide();
		$(this).parent().parent().next('.hidden').slideToggle();
		return false;
	});

	equalHeight($(".boxSpecial > .boxWhite"));	
	$('.setMiddle').vAlign();

 });
(function ($) {
  $.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2-5;
	$(this).css('top', mh);
	});
};
})(jQuery); 
function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
(function ($) {
  $.fn.singleLetter = function() {
	return this.each(function(i){            
       var numWords = new Array();
	   var words = jQuery.trim($(this).html());
       numWords = words.split(' ');
       var numWordsCounter = numWords.length;
       if(words === '')
         numWordsCounter = -1;
       if(numWordsCounter>0){
         var i =0;
         for(var j=0; j<=numWordsCounter-1; j++){
              if(numWords[i].length==1 && numWords[i]!=''){ 
				if(numWords[i+1].length>1){
				  numWords[i] = '<span class="singleLetter">'+numWords[i];
				  numWords[i+1] = numWords[i+1]+"</span>"; 
				} else {
				  numWords[i] = '<span class="singleLetter">'+numWords[i];
				  numWords[i+2] = numWords[i+2]+"</span>";	
				}
			  }
              i++;
         }
		 $(this).html(numWords.join(' '));
       }  
	});
  };
})(jQuery);
