

$(document).ready(function(){
		
    // http://nivo.dev7studios.com/
/*     $('#nivo-slider').nivoSlider({
        effect:'random',
        slices:15,
        animSpeed:500,
        pauseTime:3000,
        directionNav:true, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:true, //1,2,3...
        beforeChange: function(){},
        afterChange: function(){}
    });
 */
    // Menu stile
    $('#menu-top').menu();

    // Liste fancybox
    $(".fancybox-list").fancyboxList();
				
    // Liste fancybox
    $("a.fancybox").fancybox();

    // Link fancybox
    $("a.fancybox-iframe").fancybox({
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500,
        'speedIn': 600,
        'speedOut': 200,
        'autoScale': false,
        'type': 'iframe',
        'width': 640,
        'height': $(window).height()*0.85
    });

});




// -- Plugin menu stili ----------------------------------------------------- //

(function($){
    $.fn.menu = function() {

        return this.each(function() {

            $(this).find('li').each(function(){

                var $container = $(this);
                var $trigger = $container.children('a');
                var $menu = $container.children('ul');

                if($menu.length == 0)
                    return true

                $menu.css('display', 'none');

                $menu.mouseover(function(){
                    $container.data('hover', true);
                }).mouseout(function(){
                    $container.data('hover', false);
                });

                $trigger.click(function(event){
                    event.preventDefault();
                    event.stopPropagation();

                    // Chiusura menu
                    if($container.data('open')){
                        $menu.css('display', 'none');
                        $(document).unbind('click.menu');
                        $container.data('open', false);

                    // Apertura menu
                    }else{
                        $menu.fadeIn(200);
                        $container.data('open', true);
                        $(document).bind('click.menu', function(){
                            if(!$container.data('hover')){
                                $menu.css('display', 'none');
                                $(document).unbind('click.menu');
                                $container.data('open', false);
                            }
                        });
                    }
                });
            });
        });
    };
})(jQuery);




// -- Plugin Liste Fancybox ------------------------------------------------- //

(function($){
    $.fn.fancyboxList = function(config) {
        var counter = 0;
        return this.each(function() {
            counter++;
            $(this).find('a').each(function(){
                $(this).attr('rel', 'fancybox-list-'+counter);
                $(this).fancybox(config);
            });
        });
    };
})(jQuery);

