$(function () {
    var $items = $('#cc_menu .cc_item');
    var cnt_items = $items.length;
    var folded = false;
    var menu_time;
    $items.unbind('mouseenter').bind('mouseenter', m_enter).unbind('mouseleave').bind('mouseleave', m_leave).find('.cc_submenu > ul > li').bind('click', function () {
        var $li_e = $(this);
        if (folded) {
            hideContent();
            showContent($li_e.attr('class'))
        } else fold($li_e);
      
    });
    
     $('span.link').click(function(){
         var $items = $('#cc_menu .cc_item');
    var $li_e = $items.find('.cc_submenu > ul > li.cc_content_4_1');
  //unfold();
   //fold($li_e);
            hideContent();
           showContent('cc_content_4_1');
       
    });
    
    
    

    

    function m_enter() {
        var $this = $(this);
        clearTimeout(menu_time);
        menu_time = setTimeout(function () {
            $this.find('img').stop().animate({
                'top': '0px'
            }, 400);
            $this.find('.cc_title').stop().animate({
                'top': '449px'
            }, 400).css('background', '#3c824e');
            $this.find('.cc_submenu > ul').stop().animate({
                'height': '81px'
            }, 400)
        }, 200)
    }
    function m_leave() {
        var $this = $(this);
        clearTimeout(menu_time);
        $this.find('img').stop().animate({
            'top': '-600px'
        }, 400);
        $this.find('.cc_title').stop().animate({
            'top': '267px'
        }, 400).css('background', 'none');
        $this.find('.cc_submenu > ul').stop().animate({
            'height': '0px'
        }, 400)
    }
    $('#cc_back').click(function(){
		$(location).attr('href','oriflame.php');
	});
    function fold($li_e) {
        var $item = $li_e.closest('.cc_item');
        var d = 100;
        var step = 0;
        $items.unbind('mouseenter mouseleave');
        $items.not($item).each(function () {
            var $item = $(this);
            $item.stop().animate({
                'marginLeft': '-245px'
            }, d += 200, function () {
                ++step;
                if (step == cnt_items - 1) {
                    folded = true;
                    showContent($li_e.attr('class'))
                }
            })
        })
    }
    function unfold() {
        $('#cc_content').stop().animate({
            'left': '-693px'
        }, 600, function () {
            var d = 100;
            var step = 0;
            $items.each(function () {
                var $item = $(this);
                $item.find('img').stop().animate({
                    'top': '-600px'
                }, 200).andSelf().find('.cc_submenu > ul').stop().animate({
                    'height': '0px'
                }, 200).andSelf().find('.cc_title').stop().animate({
                    'top': '267px'
                }, 200).css('background', 'none');
                $item.stop().animate({
                    'marginLeft': '50px'
                }, d += 200, function () {
                    ++step;
                    if (step == cnt_items - 1) {
                        folded = false;
                        $items.unbind('mouseenter').bind('mouseenter', m_enter).unbind('mouseleave').bind('mouseleave', m_leave);
                        hideContent()
                    }
                })
            })
        })
    }
    function showContent(idx) {
        $('#cc_content').stop().animate({
            'left': '261px'
        }, 200, function () {
            $(this).find('.' + idx).fadeIn()
        })
    }
    function hideContent() {
        $('#cc_content').find('div.block').hide()
    }
});
