function hovering(klasa) {
    var klasa_z_hoverem = (klasa + "-hover").substr(1,100);
	
    $(klasa).hover(function() {
        $(this).addClass(klasa_z_hoverem);
    }, function() {
        $(this).removeClass(klasa_z_hoverem);
    });
}


function dodajLink(klasa) {
    $(klasa+" a").each(function() {
        $(this).parents(klasa).click(function() {
            window.location.href = $(this).find("a").attr("href");
        });
    });
}


function antyspam() {
    $(".antyspam").each(function() {
        var kod = "<a href=\"mailto:";
        var c = "";
        var l = "";
        var s = $(this).html();
        for (var i=0; i < s.length; i++) {
            l = s.charCodeAt(i)-2;
            c += String.fromCharCode(l);
        }
        kod += c;
        kod +=("\">");
        kod += c;
        kod +="</a>";
        $(this).html(kod);
        $(this).show();
    });
}



function external_links() {
    $("a").each(function() {
        if ( ($(this).attr("href")) && ($(this).attr("rel")=="external")) {
            $(this).attr("target","_blank");
        }
    });
}



function pirobox() {
    $().piroBox({
        my_speed: 600, //animation speed
        bg_alpha: 0.5, //background opacity
        radius: 4, //caption rounded corner
        scrollImage : true, // true == image follows the page, false == image remains in the same open position
        pirobox_next : "piro_next_out", // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
        pirobox_prev : "piro_prev_out",// Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
        close_all : ".piro_close, .piro_overlay",// add class .piro_overlay(with comma)if you want overlay click close piroBox
        slideShow : "", // just delete slideshow between "" if you don"t want it.
        slideSpeed : 4 //slideshow duration in seconds(3 to 6 Recommended)
    });
}


function formularz() {
    $(".removeInputFile").click(function() {
        $(this).parent("div").remove();
    });

    $(".addInputFile").click(function() {
        var cnt = $(this).attr("rel");
        cnt++;
        $(this).attr("rel", cnt);
        $("<div class=\"inputfile p_"+cnt+"\">\n\
            <input class=\"srebrny\" type=\"file\" name=\"file_"+cnt+"\"/>\n\
            <span class=\"removeInputFile\">\n\
            <img src=\"/images/ico-minus.gif\" alt=\"[-]\" style=\"vertical-align: middle\"/>\n\
            &nbsp;Usuń ten plik</span></div>").insertBefore(this);
        $(".p_"+cnt).children(".removeInputFile").click(function() {
            $(this).parent("div").remove();
        });
    });
}


function mapaGoogle() {
    //http://maps.google.pl/maps?q=52.227475,21.084833&num=1&sll=52.227422,21.085585&sspn=0.001955,0.005681&hl=pl&ie=UTF8&ll=52.227422,21.085585&spn=0.001955,0.005681&z=18
    var Malarowicz = new google.maps.LatLng(52.227475,21.084833);
    var center = new google.maps.LatLng(52.227475,21.084833);

    var myOptions = {
        zoom: 13,
        center: center,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("mapaGoogle"), myOptions);

    var malarowiczMarker = new google.maps.Marker({
        position: Malarowicz,
        map: map
    });

    var malarowiczInfo = new google.maps.InfoWindow({
        content: "<div style='font-size: 8pt'>Biuro Ubezpieczeń<br/>Katarzyny Malarowicz<br/>ul. gen. Romana Abrahama 4<br/>03-982 Warszawa</div>"
    });


    google.maps.event.addListener(malarowiczMarker, 'click', function() {
        malarowiczInfo.open(map, malarowiczMarker);
    });

}


$().ready(function(){
    $("#top-link").click(function(){
        window.location.href="/";
    });

    formularz();
    dodajLink(".addlink");
    external_links();
    antyspam();
    if ($("#mapaGoogle").length > 0) mapaGoogle();

    jQuery.validator.addMethod("nazwisko", function(value, element){
        return this.optional(element) || /^.{2,}\s.{2,}$/.test(value);
    }, "Proszę wprowadzić imię i nazwisko.");
    
    $("#contact-form").validate();
});
