$(document).ready(function(){

	// obsługa języków!
	$('ul.langsList li a').click(function(){
		var lang = $(this).attr("lang");
		$.cookie("lang", lang);
	});

	//subskrypcja
	$('.subscription').hide();

	$('.stropexcad').click(function() {
		$('.subscription').slideToggle(400);
		return false;
	});
	
	
	// link na glore strony
	$('a[href=#top]').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});

	
	//dyplomy
	$('.dyplom-desc').hide();

	/*
	
	$(".dyplom-item a").hover(
	  function () {
	    $(this).find(".dyplom-desc").fadeIn(400);
	  },
	  function () {
	    $(this).find(".dyplom-desc").fadeOut(400);
	  }
	);

*/

	
	
	
	//galeria kwalfikacje
	$("a[rel=lightbox[gallery]]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Zdjęcie ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});	
	
		//galeria kwalfikacje
	$("a[rel=galeria2], a[rel=galeria]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Zdjęcie ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});	
	
	
	$("input.email").click(function(){
		if ( $(this).val() == "Twój e-mail") { $(this).val(''); }
		
		$(this).css('color', '#434343');
	});
	
	
	
	// video z oferty
	
	$(".video-box-item a[rel]").overlay({
	
	effect: 'apple', 
	top: '10%',
	mask: {
		color: '#000000',
		loadSpeed: 200,
		opacity: 0.2
		}
	});
	
	
	
	$(".pkwalifikacje-dyplomy").click(function(){
		$('.dyplomy').slideToggle();
		if ( $(".dyplomy").is(":visible") ) {
			$('html,body').animate({scrollTop: $('.dyplomy').offset().top}, 1000);
		}	
	});
	
	
	
	
	
	$('.dyplomy').css('display', 'none');
	
	
	
	$(".pokaz-formularz").click(function(){
		$('.formularz-kontaktowy').slideToggle();
		
		if ( $(".formularz-kontaktowy").is(":visible") ) {
			$('html,body').animate({scrollTop: $('.formularz-kontaktowy').offset().top}, 1000);
		}	

	});
	
	$('.formularz-kontaktowy').css('display', 'none');
	
	
	// animacja intro top
	
	$(".topintro img").animate({ 
    	opacity: 1
  	}, 1000 );

	
	//$(".textintro").delay(800).animate({ 
    //	opacity: 1, 
    //	left: "40px"
  	//}, 1000 );

	
	// ustawienie rownej wyskosci elementów
	
	//var toprowheight = $(".top-row").height();
	//$(".top-row-block").height(toprowheight);
	
	

	
	
	
	$("ul.sitebar-list-aktualnosci").tabs("div.panes-aktualnosci > div", {
	effect: 'fade',
	fadeInSpeed: "slow"
	
	});
	
	
	
	$(".scrollable").scrollable({circular: true}).navigator().autoscroll({
	interval: 6000		
	});
	
	

	
	
	$("#contactForm").validate({
   		submitHandler: function(form) {
      
	      	var dataString = $("form#contactForm").serialize();
			//alert (dataString);return false;
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {
	 		 // search for selectors you want to add hover behavior to
			
			} else {
				$(".formularz-kontaktowy-in").html("<div id=\"messagesend\"><img src=\"layouts/images/ajax-loader.gif\" alt=\"Postęp\" /><br /><p>Trwa wysyłanie.</p></div>");
			}
					
			$("#messagesend")
				.fadeIn(1500, function() {
					$("#messagesend");
				});
			
			$.ajax({
	      		type: "POST",
	      		url: "mail.php",
	      		data: dataString,
	      		success: function() {
					$(".formularz-kontaktowy-in").html("<div id=\"message\"></div>");
					$("#message").html("<h2>Wiadomość została wysłana.</h2>")
					.append("<p>Wkrótce otrzymasz odpowiedz.</p>")
					.hide()
					.fadeIn(1500, function() {
					$("#message");
					});
				}
     		});
      
   			form.submit();
   		}	
	});

	
	
	
	
	
	$("#subscriptionForm").validate({
   		submitHandler: function(form) {
      
	      	var dataString = $("form##subscriptionForm").serialize();
			//alert (dataString);return false;
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {
	 		 // search for selectors you want to add hover behavior to
			
			} else {
				$(".formularz-kontaktowy-in").html("<div id=\"messagesend\"><img src=\"images/ajax-loader.gif\" alt=\"Postęp\" /><br /><p>Trwa wysyłanie.</p></div>");
			}
					
			
			$.ajax({
	      		type: "POST",
	      		url: "maillist.php",
	      		data: dataString,
	      		success: function() {
					$(".subscription-form").html("<div id=\"subscriptionmessage\"></div>");
					$("#subscriptionmessage").html("Twój email został dodany. Dziękujemy.")
					.hide()
					.fadeIn(1500, function() {
					$("#subscriptionmessage");
					});
				}
     		});
      
   			
   		}	
	});


	$("#arcadiaForm").validate();

	
	Cufon.replace('#contetn-footer .email, .block-red-link, h1, h2, h3, h4, h5, h6, nav ul li a, .top-row .item .itemtitle, .itemreadmore');

	
	Cufon.replace('nav ul li a', {
		textShadow: '#FFFFFF 1px 1px'
	});	
		

	$(".closeOverflowBox").click(function() {
		$("#overflowBox").fadeOut();
	});	
	
	
	$('html').click(function() {
	 $("#overflowBox").fadeOut();
	 });
	
	 $('#wieniecWapperImages').click(function(event){
	     event.stopPropagation();
	 });
	
	
	var brakloop = false;
	
	$('.wieniecImage1small').click(function() {
		$(".wieniecImage1").show();
		$(".wieniecImage2").hide();
		$(".wieniecImage1small").css("border-color","#fff");
		$(".wieniecImage2small").css("border-color","#989898");
		$(".wieniecNav").attr("breakloop", "true");
	});
	
	$(".wieniecImage2small").css("border-color","#989898");
	$('.wieniecImage2small').click(function() {
		$(".wieniecImage2").show();
		$(".wieniecImage1").hide();
		$(".wieniecImage2small").css("border-color","#fff");
		$(".wieniecImage1small").css("border-color","#989898");
		$(".wieniecNav").attr("breakloop", "true");
		

		
	});

	
	
	
	setInterval("swapImages()", 4000);
	setInterval("swapImagesSmall()", 3000);

});


function swapImages(){
    	
    	if ( !$(".wieniecNav").attr("breakloop")) {

			if ($('.wieniecImage2').is(':visible')) {
		 		$(".wieniecImage2").fadeOut(500);
		 		$(".wieniecImage2small").css("border-color","#989898");
				$(".wieniecImage1small").css("border-color","#fff");
			}  else {
		 		$(".wieniecImage2").fadeIn(500);
				$(".wieniecImage2small").css("border-color","#fff");
				$(".wieniecImage1small").css("border-color","#989898");
			}  
			
		}
      
    }


function swapImagesSmall(){
    	
    	if ( !$(".wieniecNav").attr("breakloop")) {

			if ($('.smallwieniecImage2').is(':visible')) {
		 		$(".smallwieniecImage2").fadeOut(500);

			}  else {
		 		$(".smallwieniecImage2").fadeIn(500);
				
			}  
			
		}
      
    }
