/**
 * @author ted
 */

 $(document).ready(function() {
	(function($) { 
			$.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
		$(this).find('a').css('background-position', '0 100%');
		//Calculate width of all ul's
		
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				//$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			//$(this).find(".sub").css({'width' :biggestRow});
			
		} else { //If row does not exist...
			
			//$(this).calcSubWidth();
			//Set Width
			//$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
		
	  $(this).find(".sub").fadeTo('fast', 0, function() {
	  	$(this).parent().find('a').css('background-position', '0 0');
		  $(this).hide(); 
		  
	  });
	}


	var config = {    
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
	
	
	
	$('.project').hover(function(){
		$(this).find('.project_tab > span > h2').css('color', '#cb2027')
	}, function(){
		$(this).find('.project_tab > span > h2').css('color', '#999999')
	})
	
	 // initMenu
	 
	/* $('#menu > .expand > a').click(function(){
	 	
	 })*/
	 $('#accordion > .expand').accordion({
	 	bgStartPosition : '0 3px',
		bgFinishPosition : '0 -23px',
		speed: 200,
		openFirst : true
	 });
	 
	 
       /* $('#menu ul').hide();
        $('#menu ul:first').show();
        $('#menu li a').click(function(){
            var checkElement = $(this).next();
            if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                return false;
            }
            if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $('#menu ul:visible').slideUp(100);
                checkElement.slideDown(100);
                return false;
            }
        });*/
		
		
    

});
 