function jezyki() {
    $("#en").click(function() {
        window.location.href="/en";
    });
    $("#de").click(function() {
        window.location.href="/de";
    });
    $("#pl").click(function() {
        window.location.href="/pl";
    });
}

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(".pozycja-menu").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 gorneMenu() {
    $("#menu-gorne-pozycje li").each(function(index) {
        $(this).attr("name", index);
        $(this).append("<span class=\"hover\">&nbsp;</span>");
    });

    $("#menu-gorne-pozycje li").hover(function(){
        var id = $(this).attr("name");
        $(".hover").animate({
            height: 0,
            width: 0
        },{
            queue: false,
            duration: 500
        });

        $(this).find(".hover").animate({
            height: 60,
            width: 200
        },{
            queue: false,
            duration: 500,
            easing: "easeOutBounce"
        });

        $("#menu-gorne-dol-opis div").each(function() {
            if ($(this).attr("name") != id) $(this).slideUp();
        });

        $("#menu-gorne-dol-opis-"+id).slideDown();
    });

    $("#menu-gorne-pozycje .selected").hover();
}


function zwijacz() {
    $(".zwijacz").click(function() {
        if ($(this).hasClass("rozwiniety")) {
            $(this).children(".zawartosc").hide();
            $(this).removeClass("rozwiniety");
        } else {
            $(this).children(".zawartosc").show();
            $(this).addClass("rozwiniety");
        }
    });

}


function valid() {
    
}


$().ready(function(){
    jQuery.validator.addMethod("nazwisko", function(value, element){
        return this.optional(element) || /^.{2,}\s.{2,}$/.test(value);
    }, "Wprowadź imię i nazwisko");

    
    $(".carousel").jCarouselLite({
        auto: true,
        timeout: 2000,
        speed: 500,
        scroll: 1,
        easing: "easeOutBounce",
        circular: true,
        btnPrev: "#menu-gorne-slider-lewa",
        btnNext: "#menu-gorne-slider-prawa"
    });

    $('.tooltip').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        fade: 250
    });


    $("#mapa-google").html("");
    /*  $("#mapa-google").bMap({
        mapZoom: 7,
        mapCenter:[51.0082, 17.965608],
        markers:{
            "data":[{
                "lat":50.316604,
                "lng":17.375432,
                "title":"EuroFarex",
                "body":"ul. Wyspiańskiego 9<br/>48-340 Głuchołazy"
            }]
        }
    });*/

    function initialize() {
        var myLatLng = new google.maps.LatLng(50.316604, 17.375432);
        var center = new google.maps.LatLng(51.0082, 17.965608);
        var myOptions = {
            zoom: 7,
            center: myLatLng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        var map = new google.maps.Map(document.getElementById("mapa-google"), myOptions);
        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map
        });

    }


    $("#mapaPolski").flash({
        src: "/images/mapaPolski.swf",
        width: 280,
        height: 255,
        wmode: "opaque",
        flashvars: {
            pre: "/siec_sklepow,",
            post: "/"+$("#mapaPolski").attr("title")+"/",
            red: 100,
            green: 200,
            blue: 0,
            nasycenie: 40
        }
    });

    jezyki();

    gorneMenu();
    hovering(".menu-gorne");
    hovering(".slider-navi");
    hovering(".pozycja-menu");
    dodajLink(".pozycja-menu");
    external_links();
    antyspam();
    pirobox();
    
    $("#zamowienie").validate();

    if ($("#mapa-google").length) initialize();

});
