jQuery(function() {

    $(window).load(function() {
        $('#body').css('visibility', 'visible');
    });
    
    // Position middle
    $('#body').css('marginTop', ($(window).height() - 501)/2 - 39 + 'px');


    //Png fix
    $.ifixpng(base_url + 'assets/ifixpng/pixel.gif');
    $('.logo img').ifixpng();

    // Content background opacity
    //$('#page.inner .content-bg').css('opacity', 0.5);

    // Cufon text
    Cufon.replace('.nav a, .slogan, .page_title');

    $('.nav a[href=lenktyniu-komanda] > span:eq(1)').remove();

    $('.nav a[href=paslaugos]').css({paddingLeft: '4px', paddingRight: '6px'});

    $('.nav a[href=serviso-komanda]').each(function() {
        $(this).find('.cufon:eq(0)').css({position : 'relative', left : '5px'});
    });

    $('.nav a[href=kur-mus-rasti]').each(function() {
        $(this).find('.cufon:eq(0)').css({position : 'relative', left : '5px'});
    });

    if ($('#page').hasClass('naujienos')) {
        var num = (500 - $('#page .content').height())/10;
        if (is_admin === true) {
            num += 20;
        }
        for (var i=1; i<=Math.ceil(num); i++) {
            $('#page .content').append('<br>');
        }
    }

    $('#page.naujienos .content, #page.inner .content .right_col').jScrollPane({
        showArrows : true,
        wheelSpeed : 22,
        scrollbarWidth : 13
    });

    if ($.browser.msie) {
        $(window).load(function() {
            setTimeout(function() {
                if ($('#page.naujienos .content').size()) {
                    $('#page.naujienos .content')[0].scrollTo(0);
                }
                if ($('#page.inner .content .right_col').size()) {
                    $('#page.inner .content .right_col')[0].scrollTo(0);
                }
            }, 100);
        });
    }

    // Admin stuff

    // Add news item
    $('.add_news').click(function() {
        $.get(base_url + 'naujienos/create', {}, function(response) {
                if (response.indexOf('success') == -1) {
                    alert('Oops. Serveris padarė klaidą, bandykite pakartoti operaciją.');
                } else {
                    var id = response.replace(/success/, '');
                    $('.news_block').prepend($('.news_model').html());
                    $('.news_block .id:first').html(id);
                    news_editable();
                }
            });
    });

    // Delete news item
    $('.del_news').live('click', function() {
        var $news_item = $(this).parent().parent();
        if (confirm('Ar tiktrai norite ištrinti šią naujieną?')) {
            var id = $(this).closest('.news_item').find('.id').html();
            $.get(base_url + 'naujienos/delete/' + id, {}, function(response) {
                if (response != 'success') {
                    alert('Oops. Serveris padarė klaidą, bandykite pakartoti operaciją.');
                } else {
                    $news_item.remove();
                }
            });
        }
    });

    
});

