function hideAllCondignations()
{
    $(".tabber [id^=idbuild]").hide();
}
function clearSelectedTab()
{
    $("a[id^=idcond]").removeClass("selected");
}

var ind = 0;




$(document).ready(function()
{

    hideAllCondignations();
    $("#callback_status").hide();
    $("#newsletter_status").hide();
    $("#idbuild1cond0").show();
    $("#idbuild2cond-1").show();
    $("#idbuild4cond0").show();
    $("#idbuild6cond0").show();
    $("#idbuild7cond0").show();
    $("#idbuild8cond-1").show();
    $("#idbuild10cond0").show();
    $("#idbuild12cond0").show();

    $(document).ready(function() { 
        $('.sf-menu').superfish({ 
            delay:       1000,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false                            // disable generation of arrow mark-up 
        }); 
    }); 

    $("#home_find #idpt").change(function () {
        ind = $("#home_find #idpt").val();
        $("#home_find #idbuild").empty();
        $("#home_find #results").show();
        $.getJSON("/ajax.home_find2.php", {
            lang: "pl",
            idname: "idpt", 
            value: $(this).val() 
        }, function(json){
            $.each(json, function(i,item) {
                if (ind == i)
                    $("#home_find #idbuild").append("<option selected='selected' value='" + i + "'>" + item + "</option>");
                else
                    $("#home_find #idbuild").append("<option value='" + i + "'>" + item + "</option>");
            });
        });
        $("#home_find #results").hide();
    });

    $("#home_find #idbuild").change(function () {
        ind = $("#home_find #idpt").val();
        $("#home_find #idpt").empty();
        $("#home_find #results").show();
        $.getJSON("/ajax.home_find2.php", {
            lang: "pl",
            idname: "idbuild", 
            value: $(this).val() 
        }, function(json){
            $.each(json, function(i,item) {
                if (ind == i)
                    $("#home_find #idpt").append("<option selected='selected' value='" + i + "'>" + item + "</option>");
                else
                    $("#home_find #idpt").append("<option value='" + i + "'>" + item + "</option>");
            });
        });
        $("#home_find #results").hide();
    });

    $("#idcond0").click(function() {
        clearSelectedTab();
        $(this).addClass("selected");
        hideAllCondignations();
        $("[id$=cond0]").show();
    });
    $("#idcond1").click(function() {
        clearSelectedTab();
        $(this).addClass("selected");
        hideAllCondignations();
        $("[id$=cond1]").show();
    });
    $("#idcond2").click(function() {
        clearSelectedTab();
        $(this).addClass("selected");
        hideAllCondignations();
        $("[id$=cond2]").show();
    });
    $("#idcond3").click(function() {
        clearSelectedTab();
        $(this).addClass("selected");
        hideAllCondignations();
        $("[id$=cond3]").show();
    });
    $("#idcond4").click(function() {
        clearSelectedTab();
        $(this).addClass("selected");
        hideAllCondignations();
        $("[id$=cond4]").show();
    });

    $("form#callback").submit(function() {
        $(this).hide();
        $("#callback_status").html("<img src='/gfx/loading.small.gif' alt='Loading...' />").show();
        $("#callback_status").load("/ajax.submit.php?lang=pl", { name: $("#callback_name").val(), phone: $("#callback_phone").val(), email: $("#callback_email").val(), callback: 1});
        return false;
    });

    $("form#newsletter").submit(function() {
        $(this).hide();
        $("#newsletter_status").html("<img src='/gfx/loading.small.gif' alt='Loading...' />").show();
        $("#newsletter_status").load("/ajax.submit.php?lang=pl", { name: $("#newsletter_name").val(), email: $("#newsletter_email").val(), newsletter: 1});
        return false;
    });
    

    $('#nyro-message').hide();
    
    if ($('#nyro-message').html() != null && $('#nyro-message').html() != '')
    {
        $.nyroModalManual({
            width: 360, // default Width If null, will be calculate automatically
            height: 140, // default Height If null, will be calculate automatically
            bgColor: '#000000',
            title: 'Informacja', // Modal title
            content: $('#nyro-message').html()
        });
    }
    
    $("[readonly]").css("color","#999999");

    $("ul#menu li").hide();

    $("#top-break-1").animate({height: "66px"}, 1800, function() { $("ul#menu li").fadeIn();});
    $("#top-break-2").animate({height: "15px"}, 1800);

    /*****************************  pictures in background *****************************/
    var picts = {
    "pic_duration": 14,
    "list": ["/img.php?file=images/panorama2.jpg&type=background","/img.php?file=images/dsc_1064.jpg&type=background","/img.php?file=images/dsc_1059.jpg&type=background","/img.php?file=images/28.jpg&type=background","/img.php?file=images/photos/krolewskie_domy_ii_lipiec_2009_06.jpg&type=background","/img.php?file=images/photos/lofty_i.jpg&type=background","/img.php?file=images/photos/spichlerz_andrzej_marczuk_11.jpg&type=background","/img.php?file=images/photos/spichlerz_andrzej_marczuk_17.jpg&type=background","/img.php?file=images/prezentacja-domy2.jpg&type=background"] };

    for(i = 0; i < picts.list.length; i++) {
        var img = new Image();
        img.src = picts.list[i];
    }
    
    $("#image-bk").css("background-image", "none");

    $.timer(20, function(timer) {
        var image = picts.list[Math.round(new Date().getTime()/(1000.0 * picts.pic_duration + 1) ) % picts.list.length];
        if($.browser.msie && $.browser.version=="6.0") {
            $("#image-bk").css( {
                            backgroundPosition: "50% -80px",
                            backgroundImage: "url('"+ image +"')"
                });
        } else {
            $("#image-bk")
                .fadeOut(1000, function() {
                    $(this)
                        .css( {
                            backgroundPosition: "50% 0",
                            backgroundImage: "url('"+ image +"')"
                            } )
                        .fadeIn(1000, function() {
                            $(this).fadeIn(1000, function() {
                                $(this).animate({
                                        backgroundPosition:"(50% -160px)"
                                    }, {
                                        duration: 6000
                                });
                            });
                        });
                });
        }
        timer.reset(picts.pic_duration * 1000);
    });
    $('a.flash').click(function(e) {
        e.preventDefault();
        $.nyroModalManual({
            type: 'swf',
            width: '720',
            height: '480',
            url: $(this).attr("href")
        });
        return false;
    });
    $('a.iframed').click(function(e) {
        e.preventDefault();
        $.nyroModalManual({
            type: 'iframe',
            forceType: 'iframe',
            width: '720',
            height: '480',
            url: $(this).attr("href")
        });
        return false;
    });

    $('#colours').click(function(e) {
        e.preventDefault();
        $("#contents-wrapper").toggleClass('bordeaux');
    });

});
