jQuery(document).ready(function ($md) {

    // MANEWRY
    $md('.aoverm, .toverm, #spacer').hide();
    $md('.aoverm, .toverm, .fsubmenu, .activelang, #galeria div').addClass('ui-corner-all');

    $md('.fmbut, .fsubk, ').button();
    $md('#map-show-outline, #map-show-full, #map-show-legend').addClass('ui-corner-all');

    //$md('#map-zoom-in').replaceWith('<a id="map-zoom-in" class="map-zoom"></a>');

    $md('#calculator-result, .pagination, .slides_container').addClass('ui-state-hover ui-corner-all');


    $md("#tabs").tabs();

    $md('.drag').draggable();


    // DIALOG DO KAMERY

    var w = $md(document).width();
    var h = $md(document).height();

    $md('.camdialog').dialog({
        autoOpen: false,
        width: w * .9,
        height: 600,
        modal: true,
        resizable: false,
        draggable: false,
        open: function(event, ui) {
            $md('.camdialog').load('camera/camera.html');
        }
    });
    $md('.dopen').click(function() {
        $md('.camdialog').dialog('open');

    });


    // SUBMENU AUTOSTRADA
    $md('.aover').hover(function() {
        $md('.toverm').hide('fade', 300);
        $md('.aoverm').show('fade', 300);
    }, function() {

    });

    $md('.aoverm, .toverm').mouseleave(function() {
        $md(this).hide('fade', 300);
    });


    // SUBMENU OPŁATY
    $md('.tover').hover(function() {
        $md('.aoverm').hide('fade', 300);
        $md('.toverm').show('fade', 300);
    }, function() {

    });

    $md('.tmbut, #tcontwrapper').hover(function() {
        $md('.aoverm, .toverm').hide('fade', 300);
    });

    $md('.toverm, .aoverm').click(function() {
        $md(this).hide('fade', 300);
    });

    $md('#mbody').click(function() {
        $md('.aoverm, .toverm, .fsubmenu').hide('fade', 300);
    });

    // SLIDESHOW TOP

    $md('#slideshow img').addClass('ui-corner-bl');

    $md('#slideshow').cycle({
        fx: 'fade',
        speed:    3000,
        timeout:  10000,
        pause: 1,
        next: '#slideshow'
    });


    // SLIDESHOW FOOTER

    //$md('#fslideshow img').addClass('ui-corner-bl');

    $md('#fslideshow').cycle({
        fx: 'fade',
        speed:    3000,
        timeout: 30000,
        pause: 1,
        next: '#fslideshow'
    });

    $md('#picturecontainer').cycle({
        fx:      'shuffle',
        pause: 1,
        timeout: 500,
        easing:  'easeOutBack',
        next: '.next, #picturecontainer',
        prev: '.prev'
    });


    // SLIDESHOW GALLERY


    // weather slideshow
    $md('#weathercontainer').cycle({
        fx: 'scrollLeft',
        speed:    1500,
        timeout:  10000,
        pause: 1,
        next: '#weathercontainer'
    });

    $md('#weathercontainer').hover(function() {
        $md(this).stop(true, true);
        $md('#newstop').stop(true, true);
        $md('#newstop').hide('fade', 800);
        $md('#weathercontainer').animate({
            height: '+=140px'
        })
    }, function() {
        $md(this).stop(true, true);
        $md('#newstop').stop(true, true);
        $md('#newstop').show('fade', 800);
        $md('#weathercontainer').animate({
            height: '-=140px'
        })
    });
    $md('#weathercontainer div div').first().addClass('wheight');


    // EOF SLIDESHOW


    // weather
    $md('#weathercontainer').addClass('ui-corner-all');


    // SCROLL

    $md('#cscroll').button().click(function() {
        //$md('#spacer').show();
        $md('html,body').animate({scrollTop: $('#fslideshow').offset().top - 20}, 2000);
    });


    $md('#wlepka').click(function() {
            $md('#onewslet').animate({
                width: '+=100%',
                height: '+=100%',
                opacity: '+=20%',
                right: 30
            });

        },
        function() {
            $md('#onewslet').animate({
                height: 'toggle',
                width: 'toggle'
            });
        });


    // ICONS APPEND (na koncu elementu)
    $md('').append('<span class="ui-icon ui-icon-gear moico" style="float:right;"></span>');
    $md('').append('<span class="ui-icon ui-icon-circle-triangle-s" style="float:right;"></span>');
    $md('').append('<span class="ui-icon ui-icon-gear" style="float:left;margin-top: 5px;"></span>');

    // ICONS PREPEND (na poczatku elementu)
    $md('.fsubmenu a, #tollmenu a, #menuul1 a').prepend('<span class="ui-icon ui-icon-triangle-1-e" style="float:left;position:relative;top:-1px;left:1px;"></span>');
    $md('').prepend('<span class="ui-icon ui-icon-arrowreturnthick-1-e" style="float:left;position:relative;top:2px;left:-5px;"></span>');
    $md('').prepend('<span class="ui-icon ui-icon-power" style="float:left;padding-top:0;margin-top: -2px;"></span>');


    // ---------------------------------------------------------------------------------------------------------------- FUNCTIONS
    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


    $md('.mocollapse, .mocollover').next().hide(); // chowa nastepny elelement na starcie
    $md('.collapsar, .collapser, .showme').show(); // clasa dod dodania jezeli nie chcemy zeby cos bylo od razu schowane

// COLLAPSER
    // .mocollapse - clasa do przyciskow, nie uzywac do czegos innego!!! Klikniecie pododuje ze child div robi collapse.
    // child div domyslnie zamkniety, zeby nie byl zamkniety, dodac class="collapser" - bedzie otwarty na load.

    // funkcja do mocollapse - click


    $md('.mocollapse').click(function() {
        $md(this).next().toggle({
            opacity: '+=1',
            height: 'toggle',
            width: 'toggle'

        })
    }, function() {
        $md(this).next().toggle({
            opacity: '-=1',
            height: 'toggle',
            width: 'toglle'

        })
    });


    // ---------------------------------------------------

// FOOTER MEWNU

    $md('.fsubmenu').hide();

    $md('.fm1, .fm2, .fm3, .fm4').hover(function() {
        $md('.fsubmenu:visible').hide('fade', 300);
        $md(this).next().show('fade', 300);
    }, function() {
        //$md(this).next().hide('fade', 300);
    });


    $md('.fsubmenu, #fmenuul').mouseleave(function() {
        $md('.fsubmenu').hide('fade', 300);
    });

    $md('.fmbut, #map-container').hover(function() {
        $md('.fsubmenu').hide('fade', 300);
    });


// EOF FOOTER MEWNU


    //$md('p.fprev').load('http://www.facebook.com/sokolowskibartosz div#pagelet_left_column');
    $md('.mocollover').hover(function () {
        $md(this).next().show('fade', 300);

    });

    // dialog info o trasie

    var dH = $md(document).height() * .2;
    var dW = $md(document).width() * .2;
    $md('.dialog').dialog({
        autoOpen: true,
        width: dW,
        height: dH,
        modal: true,
        draggable: false,
        resizable: false,
        closeOnEscape: true,
        closeText: 'zamknij',
        buttons: {
            Ok: function() {
                $md(this).dialog('close');
            }
        },
        close: function() {
        }
    });

});



