$(document).ready(
  function()
  { 
    if ($('.tabs').length) $(".tabs").tabs({ fx: { opacity: 'toggle' } });
    
    if ($('.resizable').length) $('.resizable').resizable();
    if ($('.draggable').length) $('.draggable').draggable();
    
    if ($('.dialog').length) $(".dialog").dialog({ modal: true, buttons: { "OK": function() { $(this).dialog("close"); } } });
    
    if ($('a.lightBox').length)
    {
      $('a.lightBox').lightBox({
        imageLoading: '/img/lightbox/' + lang + '/loading.gif',
        imageBtnClose: '/img/lightbox/' + lang + '/close.gif',
        imageBtnPrev: '/img/lightbox/' + lang + '/prev.gif',
        imageBtnNext: '/img/lightbox/' + lang + '/next.gif'
      });
    }
    
    $('#searchForm input.query').click(function() { $(this).select(); });
    
    /*
    $('#searchResult p.close span').click(function() { $('#searchResult').hide("slow"); });
    
    $('#searchForm input.query').keyup(function() 
    { 
      if ($(this).val().length < 3) 
      {
        $('#searchResult').hide("slow");
        return false;
      }
      $(this).attr('disabled', 'disabled');
      $('#searchResult').html('<img class="progress" src="/img/loader.gif" alt="" />');
      $('#searchResult').show("slow");
      $.ajax(
      {
        type:     "GET",
        cache:    false,
        url:      '/ajax.html?action=search&lang=' + lang + '&q=' + $(this).val(),
        dataType: "html",
        success:  function(result) { $('#searchResult').html(result); $('#searchForm input.query').removeAttr('disabled'); $('#searchForm input.query').focus(); },
        error:    function() { $('#searchForm input.query').removeAttr('disabled'); $('#searchForm input.query').focus(); }
      });
      return false;
    });
    */
  }
);

function ajaxGet(url, elem, target, replace)
{
  if ($(elem).length == 0 || $(target).length == 0) return false;
   
  $.ajax(
  {
    type:     "GET",
    cache:    false,
    url:      url + $(elem).val(),
    dataType: "html",
    success:  function(result)
    {
      if (replace) $(target).replaceWith(result);
      else         $(target).html(result);
    }
  });
}

function hide(elem)
{
  if ($(elem).length) $(elem).hide('slow');
}

function show(elem)
{
  if ($(elem).length) $(elem).show('slow');
}

function toggle(elem)
{
  if ($(elem).length) $(elem).toggle('slow');
}
