$(document).ready(function()
{


  /*** COLORBOX ***/
  $('a.modal_form').colorbox({
    innerWidth: '764px',
    innerHeight: '618px',
    close: 'zatvoriť okno',
    iframe: true,
    scrolling: false,
    overlayClose: false
  });
  
  $('a.colorbox').colorbox({
    overlayClose: true,
    close: 'zatvoriť',
  });


  /*** STATUS ***/
  $('div.status_success,div.status_warning,div.status_failed').each(function() { $(this).fadeIn(1500).delay(15000).fadeOut(1500); });

  /*** SCROLLABLE ***/
  $('#scrollable').scrollable({
    clickable: false,
    speed: 2000,
    keyboard: true,
    circular: false
  }).autoscroll({ autoplay: true, interval: 9000 }).navigator();

  var scrollable = $('#scrollable').data('scrollable');
  var size =1;

  if(scrollable) scrollable.onBeforeSeek(function(event, index) { if(this.getIndex()>=(this.getSize()-size) && index>this.getIndex()) { this.seekTo(0); return false; }});

 $('#scrollable2').scrollable({
    clickable: false,
    speed: 2000,
    keyboard: true,
    circular: false
  }).autoscroll({ autoplay: true, interval: 9000 }).navigator();



  $('#sidebar').each(function()
  {
    var sidebar = $(this);
    var content = $('#content');

    var padding = 37;
    var sidebar_h = sidebar.height();
    var content_h = content.height() + padding;

    if(content_h>sidebar_h) sidebar.css({ height: content_h });
    else content.css({ height: sidebar_h - padding });
  });

  $('div.tabs a').click(function()
  {
    var me = $(this);
    var box = $('#' + this.rel);

    $('#tabbox .content:visible').not(box).fadeOut('fast');
    box.fadeIn('fast');

    $('div.tabs li').removeClass('active');
    me.parent().addClass('active');

    if(this.rel=='') return true;
    else return false;
  });

  $('#subscriptions a.item').not('.active').hover(function() { $(this).find('.reflected').fadeTo('fast', 1.0); }, function() { $(this).find('.reflected').fadeTo('fast', 0.3); });

  $('form.validation').submit(function()
  {
    var ret = true;

    $(this).find(':input').each(function()
    {
      $(this).removeClass('invalid');

      if(this.value=='' && this.className.indexOf('required')!=-1)
      {
        if(ret)
        {
          alert('Prosím zadajte hodnotu v poli "'+this.title+'"');
          this.focus();
          ret = false;
        }

        $(this).addClass('invalid');
      }

      if(this.className.indexOf('email')!='-1' && this.value!='')
      {
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        if(reg.test(this.value)==false)
        {
          if(ret)
          {
            alert('Prosí­m zadajte platnú e-mailovú adresu.');
            this.focus();
            ret = false;
          }

          $(this).addClass('invalid');
        }
      }
    });

    return ret;
  });  
});

