// JavaScript Document

$(document).ready(function() {
    if(jQuery.browser.msie) {
        $('#subMenu li').hover(
            function() {
                $(this).addClass('hover');
            },
            function() {
                $(this).removeClass('hover');
            }
        );
    }
    $('a[class*=external]').attr('target', '_blank');
	$('li[class*=external] a').attr('target', '_blank');
    
    lastActive = null;
    
    if ($('#slider').length > 0) {
        $('#slider > li').each(function() {
            var _l = 0;
            $(this).prevAll().each(function() {
                _l += $(this).outerWidth(true);
            });
            $(this).css('left', _l);
        });
        $('#slider > li').css('position', 'absolute');
        
        $('#slider li a').hover(
            function(e) {
                $('#bigbox').children('div').hide();
                $('#bigbox #' + $(this).attr('rel')).show();
            },
            function() {}
        );
        
        $('#slider > li').hover(
            function() {
                if (lastActive == this)
                    return;
                if(lastActive != null)
                    $(lastActive).bb_zoomOut();
                
                $(this).bb_zoomIn();
                lastActive = this;
            },
            function() {}
        );
        lastActive = $('#slider > li.active');
        $('#slider > li.active').mouseover();
        $('#bigbox').hover(
            function() {},
            function() {
                if ($(lastActive).hasClass('active'))
                    return;
                $(lastActive).bb_zoomOut();
                
                $('#bigbox').children('div').hide();
                $('#bigbox #' + $('#slider > li.active').find('a').eq(0).attr('rel')).show();
                
                $('#slider > li.active').mouseover();
                lastActive = $('#slider > li.active');
            }
        );
    }
    
});


(function($) {
    
    $.fn.bb_zoomIn = function() {
        return $(this).each(function() {
            var box = $(this).find('.smallbox');
            var logo = $(this).find('.logo');
            var list = $(this).find('ul');
            

            logo.attr('src', logo.attr('src').replace('small', 'big'));
            logo.width(123);
            logo.height(104);
            
            if(list.length > 0)
                lTop = 10;
            else
                lTop = 25;
            
            box.attr('src', box.attr('src').replace('bigbox', 'zoom'));
            box.width(133);
            box.height(131);
            box.css({
                //'left': - 45,
                'position' : 'absolute',
				'margin-top' : '11px'
            });
            box.parents('li').css('z-index', 5);
            box.parents('li').siblings('li').css('z-index', 1);
            box.stop().animate({
               'width' : 237,
               'height' :  183,
               'left' : -50,
               'top' : -26
            }, 100);
            logo.stop().animate({
                'width' : 163,
                'height' : 138,
                'left' : -13,
                'top' : -15
            }, 100, 'linear',
                function() {
                    if(list.length > 0)
                        list.show();
                }
            );
        });
    }
    
    $.fn.bb_zoomOut = function() {
        var boxo = $(this).find('.smallbox');
        var logoo = $(this).find('.logo');
        var listo = $(this).find('ul');
        if(listo.length > 0)
            listo.hide();
        
        logoo.stop().animate({
            'width' : 123,
            'height' : 104,
            'left' : 5,
            'top' : 1
        }, 100);
        
        boxo.stop().animate({
           'width' : 133,
           'height' :  131,
           'left' : 0,
           'top' : -11
        }, 100, 'linear',
            function() {
                boxo.css({
                    'left': 0,
                    'position' : 'absolute'
                });
                boxo.width(133);
                boxo.height(131);
                boxo.attr('src', boxo.attr('src').replace('zoom', 'bigbox'));
                logoo.attr('src', logoo.attr('src').replace('big', 'small'));
                
            }
        );
    }
        
})(jQuery);

