var addthis_config = {
    username: 'xa-4c6d0d2e5b3faa59',
    ui_language: 'hu'
}

$(function() {
    $('#tagcloud').append(tagcloudHtml);

    $('#song_limit').change(function() {
        $(this).closest('form').submit();
    });

    $('.song-add #tag_list_string').autocomplete('/tag/autocomplete', {
        multiple: true,
        multipleSeparator: ', ',
        selectFirst: false
    });

    $('.song-suggest #tag_list_string').autocomplete('/tag/autocomplete/suggest/1', {
        multiple: true,
        multipleSeparator: ', ',
        selectFirst: false
    });

    $('.manage-tag #title').autocomplete('/tag/autocomplete/suggest/1', {
        selectFirst: false
    });

    $('.manage-taggroup #tag_list').autocomplete('/tag/autocomplete', {
        multiple: true,
        multipleSeparator: ', ',
        selectFirst: false
    });

    $('#query').focus();
    $('.song-search #query').focus();
    $('.song-form #title').focus();

    $('.song-form #delete').click(function() {
        return confirm('Biztos, hogy törlöd a dalt?');
    });

    $('.song-form #video_code').change(function() {
        var regex = /http:\/\/www\.youtube\.com\/v\/(.{11})/;
        var match = regex.exec($(this).val());
        var videoLinkInput = $('.song-form #video_link');
        if (match != null && (videoLinkInput.val() == '' || videoLinkInput.val() == 'http://')) {
            videoLinkInput.val('http://www.youtube.com/watch?v=' + match[1]);
            return;
        }

        regex = /http:\/\/www\.youtube\.com\/embed\/(.{11})/;
        match = regex.exec($(this).val());
        videoLinkInput = $('.song-form #video_link');
        if (match != null && (videoLinkInput.val() == '' || videoLinkInput.val() == 'http://')) {
            videoLinkInput.val('http://www.youtube.com/watch?v=' + match[1]);
            return;
        }
    });

    $('.stat .detail').click(function() {
        $(this).closest('.event').find('.detail-more').show();
        return false;
    });

    addthis.init();
});

