// Po refaktoryzacji.
$('.item[data-url] .item-name').click(function (e) {
    var link = $(this).closest('.item[data-url]').data('url');
    location.href = link;
});

// Szczegóły pliku.
$('.item[data-info] .my-item-thumbnail, .item[data-info] .item-name').click(function (e) {
    if ($('#gallery-main').hasClass('without-info')) {
        $('#gallery-main').removeClass('without-info');
        $('#gallery-info').removeClass('hide');
    }

    var data = $(this).closest('.item[data-info]').data();
    var image = $('#media-info-image');
        image.empty();
    $('#media-info-icon').empty().append($('<i class="'+data.icon+'"></i>'));
    $('#media_url').val(data.link);
    $('#media-info-name').text(data.filename);
    $('#media-info-url').val(data.link);
    $('#media-info-size span').text(data.size);
    $('#media-info-type span').text(data.extension);
    var dimensions = $('#media-info-dimensions');

    if (data.dimensionWidth != '' && data.dimensionHeight != '') {
        dimensions.show();
        dimensions.find('span').text(data.dimensionWidth+' x '+data.dimensionHeight+' px')
    } else {
        dimensions.hide();
    }

    if (data.isImage) {
        image.append($('<img src="'+data.link+'?thumb=200x200">'));
    } else {
        image.append($('<i class="'+data.icon+'"></i>'));
    }
});

// Kopiowanie URL
$('#copy-to-clipboard').bind('click', function () {
    $('#media-info-url').select();
    document.execCommand('copy');
    $('.infoCopyUrl').css({'opacity': 1, 'z-index': 1}).animate({'opacity': 0, 'z-index': -1}, 3000);
});

// Widok listy.
$('.media-view').click(function (e) {
    if ($(this).data('view') == 'grid') {
        localStorage.setItem('wicms3_media_list_view', 0);
    } else {
        localStorage.setItem('wicms3_media_list_view', 1);
    }

    changeView();
});

function changeView() {
    var $items = $('.gallery-wrapper .items');

    if (parseInt(localStorage.getItem('wicms3_media_list_view'))) {
        $items.addClass('list')
    } else {
        $items.removeClass('list')
        localStorage.setItem('wicms3_media_list_view', 0);
    }
}

changeView();
// Widok listy - koniec
