$(document).ready(function()
{
  // po nacitani webu skontrolujeme hash ci netreba naloadovat nejaky obsah
  // ak hash obsahuje bodku je to referencia (kazda musi ibsahovat bodku a ziadny clanok nesmie obsahovat bodku)
  if (document.location.hash != "" && document.location.hash.indexOf(".") > -1)
  {         
    $('.ref_item').css('opacity','0.0');
    
    // nacitame id sekcie z mr_url
    $.ajax({
    type: "POST",
    url: 'ajax_get_id_ref_item.php?shortname='+document.location.hash.substring(1),
    success: function(id_ref) {      
      load_ref(id_ref); 
    }
    }); 
  }
}
);

function change_ref(id_ref)
{
  // najprv nacitame mr_url zobrazovanej sekcie
  $.ajax({
  type: "POST",
  url: 'ajax_get_ref_shortname.php?id_ref_item='+id_ref,
  success: function(shortname) { 
  
  $.ajax({
  type: "GET",
  url: 'ajax_change_ref.php?ref='+id_ref,
  success: function(msg) {
    
    $('.ref_item').css('opacity','1.0').animate({'opacity':'0.0'}, 400, function() {
      
      $('#ref_detail_wrapper').html(msg);
      $('.ref_item').css('opacity','0.0').animate({'opacity':'1.0'}, 400);

      document.location.hash = shortname;
    
    });
  }
  }); 
  
  }
  });     
}

function load_ref(id_ref)
{
  // najprv nacitame mr_url zobrazovanej sekcie
  $.ajax({
  type: "POST",
  url: 'ajax_get_ref_shortname.php?id_ref_item='+id_ref,
  success: function(shortname) { 
  
  $.ajax({
  type: "GET",
  url: 'ajax_change_ref.php?ref='+id_ref,
  success: function(msg) {
    
    $('#ref_detail_wrapper').html(msg);
    $('.ref_item').css('opacity','0.0').animate({'opacity':'1.0'}, 400);

    document.location.hash = shortname;
  }
  }); 
  
  }
  });     
}

// animuje hover na prev aj next aby sme ukazali navstevnikovi ze sa na ne da klikat 
function animate_prev_and_next_hover()
{
  $('.ref_prev_hover').stop().css({'opacity':'0.0', 'display':'block'}).animate({'opacity':'1.0'}, 400, function() { 
    $('.ref_prev_hover').stop().css({'opacity':'1.0', 'display':'block'}).animate({'opacity':'0.0'}, 400, function() { 
      $('.ref_next_hover').stop().css({'opacity':'0.0', 'display':'block'}).animate({'opacity':'1.0'}, 400, function() { 
        $('.ref_next_hover').stop().css({'opacity':'1.0', 'display':'block'}).animate({'opacity':'0.0'}, 400);
      });
    });
  });
}

// next
function ref_next_hover_on() 
{
  $('.ref_next_hover').stop().css({'opacity':'0.0', 'display':'block'}).animate({'opacity':'1.0'}, 400);
} 
function ref_next_hover_off() 
{
  $('.ref_next_hover').stop().css({'opacity':'1.0', 'display':'block'}).animate({'opacity':'0.0'}, 400);
}

// prev
function ref_prev_hover_on() 
{
  $('.ref_prev_hover').stop().css({'opacity':'0.0', 'display':'block'}).animate({'opacity':'1.0'}, 400);
} 
function ref_prev_hover_off() 
{
  $('.ref_prev_hover').stop().css({'opacity':'1.0', 'display':'block'}).animate({'opacity':'0.0'}, 400);
}

// detail
function show_ref_detail()
{    
  // niekde je problem ked rychlo prebehne kurzor cez detail tak sa nevykona hide_ref_detail
  // takze je to osetrene tym ze sa animacia zobrazenia nevykona ak je zobrazene detail_info
  // lebo by to blikalo inak zbytocne po nadideni kurozorom nad detail
  if ($('.ref_detail_info').css('display') == 'none')
  {     
    $('#ref_detail_td').css('background','transparent url(images/ref_pad_hover.png) no-repeat center').find('img').stop().css('opacity','1.0').animate({'opacity':'0.15'}, 400, function() {
      $('.ref_detail_info').stop().css({'opacity':'0.0', 'display':'block'}).animate({'opacity':'1.0'}, 400);   
    });   
  } 
} 
function hide_ref_detail()
{   
  $('.ref_detail_info').stop().css('opacity','1.0').animate({'opacity':'0.0'}, 400, function() {
    $('#ref_detail_td').css('background','transparent url(images/ref_pad.png) no-repeat center').find('img').stop().css('opacity','0.15').animate({'opacity':'1.0'}, 400);
    $('.ref_detail_info').css('display','none');
  });       
}
