$(document).ready(function(){
  $("a[rel='lightbox']").lightBox();
  /*
  $("a[href*='s=']").each(function(){
    if ($(this).attr("rel")>0){
      var temp = "javascript:ajaxgetpage(" + $(this).attr("rel") + ");";
      $(this).attr("href",temp);
    }
  });
  $("body").append('<div id="ajaxcache" style="display: none;"></div>')
  $("body").append('<div id="ajaxactual" style="display: none;"></div>')
  */
});

function ajaxgetpage(strona) {

  if ($("#cache" + strona).length==0 && $("#ajaxactual").html()!=strona) {

    $("#tresc").fadeOut(250, function(){
      $(this).html("<center><img style='padding: 50px;' src='images/loading.gif' alt=''/></center>");
    }).fadeIn(250, function(){
      $.ajax({
        url: "ajax_main.php?s=" + strona,
        type: "GET",
       	success: function(html){
       	  $("#tresc").fadeOut(250, function(){
            $("#tresc").html(html);
            ajaxcache(strona);
            $("#ajaxactual").html(strona);
          }).fadeIn(250);
        }
      });
    });

  }else if($("#ajaxactual").html()!=strona) {

    $("#tresc").fadeOut(250, function(){
      $(this).html($("#cache" + strona).html());
    }).fadeIn(250);
    $("#ajaxactual").html(strona);

  }


}

function _delete(e,h) {
  var d = window.confirm('Czy na pewno chcesz ' + h + ' ?');
  if(d) window.location=e;
}

function ajaxcache(liczba) {
  $("#ajaxcache").append('<div id="cache' + liczba + '"></div>');
  $("#cache" + liczba).html($("#tresc").html());
}
