function doMoveArticlePage(id, direction, table)
{
    loader_img = "#row_" + id + " .load img";
    $(loader_img).show();

    $.post("ajax.php", {request:'doMoveItem', id:id, direction:direction, table:table},
    function(data){
        $(loader_img).hide();

        if(data)
        {
            row = '#row_' + id;
            moveRow  = "<tr id='row_" + id + "'>" + $(row).html() + "</tr>";
            $(row).remove();

            if(direction == 'up') $('#row_' + data).before(moveRow);
            else $('#row_' + data).after(moveRow);
        }
    });
}


function doEditArticlePage(id, table)
{
    loader_img = "#row_" + id + " .load img";
    $(loader_img).show();

    $.post("ajax.php", {request:'doEditArticlePage', id:id, table:table, description:$('#area_' + id).val()},
        function(data){
        $(loader_img).hide();
    });
}


function doDeleteArticlePage(id, table)
{
    if (confirm('Are you sure you\'d like to delete this Page?'))
    {
        loader_img = "#row_" + id + " .load img";
        $(loader_img).show();

        $.post("ajax.php", {request:'doDeleteArticlePage', id:id, table:table},
            function(data){
                if(data != 0) $('#row_' + id).remove();
        });
    }
}


function showArticlePage(page_id, current_page)
{
    box = '#info_block';

    loaderHtml = $('#loader').html();
    $(box).html(loaderHtml);

    $.post("ajax.php", {request:"showArticleOtherPage", id:page_id, current_page:current_page},
        function(data){
            $(box).html(data);
    });
}


function showReleasePage(page_id, current_page)
{
    box = '#info_block';

    loaderHtml = $('#loader').html();
    $(box).html(loaderHtml);

    $.post("ajax.php", {request:"showReleaseOtherPage", id:page_id, current_page:current_page},
        function(data){
            $(box).html(data);
    });
}


function artVideoPaginatorInit(obj)
{
    str = '';

    id = $(obj).attr('rel');
    paginator = $(obj).parent().parent().attr('id');
    if(paginator == 'articles_pager')
    {
        currentPage = artCurrentPage;
        pagesCount = artPagesCount;
    } else if(paginator == 'videos_pager')
    {
        currentPage = videoCurrentPage;
        pagesCount = videoPagesCount;
    } else if(paginator == 'releases_pager')
    {
        currentPage = releaseCurrentPage;
        pagesCount = releasePagesCount;
    }

    response = artVideoPaginator(id, paginator, currentPage, pagesCount);
    if(paginator == 'articles_pager') artCurrentPage = response;
    else if(paginator == 'videos_pager') videoCurrentPage = response;
}


function artVideoPaginator(id, paginator, currentPage, pagesCount)
{
    if(id == 'next')
    {
        if(currentPage < pagesCount) currentPage++;
    }
    else if(id == 'prev')
    {
        if(currentPage > 1) currentPage--;
    }
    else currentPage = id;

    if(currentPage <= pagesCount)
    {
        $('#' + paginator + ' a').removeClass('act');
        $("#" + paginator + " a[rel='" + currentPage + "']").addClass('act');
        $('#' + paginator + '_list .list-items1').hide();
        $('#' + paginator + '_box' + currentPage).show();
    }

    return currentPage;
}


function init_prefilled_fields(fields)
{
    $(fields).focus(function(){
        if($(this).val() == $(this).attr('title')) $(this).val('');
    });

    $(fields).blur(function(){
        if($(this).val() == '') $(this).val($(this).attr('title'));
    });
}
