/******************************************************************************
* jquery.ctg.hoverHighlight.js 
*
* @description fades out non-hovered items in a set
*
* @param {Object} [settings] Settings for opacity and container
* @return {Object} a jquery object
******************************************************************************/
(function($) {
		
	$.fn.hoverHighlight = function(settings) {

        //Defaults
		settings = jQuery.extend({
			opacity: 0.4,
			container: $(this).parent()
		}, settings);
		
        var level = settings.opacity;
        var box = settings.container;
        
        var items = $(this);
        
        //For each item
        items.each(function(){ 
            //Add hover handler
            $(this).hover(
                //Mouse in
            	function(){
            	    $(this).addClass("lihover"); 
                    items.each(function() {
                           $(this).queue("fx", []); //Stop animations
                    });
            	    $(this).fadeTo(300,1.0);
            	    items.not('.lihover').fadeTo(300,level);
            	},
            	//Mouse out
            	function(){
            	    $(this).removeClass("lihover"); 
            	}
        	)
        });
        	
        box.mouseout(
            //Check for mouse position outside container to light up all items
            function(e){
                var left = $(this).position().left;
                var top = $(this).position().top;
                var right = left + $(this).width();
                var bottom = top + $(this).height();
                
                if((e.pageX <= left || e.pageX >= right) || (e.pageY <= top || e.pageY >= bottom)) {
                    items.each(function() {
                           $(this).queue("fx", []); //Stop animations
                    });
            	    items.fadeTo(300,1.0);
            	}
            }
        );
        return this;
    
	};//Close function
})(jQuery);
