
$(document).ready(function() {

    //rezerwacja i pytanie oszczegoly

    $('.szukaj_zaaw').click(function(){
        var tmp = $(this).attr('rel');

        if(tmp == 'standard'){
            $('#search_standard').show();
            $('#search_advenced').hide();
        }

        if(tmp == 'advenced'){
            $('#search_standard').hide();
            $('#search_advenced').show();
        }
        return false;
    });

    $(function() {
        $('#hotel_gallery a').lightBox();
       
    });


    $(".trip_id_radio").change(function(){
        
        $('#trip_desc_container').load('/hotel/ajaxshow?t_id='+$(this).val());
        $('html, body').animate({scrollTop:'220px'}, 'slow');
    });


    


    $('#trip_question').click(function(){
        var trip_id = $(".trip_id_radio:checked").val();
        
        document.location.href='/zapytaj-o-szczegoly,'+trip_id+'.html';
        return false;
    });

    $('#trip_order').click(function(){
        var trip_id = $(".trip_id_radio:checked").val();
        document.location.href='/zarezerwuj-wycieczke,'+trip_id+'.html';
        return false;
    });

    $('.more_person').click(function(){
        var obj = $(this).attr('rel');
        $('#'+obj).show();
        var nb_persons = parseInt($('#order_nb_persons').val());
        $('#order_nb_persons').val(nb_persons+1);
        calculate_price();
        $(this).hide();
        return false;
    });

    $('.less_person').click(function(){
        var obj = $(this).attr('rel');
        $('#'+obj).hide();
        var nb_persons = parseInt($('#order_nb_persons').val());
        $('#order_nb_persons').val(nb_persons-1);
        calculate_price();
        $('.hide .more_person').show();
        if($('#order_nb_persons').val() == 1){
            $('.more_person').show();
        }
        return false;
    });

    function calculate_price(){
        var type = $('#order_pricetype').val();
        var nb_persons = parseInt($('#order_nb_persons').val());
        var price = parseInt($('#order_price').val());
        $('#nb_person').html(nb_persons);
        
        if(type == 'ROOM'){
            $('#total_price').html(price);
        }else if(type == 'PERSON'){
            $('#total_price').html(price*nb_persons);
        }else{
            $('#total_price').html(price*nb_persons);
        }
    }

    // Closing Divs - used on Notification Boxes
    $('#country_box').change(function(){
        var country_id = $(this).val();

        if(country_id == 0){
            $('#region_box').attr('disabled', true);
        }else{

            $('#region_box').load('search/regions?country_id='+country_id);

            $('#region_box').removeAttr('disabled');
        }
    });
    $('#country_box2').change(function(){
        var country_id = $(this).val();

        if(country_id == 0){
            $('#region_box2').attr('disabled', true);
        }else{

            $('#region_box2').load('search/regions?country_id='+country_id);

            $('#region_box2').removeAttr('disabled');
        }
    });
    $(".datepicker").datepicker({
        showOn: 'button',
        buttonImage: 'img/kalendarz.gif',
        buttonImageOnly: true,
        changeMonth: true,
	changeYear: true

    });
    $(function(){
        $(".date_picker").datepicker({
            showOn: 'button',
            buttonImage: 'img/kalendarz.gif',
            buttonImageOnly: true
        });
    });

    $('#gal_min_photo').cycle({
        fx:     'fade',
        speed:  1000,
        timeout: 5000,
        next:   '#gal_next',
        prev:   '#gal_prev',
        after:   onAfter
    });
    function onAfter(curr,next,opts) {
        $('#gal_nb').html(opts.currSlide + 1);

    }

    /*
     * Promocje
     */
    $('#promo_cont').cycle({
        fx:      'scrollUp',
        speedIn:  500,
        speedOut: 500,
        delay:   -2000 
    });
                                         
   
    


    $('#newsletter_form').submit(function(){

        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        if(reg.test($('#newsletter_email').val()) == false){
            window.alert('Podany adres email jest niepoprawny');
            return false;
        }else{
            return true;
        }


    });

    
  
    //popularne kierunki

    $('.map_area').mouseover(function(){
        var obj_id = $(this).attr('href');
        var obj_img = 'img/' + $(this).attr('alt') + '.png';
        cont_show(obj_id, obj_img);
    });
    $('.map_area').mouseout(function(){
        cont_show();
    });
    $('.map_area').click(function(){
        var obj_id = $(this).attr('href');
        var obj_img = 'img/' + $(this).attr('alt') + '.png';
        cont_show(obj_id, obj_img, '1');
        return false;
    });

    selected_id = 'north-america';
    selected_img = null;
    function cont_show(id, img, back) {
        if(id == null) {
            id = selected_id;
            img = selected_img;
        }
        if(back=='1') {
            selected_id = id;
            selected_img = img;
        }

        var map = $('#cont_map');
        if(img == null) {
            map.attr('src', 'img/mapa-swiata.png');
        } else {
            map.attr('src', img);            
        }
        $('.cont_urls').hide();
        $(id).show();
    }
    cont_show('#cont_europe', 'img/europe.png', '1');
            



// Closing jQuery
});

