var interval = null;
/*lightbox */
$( function() {
    $('[rel=lightbox], [rel=lightbox[gallery]],.fullNews .img .min').prettyPhoto( {
        theme: 'dark_square'
    } );

} );


/*news */
$(function() {
    $('.newsBox .more').click( function() {
        if($('#home').get().length>0) {
            return true;
        }
        $(this).parent().parent().find('.full').slideDown();
        $(this).slideUp();
        $('.newsBox .back').css('display', 'block');
        return false;
    } );
    $('.newsBox .img a').click(function() {
        $(this).parent().parent().find('.more').click();
        return false;
    });
    $('.newsBox .back').each(function() {
        if($(this).parent().parent().hasClass('fullNews')) {
            return;
        }
        $(this).click( function() {
            $(this).hide();

            $(this).parent().slideUp('normal', function() {
                $(this).parent().find('.more').slideDown();
            });
            return false;
        } )
    } );
});

/*
 * Contact Form
 */
$( function() {
    $('.txtinput, #contactForm .text').each( function() {
        $(this).attr('defaultText', ( $(this).hasClass('mess') ? $(this).text() : $(this).attr('value') )).focus( txtinputFocus ).blur( txtinputBlur );
    } );
    $('#searchBox .text, #newForm .text, #newForm textarea').each(function() {
        if($(this).attr('value') == '') {
            $(this).attr('value', $(this).attr('defaultText'))
        }
    }).focus( txtinputFocus ).blur( txtinputBlur );

} );
function txtinputFocus() {
    if($(this).hasClass('mess')) {
        if($(this).attr('defaultText') == $(this).text())
            $(this).text('');
    } else {
        if($(this).attr('defaultText') == $(this).attr('value'))
            $(this).attr('value','');

    }
}

function txtinputBlur() {
    if($(this).hasClass('mess')) {
        if($(this).attr('value') == '')
            $(this).text($(this).attr('defaultText'));
    } else {
        if($(this).attr('value') == '')
            $(this).attr('value', $(this).attr('defaultText') );

    }
}

$(  function() {
    $('#top img').css( 'opacity', 0 );
    setTimeout( function() {
        $( '#top img' ).animate({
            opacity: 1
        }, 1000);
    }, 600 );


});
$('#searchForm').submit(function() {
    $('input.text').each(function() {
        if($(this).attr('value') == $(this).attr('defaultText')) {
            $(this).attr('value', '');
        }
    });
});

function update()
{
    typ = 0;
    var typ_wlasnosci = document.getElementsByName("PropertyType");



    for (i=0;i<typ_wlasnosci.length;i++){

        if (typ_wlasnosci[i].checked==true)
            typ=typ_wlasnosci[i].value;
    }


    val = document.getElementById("wart_n").value;
    prov_p = document.getElementById("prow").value;
    splitstring = val.split(" ");
    val = "";
    for(i = 0; i < splitstring.length; i++)
        val += splitstring[i];
    if(val != '')
    {
        sum = 1.0*val;
        prov= (sum*prov_p)/100;
        prov_vat=0.23*prov;


        document.getElementById("vat_prow").value = prov_vat.toFixed(2);
        document.getElementById("prow_w").value = prov.toFixed(2);

        tax = 0.02*val;
        sum = sum + tax;
        document.getElementById("tax").value = tax.toFixed(2);
        temp = 0;
        if(val <= 3000)
            temp = 100;
        if(val > 3000 && val <= 10000)
            temp = 100 + 0.03*(val - 3000);
        if(val > 10000 && val <= 30000)
            temp = 315 + 0.02*(val - 10000);
        if(val > 30000 && val <= 60000)
            temp = 710 + 0.01*(val - 30000);
        if(val > 60000 && val <=1000000)
            temp = 1010 + 0.004*(val - 60000);
        if(val > 1000000)
            temp = 4770 + 0.002*(val - 1000000);
        if(typ < 3)
            temp = temp/2.0;
        sum = sum + temp;
        document.getElementById("op_not").value = temp.toFixed(2);
        vat = 0.22*temp;
        if(typ > 1)
            sum = sum + vat + 400;
        else
            sum = sum + vat + 200;

        sum = sum + prov + prov_vat;
        document.getElementById("suma").value = sum.toFixed(2);
        document.getElementById("vat_op_not").value = vat.toFixed(2);
        if(typ > 1)
            document.getElementById("op_sad").value = '200.00';
        else
            document.getElementById("op_sad").value = 'brak';
        document.getElementById("wnioski").value = '200.00';
    }
    else
    {
        document.getElementById("vat_prow").value = '';
        document.getElementById("prow_w").value = '';
        document.getElementById("tax").value = '';
        document.getElementById("op_not").value = '';
        document.getElementById("vat_op_not").value = '';
        document.getElementById("op_sad").value = '';
        document.getElementById("wnioski").value = '';
        document.getElementById("suma").value = '';
    }
}


$(function() {
    $('#newForm select, #searchBox select').each(function() {
        if($(this).attr('id') == 'search_country') {
            $(this).jgdDropdown({
                callback: function(obj, val) {
                    downloadCity(val);
                }
            });
        } else {
            $(this).jgdDropdown();
        }
    });
    $('form').submit(function() {
	$(this).find('input[type=text]').each(function() { if($(this).attr('value') == $(this).attr('defaultText')) $(this).attr('value', '')  });
    });
});
function downloadCity(val) {
    $.ajax({
        url: 'city.php',
        data: {country: val},
        success: downloadCityCallBack,
        dataType: 'text'
    });

}
function downloadCityCallBack(data) {
    $('#jgd_dd_search_city').remove();
    $('#search_city').show().html($(data).html()).jgdDropdown();
}
$(function() {
    $('#menu .linkWrap').hover(function() {
        $(this).addClass('hover');
        if($(this).attr('maxHeight') == null) {
            $(this).attr('maxHeight', $(this).find('ul').height());
            $(this).find('ul').height(0);
        }
        $(this).find('ul').stop().animate({
            height: $(this).attr('maxHeight') + 'px'
        }, 'fast');
    }, function() {
        $(this).removeClass('hover');
        $(this).find('ul').stop().animate({
            height: '0px'
        }, 'fast');
    }).click(function() {
        window.location = $(this).find('.firstLevel').attr('href');
    });
});

