/*******************************************************************************
	TITLE: 			Cat Chow Bag Tabs
	
	AUTHOR:			Dan Edwards
	
	VERSION:		1.0
	
	REQUIRES:		jQuery v1.3.2
	
	EXPECTS:		dl.content-tabs in markup
	
	OPTIONS:		none
					
	CALLBACKS: 		none
					
	DESCRIPTION:	-
	
*******************************************************************************/

(function($) {
    $.fn.extend({
        catChowBagTabs: function(options) {
        
            // DEFAULTS
            var defaults = {
                listContainer: "dl.content-tabs",
                listTitles: "dl.content-tabs dt",
                listDefinitions: "dl.content-tabs dd",
                hoverListDefinition: "dl.content-tabs dt.hover + dd",
                defaultInfo: ".selector-default"
            };
            var options = $.extend(defaults, options);
            
            return this.each(function() {

                // VARIABLES
                var hoverSuffix = "-hover",
                    elClass,
                    currentDef = $("dl dd:visible"),
                    currentTitle = currentDef.prev("dt");

                // FUNCTIONS
                showDd = function(el) {
                    $(el).parent().addClass('hover').addClass("content-tabs-hover");
                    
                    currentClass(el);
                    $(el).addClass('hover').addClass(elClass + hoverSuffix);
                    $(el, options.hoverListDefinition).addClass('hover');
                    
                    $(options.listDefinitions).hide();
                    $(options.defaultInfo).hide();
                    $(el).next("dd").show();
                };

                hideDd = function(el) {
                    $(el).parent().removeClass('hover').removeClass("content-tabs-hover");
                    
                    var removeClass = elClass + hoverSuffix;
                    $(el).removeClass('hover').removeClass(removeClass);
                    $(el, options.listDefinitions).removeClass('hover');
                    
                    $(options.listDefinitions).hide();
                    $(options.defaultInfo).show();
                    $(currentDef).show();
                };
                
                currentClass = function(el) {
                    elClass = $(el).attr("class").split(" ");
                    elClass = elClass[0];
                    return;
                };

                // EVENT LISTENERS
                $(options.listTitles).mouseover(function(event) {
                    showDd(this);
                }),
                $(options.listTitles).mouseout(function(event) {
                    hideDd(this);
                });
                
                $(options.listDefinitions).mouseover(function(event){
                    $(this).hide();
                });
                
                // TRIGGERED ON PLUGIN LOAD
                
            });
        }
    });
})(jQuery);