$(document).ready(function()
{
  /*** REFLECTION ***/
  $('img.reflect').reflect({
    height: 40,
    opacity: 0.18
  });

  /*** SLIDESHOW ***/
  $('#slideshow img').each(function()
  {
    var me = $(this);
    me.parent().css({ 'background-image': 'url('+ me.attr('src') +')' });
    me.remove();
  });

  $('#slideshow').cycle({
    pager: '#pager',
    speed: 1000,
    timeout: 5000
  });

  $('#home_showroom').hover(function() { $(this).find('.tooltip').fadeIn('fast'); }, function() { $(this).find('.tooltip').fadeOut('fast'); });

  /*** SCROLLABLE ***/
  $('#scrollable').scrollable({
    clickable: false,
    speed: 500,
    keyboard: false
  });

  /*** COLORBOX ***/
  $('a.modal_img').colorbox({
    innerWidth: '940px',
    innerHeight: '375px',
    opacity: 0.85,
    close: 'zatvoriť okno',
    iframe: true,
    scrolling: false,
    overlayClose: false
  });
 
  $('a.modal_form').colorbox({
    innerWidth: '764px',
    innerHeight: '615px',
    opacity: 0.85,
    close: 'zatvoriť okno',
    iframe: true,
    scrolling: false,
    overlayClose: false
  });
  
  $('a.modal_form_long').colorbox({
    innerWidth: '764px',
    innerHeight: '715px',
    opacity: 0.85,
    close: 'zatvoriť okno',
    iframe: true,
    scrolling: false,
    overlayClose: false
  });

  $('a.modal_map').colorbox({
    innerWidth: '994px',
    innerHeight: '615px',
    opacity: 0.85,
    close: 'zatvoriť okno',
    iframe: true,
    scrolling: false,
    overlayClose: false
  });

  $('a.modal_contact').colorbox({
    innerWidth: '820px',
    innerHeight: '468px',
    opacity: 0.85,
    close: 'zatvoriť okno',
    iframe: true,
    scrolling: false,
    overlayClose: false
  });

  var scrollable = $('#scrollable').data('scrollable');
  var size = 6;

  if(scrollable)
  {
    scrollable.onBeforeSeek(function(event, index) { if(this.getIndex()>=(this.getSize()-size) && index>this.getIndex()) { return false; }});
    scrollable.seekTo($('#scrollable a.active').index()-2, 1);
  }

  $('#scrollable strong').hover(function() { $(this).parent().find('.reflected').fadeTo('fast', 1.0); }, function() { $(this).parent().find('.reflected').fadeTo('fast', 0.85); });

  /*** STATUS ***/
  $('div.status_success,div.status_warning,div.status_failed').each(function() { $(this).fadeIn(1500).delay(15000).fadeOut(1500); });

  $('form.validation').submit(function()
  {
    var ret = true;

    $(this).find(':input').each(function()
    {
      if(ret)
      {
        if(this.value=='' && this.className.indexOf('required')!=-1)
        {
          alert('Prosím zadajte hodnotu v poli "'+this.title+'"');
          this.focus();
          ret = false;
        }

        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)
          {
            alert('Prosím zadajte platnú e-mailovú adresu.');
            this.focus();
            ret = false;
          }
        }
      }
    });

    return ret;
  });
});

