$(function(){
        
        // main page accordion
        var _nodeHolder = $('.categories-area');
        var _nodeItem = _nodeHolder.find('.category-box');
        var _slideDuration = 1000;
        
        // click node
        _nodeItem.click(function(){
                _nodeItem.each(function(){
                        $(this).removeClass('active');
                });
                $(this).addClass('active');
                _nodeItem.each(function(){
                        if($(this).hasClass('active')) {
                                $(this).removeClass('not-active');
                                $(this).animate({
                                        'width':'855px'
                                },_slideDuration,function(){
                                        $(this).find('.heading').fadeOut();
                                        $(this).find('a img').fadeOut();
                                });
                        }else{
                                $(this).addClass('not-active');
                                $(this).animate({
                                        'width':'25px'
                                },_slideDuration,function(){
                                        $(this).find('.heading').fadeIn();
                                        $(this).find('a img').fadeIn();
                                });
                        }
                });
        });
        $('h1 a').click(function(){
                _nodeItem.each(function(){
                        $(this).removeClass('not-active');
                        $(this).removeClass('active').animate({
                                'width':'196px'
                        });
                        $(this).find('.heading').fadeIn();
                        $(this).find('a img').fadeIn();
                });
        });
        
        
        // nutricosmetics accordion
        var _nodeA = $('.accordion li');
        var _openerA = _nodeA.find('.head a.opener');
        var _slideA = _nodeA.find('.slide');
        
        _openerA.click(function(){
                var _heightA = $(this).parents(_nodeA).find('.text').height()+15;
                if (_heightA<$(this).parents(_nodeA).find('.images').height()+18) _heightA = $(this).parents(_nodeA).find('.images').height()+15
                        
                if (!$(this).parents(_nodeA).hasClass('active')) {
                        _hideA();
                        $(this).parents('li').find('.slide').animate({
                                'height':_heightA,
                                'marginTop':'-20px'
                        });
                        $(this).parents('li').addClass('active');
                }
                return false;
        });
        function _hideA() {
                _nodeA.filter('.active').each(function(){
                        $(this).find('.slide').animate({
                                'height':0,
                                'marginTop':0
                        });
                        $(this).removeClass('active');
                });
        }
});
