$(document).ready(function() {
    $('#flBubles').flash({
      swf: $_coffitoUrl2+'/images/theme/fl_bubles.swf',
      height: 250,
      width: '100%',
      wmode: 'transparent',
      quality: 'hight',
      menu: false,
      scale: 'noscale'
    });
    //$('#flBubles').has('object').children('a').hide();

/*----------------------------------------------------------------------------*/
/* Menu HOVER                                                                 */
    setTimeout(function () {
        var $el, leftPos, newWidth,
        $mainNav2 = $('#coffitoHeader .coffitoMenuH ul');

        if ($($mainNav2).length > 0) {
            $mainNav2.append('<li class="hover"></li>');

            var $magicLineTwo = $($mainNav2).children('.hover');
            var $mainNav2A = $($mainNav2).children('.selected');
            if ($mainNav2A.length > 0) {
                $magicLineTwo
                    .width($($mainNav2A).width())
                    .height($mainNav2.find('a').height())
                    .css('left', ($($mainNav2A).position().left))
                    .data('origLeft', $($mainNav2A).position().left)
                    .data('origWidth', $($mainNav2A).width());
            } else {
                $magicLineTwo
                    .width(0)
                    .height($mainNav2.height())
                    .css('left', $($mainNav2).children('li').position().left)
                    .data('origLeft', $($mainNav2).children('li').position().left)
                    .data('origWidth', 0);
            }
            $('#coffitoHeader .coffitoMenuH ul li').hover(function() {
                var $el = $(this);
                $magicLineTwo.stop().animate({
                    left: $el.position().left,
                    width: $el.width()
                }, 400)
            }, function() {
                $magicLineTwo.stop().animate({
                    left: $magicLineTwo.data('origLeft'),
                    width: $magicLineTwo.data('origWidth')
                }, 400);
            });
        }
    }, 1000);

/*----------------------------------------------------------------------------*/
/* Contact HOVER                                                            */
    $('#fl_contact.hoverer').removeClass('hoverer');
    $('#fl_contact').hover(
        function() {
            $(this).stop(true,true).animate({right:'0px'}, 300, 'swing');
        },
        function() {
            $(this).animate({right:'-'+($(this).width())+'px'}, 300, 'swing');
        }
    );

    $('#flMenuBarBg').hover(
        function() {
            $('#flMenuBarBg').data('flIsHover', true);
            $(this).stop().animate({'opacity':'1'}, 250);
            $('#coffitoHeader').stop().animate({'opacity':'1'}, 250);
        },
        function() {
            var currentY = $(document).scrollTop();
            $('#flMenuBarBg').data('flIsHover', false);
            if (currentY > 70) {
                $(this).stop().animate({'opacity':'0.70'}, 250);
                $('#coffitoHeader').stop().animate({'opacity':'0.85'}, 250);
            }
        }
    );

    $('#coffitoHeader').hover(
        function() {
            $('#flMenuBarBg').data('flIsHover', true);
            $(this).stop().animate({'opacity':'1'}, 250);
            $('#flMenuBarBg').stop().animate({'opacity':'1'}, 250);
        },
        function() {
            var currentY = $(document).scrollTop();
            $('#flMenuBarBg').data('flIsHover', false);
            if (currentY > 70) {
                $(this).stop().animate({'opacity':'0.70'}, 250);
                $('#flMenuBarBg').stop().animate({'opacity':'0.85'}, 250);
            }
        }
    );

    $(window).scroll(function(){
        var currentY = $(document).scrollTop();
        if (currentY > 70 && !($('#flMenuBarBg').data('flIsHover'))) {
            $('#flMenuBarBg').stop().animate({'opacity':'0.70'}, 1);
            $('#coffitoHeader').stop().animate({'opacity':'0.85'}, 1);
        } else {
            $('#flMenuBarBg').stop().animate({'opacity':'1'}, 1);
            $('#coffitoHeader').stop().animate({'opacity':'1'}, 1);
        }
    });
});
