
    topNav = ""; //topNav_contacts, topNav_aboutSPD, topNav_policeWork, topNav_workingTogether, topNav_safety, topNav_data,topNav_careers
    leftNav_MainCat = "";
    leftNav_SecondaryCat = "";
    leftNav_TertiaryCat = "";

function whatPage(){
    $("ul#leftNav li.TIERTWO_SUB").hide();
    $("ul#leftNav li.TIERTWO_SUB_PARENT").hide();
    $("ul#leftNav li.TIERTWO_SUB2").hide();

    if(topNav!="" && $("#"+topNav)){
      $("#"+topNav+" a img").attr('src',"/police/images/"+topNav+"_on.png");
  	}
    leftNav_MainCat = "leftNav_"+ leftNav_MainCat;

    if(leftNav_MainCat !="" && $(leftNav_MainCat)){
      leftNav_SecondaryCat = leftNav_MainCat+"_"+leftNav_SecondaryCat;
      if($("#"+leftNav_MainCat).hasClass('TIERTWO')){
        $("#"+leftNav_MainCat).switchClass('TIERTWO','TIERTWO_ON');
			}else{
        $("#"+leftNav_MainCat).switchClass('TIERTWO_PARENT','TIERTWO_PARENT_ON');   
			}
      $("#"+leftNav_MainCat+"_container li").show();
	    $("ul#leftNav li.TIERTWO_SUB2").hide();
      if(leftNav_SecondaryCat !="" && $(leftNav_SecondaryCat)){
        leftNav_TertiaryCat = leftNav_SecondaryCat+"_"+leftNav_TertiaryCat;
  			if($("#"+leftNav_SecondaryCat).hasClass('TIERTWO_SUB_PARENT')){
	  			$("#"+leftNav_SecondaryCat).switchClass('TIERTWO_SUB_PARENT','TIERTWO_SUB_PARENT_ON')	
		  	}else if($("#"+leftNav_SecondaryCat).hasClass('TIERTWO_SUB')){
            $("#"+leftNav_SecondaryCat).switchClass('TIERTWO_SUB','TIERTWO_SUB_ON');	
	      }
	      if(leftNav_TertiaryCat != "" && $(leftNav_TertiaryCat)){
          $("#"+leftNav_SecondaryCat+"_container li").show();
   		    $("#"+leftNav_TertiaryCat).switchClass('TIERTWO_SUB2','TIERTWO_SUB2_ON');
    		}
	    }
    }
  }

$(document).ready(function() {
  brow7 = false;

 if ($.browser.msie  && parseInt($.browser.version) == 7) {
    brow7 = true;
//    alert("IE 7 browser")
     $("#mainContainer").css("z-index","1");
  } else {
    brow7 = false;
  }

  function megaHoverOver(){
  if(brow7 == false){
//    $("#mainContainer").css("z-index","-1")
  $(this).find(".sub").stop().fadeTo('fast', 1).show();
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 

		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});
//			alert($(this).find(".sub").left());
			$(this).find(".row:last").css({'margin':'0'});

		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
		}
		
    offset = $(this).position();
    if(offset.left >360 && $(this).find(".sub").width() >= 600){
  		$(this).find(".sub").css({'left' : -((offset.left - 338)) });
 //     alert();
    }else if(offset.left >360 && $(this).find(".sub").width() <= 300){
			$(this).find(".sub").css({'left' : -((offset.left - 638)) });
		}
		
//    bigRow = $(this).find(".sub").css({'width' : rowWidth});
//    console.log("OFFSETLEFT: "+ offset.left +" ROW WIDTH: "+ rowWidth );		
	}
}
	
	function megaHoverOut(){ 
  if(brow7 == false){
//     $("#mainContainer").css("z-index","1")
//	}
    $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
   }
  }

if(brow7 == false){

	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 50, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 250, // 250 number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#deptTopNav li .sub").css({'opacity':'0'});
	$("ul#deptTopNav li").hoverIntent(config);
  }
});

