Limb.Class('ajaxLoader',
{
  __construct: function(container)
  {
    if (container)
      this.container = jQuery(container);
    else
      this.container = jQuery('body');
    this.build();
  },
  build: function()
  {
    this.container.append("<div class='ajax_loader' style='display:none;'>Загрузка ...</div>");
    this.ajaxLoader = jQuery('.ajax_loader');
  },
  show: function ()
  {
    this.ajaxLoader.show();
  },
  hide: function ()
  {
    this.ajaxLoader.hide();
  }
});

/*Инициализирует подсветку меню*/
function HightlightMemu(path)
{
  var url = window.location.toString();
  var max = 0;
  var link = null;

  jQuery(path).each(function()
  {
    //finding the longest href
    if(url.indexOf(this.href) >= 0 && this.href.length > max)
    {
      link = this;
      max = this.href.length;
    }
  });

  if(link)
    jQuery(link).attr('class', 'selected');

}


function initMainMenu(){
  //left navigation current item highlight
  HightlightMemu("#menu > ul > li > a");

};

function messageBlock (msg,controller)
{
  if(controller)
  {
    var controller = jQuery(controller);
    var offsetPosition = controller.offset();
    var position = "left:"+offsetPosition.left+"px;top:"+(offsetPosition.top+controller.height()+5)+"px;";
    jQuery('#wrapper').append("<div class='message_block' style='"+position+"'>" + msg + "<a href='javascript:void(0)' class='close_icon' onclick='jQuery(this.parentNode).remove();return false;' title='Закрыть'><img src='images/1x1.gif' alt='Закрыть'/></a></div>");
  } 
  else
  {
    var position = "left:50%;top:50%;";
    jQuery('#wrapper').append("<div class='message_block' style='"+position+"'>" + msg + "<a href='javascript:void(0)' class='close_icon' onclick='jQuery(this.parentNode).remove(); return false;' title='Закрыть'><img src='images/1x1.gif' alt='Закрыть'/></a></div>");
  }
};

function confirmBlock (param1, param2,param3)
{
  var html = "<div class='confirm_block'>";

  if (typeof(param1) == "string")
  {
    var link = "#";
    var msg = param1;
  }
  else
  {
    var link = param1.href;
    var msg = param2;
  }

  html += "<span class='msg'>" + msg + "</span>";
  html += "<a id='ok_button' href='"+ link +"' class='button'>OK</a><br />";
  html += "<a href='#' id='cancel_button' class='button'>Отмена</a>";
  html += "</div>"

  if(jQuery("#wrapper").is('div'))
    var elem = jQuery(html).appendTo("#wrapper");
  else
    var elem = jQuery(html).appendTo("body");

  var timeout = setTimeout(function(){deleteNode(elem)},20000);

  if (typeof(param3) == "function")
  {
    elem.find('.button').eq(0).click(param3);
  }
  
  elem.find('.button').eq(0).click(function(){jQuery(this.parentNode).remove();clearTimeout(timeout);});
  elem.find('.button').eq(1).click(function(){jQuery(this.parentNode).remove();clearTimeout(timeout);return false;});

  if(typeof(param1) == "string")
    return elem;
  else
    return false;
}

jQuery(document).ready(function()
{
  ajaxLoader = new ajaxLoader('#wrapper');
  /*Main Menu*/
  initMainMenu();


});
