$(document).ready(function(){

    //Slider
    $("#scrollable").scrollable({ circular: true }).autoscroll(4000);

    $('#scrollable .item').each(function(index) {
        if ($(this).find('img').attr('title')) var titleToUrl= $(this).find('img').attr('title');
        
        if (titleToUrl != undefined) {
            $(this).find('figure').wrap('<a href="'+titleToUrl+'"/>');
        }

        if ($(this).find('img').attr('alt')) var showAlt = $(this).find('img').attr('alt');

        if (showAlt != undefined) {
            $(this).find('figure').append('<figcaption>'+showAlt+'</figcaption>');
        }
    });

    //Contact form

    $("#edit-submit").replaceWith('<button type="submit" id="edit-submit" name="op" class="isubmit"><div class="form-submit">Submit</div></button>')

    var values = []; // array for default values
    $('.form-text').each(function() {
      values[ $(this).attr('name') ] = $(this).val(); // pushing values
    });

    $('.form-text').focus(function() {
       if ( $(this).val() == values[ $(this).attr('name') ])  $(this).val("");
    });

    $('.form-text').blur(function() {
      if ( ! $(this).val() ) $(this).val( values[ $(this).attr('name') ] );
    });

    
    $('.form-textarea').each(function() {
      values[ $(this).attr('name') ] = $(this).val(); // pushing values
    });

    $('.form-textarea').focus(function() {
       if ( $(this).val() == values[ $(this).attr('name') ])  $(this).val("");
    });

    $('.form-textarea').blur(function() {
      if ( ! $(this).val() ) $(this).val( values[ $(this).attr('name') ] );
    });

    //Info
    $(".info-page_blocks .info-page_block_i:nth-child(2n)").addClass("right");

    //Faq
    $(".faq_question").click(function(){
        $(this).next(".faq_answer").slideToggle("slow")
        .siblings(".faq_answer:visible").slideUp("slow");
        $(this).siblings(".faq_answer");
     });

    //Contacts map
    $('.contacts_map_gmap:first').show();

    $('.contacts_map_a').click(function(){
       var MapTopOpen = $(this).attr('id') + '-loc';

       $('#'+MapTopOpen).show().siblings(".contacts_map_gmap:visible").hide();
    });


});

