$(document).ready(function(){
  $("#featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true); 
  $("#tabs1").tabs({ selected: 0, fxFade: true, fxSpeed: 'fast' });
  $("#tabs2").tabs({ selected: 2, fxFade: true, fxSpeed: 'fast' });
  $("#tabs3").tabs({ selected: 2, fxFade: true, fxSpeed: 'fast' });
  $("#online-guests").html($('#online-cache a').html());
  
  InitFormMask($('#logowanie .text'));
  InitFormMask($('#search_s'));
  InitComment($('#comment-publish-wrapper .submit'));
  
  $('.kalendarz a').each(function(){
    var o = $(this); var s = o.attr('rel').replace('~', '<br />'); o.simpletip({ fixed: false, content: s });
  });
});

function InitFormMask(oNodes)
{
  // init default values
  for(i = 0, j = oNodes.length; i < j; i++)
    InitFormMaskBlur(oNodes[i]);
  
  // onblur and focus actions
  oNodes.blur(function() { InitFormMaskBlur(this); }).focus(function()
  { if(this.value == this.title) this.value = ''; });
  
  // init empty fields (defaults) before form posting
  oNodes.parents('form:first').submit(function() {
    for(i = 0, j = oNodes.length; i < j; i++) {
      var o = $(oNodes[i]); if(o.val() == o.attr('title')) o.val('');
    } return true;
  });
}

function InitFormMaskBlur(oObj)
{
  if(oObj.value == '') oObj.value = oObj.title;
}

function InitComment(oObj)
{
  oObj.click(function() {
    var oThis = $(this);
    var oForm = oObj.parents('form:first');
    
    oThis.attr('disabled', 'disabled');
    
    $.post(oForm.attr('action'), oForm.serialize(), function(sResponse){
      var aResponse = sResponse.split('%');
      
      if(aResponse[0] == 1)
        window.location.reload();
      else
      {
        alert(aResponse[1]);
        oThis.attr('disabled', '');
      }
    });
    
    return false;
  });
}



