// JavaScript Document

// Display Roll Over

function closeNav() {
  // $('#'+$(this).attr('id')+' .sub').hide();
	$('#'+$(this).attr('id')+' .section').css({color:'#000','border-color': '#000'});
	/* var x = $('#'+$(this).attr('id')+' a.section').css("background-position");
	if (x == 'undefined' || x == null) {
		x = $('#'+$(this).attr('id')+' a.section').css("background-position-x");
	} else {
		x = x.split(" ")[0]
	}
	$('#'+$(this).attr('id')+' a.section').css({backgroundPosition: x+' 0'}); */
}

$().ready(function(e) {
    $('#container').css({height: $(document).height()});
    
    $('.level').mouseenter(function(){showNav($(this).attr('id').replace('_level',''));});
    
    $('.block').bind('mouseleave', function(e) {
  		$('.block').hide();
  		$('.level').each(closeNav);
    });
    
    $('#container').bind('mouseleave', function(e) {
  		$('.block').hide();
  		$('.level').each(closeNav);
    });
    
    $('.featured-image-credit').hide();
    $('.featured-image').hover(
      function() {
        $(this).find('div').fadeIn('normal');
      },
      function() {
        $(this).find('div').fadeOut('normal');
      }
    );
    
});

function showNav(section) {
    
	if (section){
		document.getElementById(section + "_level").style.zIndex = 200;
    
    /* var x = $('#' + section + '_level a.section').css("background-position");
		if (x == 'undefined' || x == null) {
			x = $('#' + section + '_level a.section').css("background-position-x");
		} else {
			x = x.split(" ")[0]
		}
		$('#' + section + '_level a.section').css({backgroundPosition: x+" -30px"}); */
        
    /* if (document.getElementById(section + "_sub")) {
  		document.getElementById(section + "_sub").style.position = "absolute";
  		document.getElementById(section + "_sub").style.zIndex = 100;
  		document.getElementById(section + "_sub").style.display = "block";
    } */
    
    $('#'+section+'_level .section').css({color:'#fff','border-color': '#fff'});
		
		var h = $('#container').height();
		if ($('#flash').length){
		  h = h + 51
		}
		$('#'+section+'_block').css({height: h});
    $('#'+section+'_block').show();
		
		$('.block:not(#'+section+'_block)').hide();
		$('.level:not(#'+section+'_level)').each(closeNav);
	}
}