/*
 * JS - DELO
 */
(function ($) {
  $(document).ready(function() {
    if($('.jcarousel-skin-image-gallery-top').length > 0) {
      $('.jcarousel-skin-image-gallery-top .jcarousel-item').each(function() {
        var text = $(this).find('img').attr('title');
        
        if (text.length > 0) {
      	  $(this).append('<span class="hover-title">'+text+'</span>');
      	  $(this).find('.hover-title').show();
      	  $(this).find('.hover-title').hide();
        }
      });

      $('.jcarousel-skin-image-gallery-top .jcarousel-item').hover(
        function () {
          $(this).addClass('hover');
          var elem = this;

          setTimeout(function(){
            var queue = $(elem).queue();
            if ($(elem).hasClass('hover') && queue.length == 0) {
              $(elem).find('.hover-title').fadeIn();
            }            
          }, 500);
        },
        function () {
          $(this).removeClass('hover');
          var elem = this;

          setTimeout(function(){
            if(!$(elem).hasClass('hover')) {
              $(elem).find('.hover-title').fadeOut();
            }
          },500);
        }
      );
    }

    if($('.node-article-teaser-col .image-teaser-text').length > 0) {
      $('.node-article-teaser-col').hover(
        function () {
          var queue = $(this).find('.teaser-text').queue();
          if (queue.length == 0) {
            $(this).find('.teaser-text').slideDown(300);
          }
        },
        function () {
          $(this).find('.teaser-text').slideUp(100);
        }
      );
    }
    
    if($('.popup-question').length > 0) {
      
      $(".popup-question").each(function(){
        id = $(this).attr('id');
        link = $('[rel='+id+']');
        $(this).css('left',link.position().left+10);
      });

      $(".popup-question").hover(
        function(){
          $(this).addClass('hover');
        },
        function(){
          var queue = $(this).queue();
          $(this).removeClass('hover');
          $(this).fadeOut();
        }
      );
      
      $('.question-popup-link').hover(
        function () {
          var div = $(this).attr('rel');
          var queue = $('#'+div).queue();
          if (queue.length == 0) {
            $('#'+div).fadeIn();
          }
        },
        function () {
          div = $(this).attr('rel');
          var queue = $('#'+div).queue();

          setTimeout(function(){
            if(!$('#'+div).hasClass('hover')) {
              $('#'+div).fadeOut();
            }
          },100);
        } 
      );      
    }
  });
})(jQuery);
;

