div_to_load = 'content';
after_load  = '';

function ContentLoad(link, div_name, after_func, div_small)
 {
  div_to_load = div_name || 'content';
  after_load  = after_func || '';
  div_small   = div_small || 0;

  $("#"+div_to_load).css("-moz-opacity", 0.5);
  $("#"+div_to_load).css("opacity", 0.5);
  $("#"+div_to_load).css("filter", "alpha(opacity=50)");

  var main_div = $("#"+div_to_load);
  var height   = $("#"+div_to_load).height();
  var width    = $("#"+div_to_load).width();
  var ofset    = $("#"+div_to_load).offset();
  if (div_small)
   {
    var top  = ofset.top-height*17;
    var left = ofset.left-width/1.1;
   }
  else
   {
    var top  = ofset.top-height/(3*2);
    var left = ofset.left-width/3;
   }


  $("<div id='content_loading'></div>")
  .html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;завантаження...")
  .css("position","absolute")
  .css("height",  height / 2)
  .css("width",   width*2 / 3)
  .css("top",     top)
  .css("left",    left)
  .prependTo(main_div);

  $.get(link, {ajax: 1},onAjaxSuccess);
 }

function onAjaxSuccess(data)
 {
  $("#content_loading").remove();
  $("#"+div_to_load).css("-moz-opacity", 1);
  $("#"+div_to_load).css("opacity", 1);
  $("#"+div_to_load).css("filter", "alpha(opacity=100)");
  $("#"+div_to_load).attr("innerHTML", data);

  if (after_load != '') eval(after_load);
 }

function VoteGo(link)
 {
  var queryString = $('#inter').formSerialize();
  ContentLoad(link+'/?'+queryString, 'content');
  return false;
 }


cur_foto_id = 0;
function FotoVoteGo(link, id)
 {
  ContentLoad(link+'/'+id+'/', "to_vote_"+id, 'FotoVoteSuccess()', 1);
  cur_foto_id = id;
 }

function FotoVoteSuccess()
 {
  if ($("#to_vote_"+cur_foto_id).html()) return;
  $("#to_vote_"+cur_foto_id).html(c_vote_accepted);
  var votes = $("#votes_"+cur_foto_id).html();
  $("#votes_"+cur_foto_id).html(votes*1+1);

  $("div").each(
    function()
     {
      var reg = new RegExp("^to_vote_(\\d+)$", "i");
      var match = reg.exec(this.id);
      if (match !==null && match.length && match[1] && match[1] != cur_foto_id)
       {
        $(this).hide();
       }
     }
  );

  $("div[@id=^'to_vote_']").hide();
 }

function SubsrcibeGo(link)
 {
  var queryString = $('#send').formSerialize();

  ContentLoad(link+'/?'+queryString, 'subscribe');
  return false;
 }

function FormContactSendGo()
 {
  var res = jQuery.validate({messageheader: c_data_wrong});
  if (!res) return;

  document.emailForm.to_send.value=1;
  $('#contact_form').submit();
 }
