$(document).ready(function() {
   
    //$("#login_form input.login").focus();
    $("#SearchForm input.search").focus();
    $("#SearchForm input.search").click(function() {
        $(this).val("");
        return true;
    });
    
    $("#SearchForm2 input.search").focus();
    
    //$("#searchphrase").focus(function() {
    /*$("#SearchForm input.search").focus(function() {
        if ($(this).val() == 'szukane hasło') {
            $(this).val('');
            $(this).css('color','#000');
        }
        else
            $(this).css('color','#999');
        return true;
    });*/
        

    $("#forgot_password_link").click(function() {
        //$("#forgot_password_form").css("visibility", "visible");
        $("#forgot_password_form").css("display", "block");
        $("#forgot_password_div").css("display", "none");
        return false;
    });
    $("#login_form input").focus(function() {
        //$("#forgot_password_form").css("visibility", "hidden");
        $("#forgot_password_form").css("display", "none");
        $("#forgot_password_div").css("display", "block");
    });

    $("#forgot_password_form").css("display", "none");
    //$("#forgot_password_form").css("visibility","hidden");
    
    var duzyprodukt1h=parseInt($("#duze_produkty .indent").eq(0).height());	//var duzyprodukt1h=parseInt($("#duze_produkty .indent").eq(0).css("height"));
    var duzyprodukt2h=parseInt($("#duze_produkty .indent").eq(1).height());	//var duzyprodukt2h=parseInt($("#duze_produkty .indent").eq(1).css("height"));
    var duzyproduktMax = Math.max(duzyprodukt1h, duzyprodukt2h);
    $("#duze_produkty .indent").css("height", duzyproduktMax + "px");

    /*$("#duze_produkty a.buy-button").eq(0).css("top", (duzyproduktMax - duzyprodukt1h) + "px");
    $("#duze_produkty a.buy-button").eq(1).css("top", (duzyproduktMax - duzyprodukt2h) + "px");*/
    $("#duze_produkty a.buy-button").eq(0).css("top", (duzyproduktMax - duzyprodukt1h + 25) + "px");
    $("#duze_produkty a.buy-button").eq(1).css("top", (duzyproduktMax - duzyprodukt2h + 25) + "px");

    var maly1h = 0;
    var maly2h = 0;
    var maly3h = 0;
    var maly4h = 0;
    
    if ($(".box3").length > 0)
	maly1h = parseInt($(".box3").eq(0).height());
    if ($(".box3").length > 1)
	maly2h = parseInt($(".box3").eq(1).height());
    if ($(".box3").length > 2)
	maly3h = parseInt($(".box3").eq(2).height());
    if ($(".box3").length > 3)
	maly4h = parseInt($(".box3").eq(3).height());
	
    var malyproduktMax = Math.max(maly1h, maly2h, maly3h, maly4h);
    $(".box3").css("height", malyproduktMax + "px");
    
    if ($(".box3 a.link").length > 0)
	$(".box3 a.link").eq(0).css("top", (malyproduktMax - maly1h) + "px");
    if ($(".box3 a.link").length > 1)
	$(".box3 a.link").eq(1).css("top", (malyproduktMax - maly2h) + "px");
    if ($(".box3 a.link").length > 2)
	$(".box3 a.link").eq(2).css("top", (malyproduktMax - maly3h) + "px");
    if ($(".box3 a.link").length > 3)
	$(".box3 a.link").eq(3).css("top", (malyproduktMax - maly4h) + "px");
    $(".jsonly").css("visibility", "visible");
     
    $("#produkt .ukryty").css("display", "none");
    $(".switch").click(function() {
            var id = "#ukryty" + parseInt($(this).attr("id").substring(6));
            if ($(id).css("display")=="none") {
                $(id).css("display", "block");
                $(this).find(".link_red").css("visibility","hidden");
            }
            else {
                $(id).css("display", "none");
                $(this).find(".link_red").css("visibility","visible");
            }
    });
    
//
//
$(".sklep_home").parent().each(function() {
    //find(".sklep_home").
    //alert($(this).attr("id"));
    var row = $(this).find(".sklep_home");
    var h1 = parseInt(row.eq(0).height());
    var h2 = parseInt(row.eq(1).height());
    var h3 = parseInt(row.eq(2).height());
    row.each(function() {
	$(this).height(Math.max(h1, h2, h3));
    });
});
//var malyproduktMax = Math.max(maly1h, maly2h, maly3h, maly4h);
//$(".box3").css("height", malyproduktMax + "px");

// 
    $('a.lightbox').lightBox({
	imageBtnPrev: '',
	imageBtnNext: ''
   }); // Select all links with lightbox class
 
    // tooltips
    $(".tooltip").attr("title", function() {
                if ($(this).attr("title")) return $(this).attr("title");
                return $(this).find(".tooltip_content").html();
            }).tooltip({
            cssClass: "tooltip-receptariusz",
            delay : 300,
            duration : 2000,
            xOffset : 15,
            yOffset : 15,
            opacity : 15
        });
    
    $(".tooltip_rejestracja").attr("title", function() {
                if ($(this).attr("title")) return $(this).attr("title");
                return $(this).find(".tooltip_content").html();
            }).tooltip({
            cssClass: "tooltip-rejestracja",
            delay : 200,
            duration : 2000,
            xOffset : 15,
            yOffset : 15,
            opacity : 15
        });
   
    $("#skopiuj_adres").click(function() {
        if ($("#reg_adrkoresp_nazwa").val())
            $("#adrdofak_nazwa").val($("#reg_adrkoresp_nazwa").val());
        else
            $("#adrdofak_nazwa").val($("#reg_imie").val() + ' ' + $("#reg_nazwisko").val());
        $("#adrdofak_ulicanumer").val($("#reg_adrkoresp_ulicanumer").val());
        $("#adrdofak_kod").val($("#reg_adrkoresp_kod").val());
        $("#adrdofak_miejscowosc").val($("#reg_adrkoresp_miejscowosc").val());
        return false;
    });
    
    $(".video_trigger").click(function() {
	$(this).find("img").css("display", "none");
	$(this).parent().next("object").css("display", "block");
	return false;
    });
});
