function pageselectCallback(page_index, jq){
    var cat = $("#idCat").html();
    var max_elem = Math.min((page_index+1) * items_per_page, $('#news div.result').length);
	
    if (max_elem)
    {
		var newcontent = '';
        for(var i=page_index*items_per_page;i<max_elem;i++)
        {
            newcontent += $('#news div.result:eq('+i+')').html();
			
        }
        $('#Searchresult').empty().append(newcontent);
    }
    else
    {
        $.ajax({
          url: "stiri.ajax.php?op=by_cat&cat="+cat,
          cache: false,
          success: function(html){
            $("#news").html(html);
          }
          ,
        complete: function(){
            max_elem = Math.min((page_index+1) * items_per_page, $('#news div.result').length);
            var newcontent = '';
            for(var i=page_index*items_per_page;i<max_elem;i++)
            {
                newcontent += $('#news div.result:eq('+i+')').html();
            }
            $('#Searchresult').empty().append(newcontent);
        }
        });
    }
    return false;
}
function initPagination() {
    $("#poza_pagini").show();
    var num_entries = $('#news div.result').length;
	
    if (num_entries>0)
    {
        // Create pagination element
        $("#Pagination").pagination(num_entries, {
            items_per_page:items_per_page,
            num_display_entries:num_display_entries,
            num_edge_entries: num_edge_entries,
            callback: pageselectCallback
        });
		
    }
    else
    {
        $("#Pagination").empty();
        haveChildCategories($("#idCat").html());
    }
}
function showChildCategories(id)
{
    $("#child_categories").empty();
    $.ajax({
      url: "categorii.ajax.php?op=get_childs&id="+id,
      cache: false,
      success: function(html){
        $("#child_categories").html(html);
      }
    });
}
function haveChildCategories(id)
{
    $.ajax({
      url: "categorii.ajax.php?op=get_childs&id="+id,
      cache: false,
      success: function(html){
        if (html.length)
            $('#Searchresult').html('');
        else
            $('#Searchresult').html('<div align="center">Aceasta categorie nu are momentan informatii.</div>');
      }
    });
}

function readMore(id,one)
{

var singleNews = 0;
if(one)
    singleNews = 1;
$("#poza_pagini").hide();
$(".ad-thumb-list").empty();
$("#news_details").empty();
$("#news").empty();
var nr = parseInt($("#nr_vizualizari_"+id).html())+1;
$("#nr_vizualizari_"+id).html(nr);
$("#Searchresult").slideUp(600);
$("#Searchresult").hide();
$("#Pagination").hide();
$("#child_categories").hide();
var ajax_load = "<center><img src='images/ajax-loader.gif' alt='loading...' /></center>";
var loadUrl = 'stiri.ajax.php';
var data = {
                op:'read_more',
                id:id,
                one:singleNews
};
var callbackFunction = function(){
    var galleries = $('.ad-gallery').adGallery({
          loader_image: 'loader.gif',
          width: 500, // Width of the image, set to false and it will read the CSS width
          height: 375, // Height of the image, set to false and it will read the CSS height
          thumb_opacity: 0.7, // Opacity that the thumbs fades to/from, (1 removes fade effect)
                                                  // Note that this effect combined with other effects might be resource intensive
                                                  // and make animations lag
          start_at_index: 0, // Which image should be displayed at first? 0 is the first image
          animate_first_image: false, // Should first image just be displayed, or animated in?
          animation_speed: 400, // Which ever effect is used to switch images, how long should it take?
          display_next_and_prev: true, // Can you navigate by clicking on the left/right on the image?
          display_back_and_forward: true, // Are you allowed to scroll the thumb list?
          scroll_jump: 0, // If 0, it jumps the width of the container
          slideshow: {
                enable: false,
                autostart: false
          },
          effect: 'fade', // or 'slide-vert', 'resize', 'fade', 'none' or false
          enable_keyboard_move: true, // Move to next/previous image with keyboard arrows?
          cycle: true, // If set to false, you can't go from the last image to the first, and vice versa
          // All callbacks has the AdGallery objects as 'this' reference
          callbacks: {
                // Executes right after the internal init, can be used to choose which images
                // you want to preload
                init: function() {
                  // preloadAll uses recursion to preload each image right after one another
                  this.preloadAll();
                },
                // This gets fired right after the new_image is fully visible
                afterImageVisible: function() {
                        var image = this.images[this.current_index];
                },
                // This gets fired right before old_image is about to go away, and new_image
                // is about to come in
                beforeImageVisible: function(new_image, old_image) {
                  // Do something wild!
                }
          }
        });
         $('.ad-nav').width(($('.ad-gallery').width()));
         window.location = '#top';
};
$("#news_details").html(ajax_load).load(loadUrl,data,callbackFunction);
}

function showAllNews()
{
    $("#images").hide();
    $("#news_details").empty();
    $("#Searchresult").slideDown(600);
    $("#Pagination").show();
    $("#child_categories").show();
    $("#poza_pagini").show();
    window.location = '#';
}




