/**
 * CS-CONNECT s.r.o.
 *
 *
 * @version SVN:$Id: app.js 72 2011-02-06 11:41:59Z mishal $
 * @author Mishal <mishal at mishal dot cz>
 */
Application.behaviors.myApp = function()
{

  $('#menu ul li.menu-level-0').each(function()
  {
    var config = {
         over: function() { $(this).addClass('active').find('div.menu-level-1:first').stop().show('fast'); },
         timeout: 300, // number = milliseconds delay before onMouseOut
         out: function() { $(this).removeClass('active').find('div.menu-level-1:first').stop().fadeOut('fast'); }
    };

    $(this).hoverIntent(config);

    
  });

  // FIXME: make with CSS
  // $('#menu ul li div.menu-level-1').hide();

  $('#content a[href$=.pdf],#sidebar a[href$=.pdf]').addClass('pdf');
 
  $('#content a:has(img)').each(function()
  {
    var link = $(this).attr('href');
    if(!link.match('.(jpg|gif|png|jpeg)$'))
    {
      // skip all non image links
      return;
    }    
    $(this).fancybox();
  });

  $('#sidebar a:has(img)').each(function()
  {
    var that  = $(this);
    var rel = that.attr('rel');
    if(rel)
    {
      rel += ' fancybox';
    }
    else
    {
      rel = 'fancybox';
    }

    var fancyboxOptions = {};

    var link = that.attr('href');
    if(!link.match('.(jpg|gif|png|jpeg)$'))
    {
      // skip all non image links
      return;
      fancyboxOptions.type = 'iframe';
      fancyboxOptions.width  = 640;
      fancyboxOptions.height  = 480;
    }

    that.attr('rel', rel);
    var image = that.find('img');
    var title = that.attr('title') || image.attr('alt');
    that.wrap($('<div class="image-wrapper" />'));
    if(title)
    {
      that.after('<p>' + title + '</p>');
    }
    
    that.fancybox(fancyboxOptions);

  });

};
