$(function() {
    menu();
    $('#logos').simpleSpy(5, 5000)
    $('#reallist li').captionImg();
    $('.lightbox').fancybox();
})

function menu() {
    $('#header ul ul').hide();
    $('#tab-offer').hover(function() {
        $(this).css('background','#ff2525').find('ul').stop(false,true).slideDown('500');
    }, function() {
        $(this).css('background','').find('ul').stop(false,true).slideUp('500');
    })
}

(function ($) {    
    $.fn.simpleSpy = function (limit, interval) {
      // set some defaults
        limit = limit || 4;
        interval = interval || 4000;
        
        return this.each(function () {
            // capture a cache of all the list items
            var $list = $(this),
              items = [], // uninitialised
              currentItem = limit,
              total = 0, // initialise later on
              width = $list.find('> li:first').width();
                  
            // capture the cache
            $list.find('> li').each(function () {
              items.push('<li>' + $(this).html() + '</li>');
            });
            total = items.length; 
            $list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();
                  
            function spy() {
                var $insert = $(items[currentItem]).css({
                    width : 0,
                    opacity : 0,
                    display : 'none'
                }).prependTo($list);

                $list.find('> li:last').animate({ opacity : 0}, 1000, function () {
                $insert.animate({ width : width }, 1000).animate({ opacity : 1 }, 1000);
                
                $(this).animate({ width : 0 }, 1000, function () {
                        $(this).remove();
                    });
                });
                currentItem++;
                if (currentItem >= total) {
                    currentItem = 0;
                }
                setTimeout(spy, interval);
            }
            spy();
        });
    };    
})(jQuery);

/**
 * jQuery plugin for sliding image captions
 *
 * @author: Dariusz Pobożniak (http://pobozniak.pl)
 * @date: 04.03.2010
 * @usage: 
 * 
 */
 
(function($) {
    $.fn.captionImg = function(customOptions) {
        var defaultOptions = {
            attribute: 'alt'
        }
        var options = $.extend({}, defaultOptions, customOptions);
        
        return this.each(function() {
            var $this = $(this);
            var $txt = $this.find('img').attr(options.attribute);
            var $caption = $('<div class="caption">' + $txt + '</div>').hide();
            $caption.appendTo($this);
            var width = $this.width() - parseInt($caption.css('paddingLeft')) - parseInt($caption.css('paddingRight'));
            $caption.css('width', width);
            
            $(this).hover(function() {
                $(this).find('.caption').stop(false,true).slideDown();
            }, function() {
                $(this).find('.caption').stop(false,true).slideUp();
            })
        })
    }
})(jQuery);
