// main js script for gawelorg

$.fa.extend({
    preview: function(field, plugin, options) {
        field.css('height', '10em');
        var url = '/ajax/preview';
        var last = new Date().getTime()
        var updatePreview = function() {
            var current = new Date().getTime();
            if (current > last + 500) {
                last = current;
                $.post(url, {comment:field.val()}, function(data) {
                    if (!plugin.hasClass('bordered-table')) {
                        plugin.addClass('bordered-table');
                        plugin.css('margin-top', '0.5em');
                        plugin.css('padding-left', '0.5em');
                        plugin.css('width', '530px');
                    }
                    plugin.html(data.html);
                }, "json");
            }
        }
        field.keyup(updatePreview);
        field.blur(function() { last=0; updatePreview();});
        if (field.val())
            field.blur();
    }
});


$(document).ready(function() {
    $('.pagination span').wrap('<a href="#"></a>');
    $('.pagination a').each(function() {
        var self = $(this);
        if (/pager_curpage/.exec(self.html())) {
            self.wrap('<li class="active"></li>');
        } else {
            self.wrap('<li></li>');
        }
    });
    $('.pagination > li').wrapAll('<ul></ul>');

    $('.footer').css('position', 'fixed');
    $('.footer').css('width', '100%');
    $('.footer').css('top', $(window).height()-40+'px');
    $(window).resize(function() {
        $('.footer').css('top', $(window).height()-40+'px');
    });


    $('.post img').each(function() {
        var self = $(this);
        var href=self.attr('src').replace('/thumbs/blog/', '/thumbs/large/');
        self.wrap('<a class="slimbox" href="'+href+'"></a>');
    });
    $('a.slimbox').slimbox();

});

