/**
 * BillyReid.com - Side Links JS.
 * 
 * @author Randy Little
 * @created 10/30/2011
 * @updated 1/16/2012
 * @version 2
 * @copyright Billy Reid, Inc.
 */
jQuery(function(){
        /**
         * Opening category's that this product belongs within.
         */
        jQuery("input[name=category-id]").each(function() {
            /**
             * Recursively open category structure.
             */
            showCategory ( jQuery("div[data-category-id="+jQuery(this).val()+"]") );
            
            /**
             * Highlight this category.
             */
            if ( jQuery(this).attr("data-level") == "2" )
            {
                    jQuery(".category-name", "div[data-category-id="+jQuery(this).val()+"]")
                        .eq(0).css({"color":"#FFFFFF","display":"inline-block","margin-bottom":"7px"});
            } else {
                    jQuery(".category-name", "div[data-category-id="+jQuery(this).val()+"]")
                        .eq(0).css("color","#FFFFFF");
            }
                        
                
            /**
             * Open categories one level up within category.
             */
            jQuery("div[data-level="+
                    (parseInt(jQuery("div[data-category-id="+jQuery(this).val()+"]").attr("data-level"))+1)
                    +"]", "div[data-category-id="+jQuery(this).val()+"]").each(function(){
                        jQuery(this).show();
                    });
        });
        
        assessCaptureArea();
        
        /**
         *  Recursive function to open category tree
         */ 
        function showCategory(cat)
        {
            /**
             * Get category parent.
             */
            var _catParent = jQuery(cat).parent("div");
            var _dataLevel = jQuery(cat).attr("data-level");
            
            /**
             *  Recursively show all categories within this level.
             */
            jQuery("div[data-level="+_dataLevel+"]", _catParent).each(function(){
                if ( jQuery(this).attr("data-is-active") == "1" )
                    jQuery(this).show();
            });
            
            if ( parseInt ( jQuery(cat).attr("data-level") ) > 2 )
            {
                showCategory (
                    jQuery(cat).parent("div[data-level="+
                        (parseInt(jQuery(cat).attr("data-level"))-1)+
                        "]")
                );
            }
        }
});
