﻿//* Różne funkcje

// Przełączanie 2-óch div (informacje/dane techniczne)
$(document).ready(function() {

    $("a.pokazInfo1").click(function() {
        $(this).parents("div.tresc").children("div.info1").show('slow');
        $(this).parents("div.tresc").children("div.info2").hide('slow');
    });

    $("a.pokazInfo2").click(function() {
        $(this).parents("div.tresc").children("div.info1").hide('slow');
        $(this).parents("div.tresc").children("div.info2").show('slow');
    });
});

// Obsługa menu	
$(function() {
	$("a.menuparent").click(function(){
		$(this).parent().children("ul.podmenu").toggle('slow');
	});
});            

// jQuery lightbox plugin - porzucenie normalnego lightboxa 2.03
$(function() {
	// Użyj przykładu:
	$('a[rel="lightbox"]').lightBox(); // Wybiera wszystkie linki zawierające atrybut rel="lightbox" - NIE DZIAŁA
	// Wybiera wszystkie linki dla id="lightbox1" etc...
	$('a#lightbox1').lightBox(); // Wybiera wszystkie linki z ID="lightbox1"
	$('a#lightbox2').lightBox(); // Wybiera wszystkie linki z ID="lightbox2"
	$('a#lightbox3').lightBox(); // Wybiera wszystkie linki z ID="lightbox3"
	$('a#lightbox4').lightBox(); // Wybiera wszystkie linki z ID="lightbox4"
	$('a#lightbox5').lightBox(); // Wybiera wszystkie linki z ID="lightbox5"
	// This, or...
	$('a.lightbox').lightBox(); // Wybiera wszystkie linki z class="lightbox"
	// This, or...
	//$('a').lightBox(); // Wybiera wszystkie linki na stronie
	// ... The possibility are many. Use your creative or choose one in the examples above
});

// funkcja walidacji formularza jQuery.validate plugin

SubmittingForm=function() {
    alert("Dziękujemy za wypełnienie formularza.");
}

$(function() {
           $("#form1").validate({
		success: function(label) {
			label.css({background: url('images/checked.gif')})
		},
               submitHandler:function(form) {
                   SubmittingForm();
               },
               rules: {
                   Imie: "required",
				Nazwisko: {
					required: true,
					minlength: 9,
					digits: true,
				},
                   email: {
                       required: true,
                       email: true
                   },
                   content: {
                       required: true
                   }
               },
               messages: {
                   comment: "Wprowadź komentarz."
               }
           });
       });

// Powiększa obrazek po najechaniu myszką na miniaturkę (kontakt.html) jQuery
$(function() {
	$("img.mini").mouseover(function() {
		$(this).parents("div.fotka").children("div.duze").show('slow');
	});
			
	$("img.mini").mouseout(function() {
		$(this).parents("div.fotka").children("div.duze").hide('slow');
	});
});
		
// Tabulatory na podstronach jQuery
$(function() {

	//Domyślna akcja 
	$(".tab_content").hide(); //Ukrycie całej zawartości
	$("ul.tabs li:first").addClass("active").show(); //Aktywacja pierwszego taba
	$(".tab_content:first").show(); //Pokaż zawartość pierwszego taba
	
	//Zdfarzenie na kliknięcie myszką
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Zdjęcie atrybutu aktywny z wszystkich tabów
		$(this).addClass("active"); //Dodanie klasy "active" do wybranego taba
		$(".tab_content").hide(); //Ukryj całą zawartość tabów
		var activeTab = $(this).find("a").attr("href"); //Znajdź wartość rel atrybutu do identyfikacji aktywnego taba + zawartość
		$(activeTab).fadeIn("slow"); //Rozświetla aktywny tab
		return false;
	});

});
		
// Obsługa tooltipa
	//Select all anchor tag with rel set to tooltip
	$('a[rel=tooltip]').mouseover(function(e) {
		
		//Grab the title attribute's value and assign it to a variable
		var tip = $(this).attr('title');	
		
		//Remove the title attribute's to avoid the native tooltip from the browser
		$(this).attr('title','');
		
		//Append the tooltip template and its value
		$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');
		
		//Set the X and Y axis of the tooltip
		$('#tooltip').css('top', e.pageY - 50 );
		$('#tooltip').css('left', e.pageX - 270 );
		
		//Show the tooltip with faceIn effect
		$('#tooltip').fadeIn('500');
		$('#tooltip').fadeTo('10',0.8);
		
	}).mousemove(function(e) {
	
		//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
		$('#tooltip').css('top', e.pageY - 50 );
		$('#tooltip').css('left', e.pageX - 270 );
		
	}).mouseout(function() {
	
		//Put back the title attribute's value
		$(this).attr('title',jQuery('.tipBody').html());
	
		//Remove the appended tooltip template
		$(this).children('div#tooltip').remove();
	});		
	
// Otwiera link w nowym oknie/karcie JavaScript
function externalLinks() {
        if( ! document.getElementsByTagName )
            return;

    var anchors = document.getElementsByTagName( "a" );
         for (var i=0; i<anchors.length; i++) {
                   var anchor = anchors[i];
                   if( anchor.getAttribute( "href" ) && anchor.getAttribute( "rel" ) == "external" )
                     anchor.target = "_blank";
         }
}

window.onload = externalLinks;

// Miganie tekstu JavaScript
function flash(id, kolor, czas, kolor2, czas2)
{
	document.getElementById(id).style.color = kolor;
	setTimeout('flash("' + id + '","' + kolor2 + '",' + czas2 + ',"' + kolor + '",' + czas + ')', czas);
}

