( function($) {
$(document).ready(function() {

// **************** Modify List and DIV properties based on page name ****************

// Get Current page name
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

// Get First half of URL (For Directories)
var firstHalf = sPath.replace('sPage', '');


// UNIVERSAL FUNCTIONS **************************************************
// (HOME LOGO HOVER, DROP DOWN MENU AND TOP NAV HOVER, SUB NAV LINK SELECTION)

// Home Logo Hover
if(firstHalf == "/blog/"){ // If we are in the blog then bump up directories one level
 $("#logo").mouseenter(function() {	$(this).attr("src", "../images/header_logo_o.jpg"); });
 $("#logo").mouseleave(function() { $(this).attr("src", "../images/header_logo.jpg");	});
}else{
 $("#logo").mouseenter(function() {	$(this).attr("src", "images/header_logo_o.jpg"); });
 $("#logo").mouseleave(function() { $(this).attr("src", "images/header_logo.jpg");	});
}



// Hover top nav button and drop down the sub menu 
$(".firstlevel").hover(function() { // On hover of Top Nav link
		$(".secondlevel").hide(); // Hide the Sub Nav
		
		// Turn all Top Level buttons to the off state
		if(firstHalf == "/blog/"){ // If we are in the blog then bump up all directories one level
			$("#main-about").find('img').attr("src", "../images/nav_main_about.gif");
			$("#main-team").find('img').attr("src", "../images/nav_main_team.gif");
			$("#main-patient").find('img').attr("src", "../images/nav_main_patient.gif");
			$("#main-contact").find('img').attr("src", "../images/nav_main_contact.gif");
		}else{
			$("#main-about").find('img').attr("src", "images/nav_main_about.gif");
			$("#main-team").find('img').attr("src", "images/nav_main_team.gif");
			$("#main-patient").find('img').attr("src", "images/nav_main_patient.gif");
			$("#main-contact").find('img').attr("src", "images/nav_main_contact.gif");
		}
		
		$("nav-main img").attr("src", newimgsrc); // UNse
				var imgsrc = $(this).find('img').attr("src");
				var fileExt = imgsrc.substr(-6); // Get the last 6 characters to see if its active
				if(fileExt != "_o.gif"){		 // If the Image is not already Highlighted	then highlight it
					var preimgsrc = imgsrc.replace('.gif','');
					var newimgsrc = preimgsrc + "_o.gif";
					$(this).find('img').attr("src", newimgsrc);
				}

	// Show the sub nav based on the top nav item being scrolled over
	var buttonName = $(this).attr("id");
	if(buttonName == "main-about"){	  $('#nav-sub-welcome').show(); }
	if(buttonName == "main-team"){    $('#nav-sub-team').show(); }
	if(buttonName == "main-patient"){ $('#nav-sub-patient').show(); }
	if(buttonName == "main-contact"){ $('#nav-sub-contact').show(); }

});



// Change Current Sub Nav Link to Selected
$("a[href='" + sPage + "']").attr("class","selected"); // Selector is based on current page name
// END UNIVERSAL FUNCTIONS **************************************************
	
	

// TAB SPECIFIC FUNCTIONS **************************************************
// (ON STATE FOR TOP NAV, SHOW CURRENT SUB NAV, REMOVE MOUSEOVER FOR CURRENT TOP NAV)

// Welcome
if(sPage.indexOf("welcome_") == 0){ // Identify tab based on URL Prefix
	$("#nav-main-welcome").attr("src","images/nav_main_about_o.gif"); // On sate for top nav
	$("#nav-sub-welcome").show(); // Show Sub nav 
	$("#main-about").removeAttr('onmouseover'); // Remove Mouseover Atttribute 	
}

	// Special Condition for Blog pages under Welcome Tab
	if(firstHalf == "/blog/"){
		$("#nav-main-welcome").attr("src","../images/nav_main_about_o.gif");
		$("#nav-sub-welcome").show();
		$("#main-about").removeAttr('onmouseover');
		$("a[href='../blog']").attr("class","selected"); // Change current link to Selected 
	}

// Our Team
if(sPage.indexOf("team_") == 0){
	$("#nav-main-team").attr("src","images/nav_main_team_o.gif"); 
	$("#nav-sub-team").show();
	$("#main-team").removeAttr('onmouseover'); 
}

// Patient Care
if(sPage.indexOf("patient_") == 0){
	$("#nav-main-patient").attr("src","images/nav_main_patient_o.gif");
	$("#nav-sub-patient").show(); 
	$("#main-patient").removeAttr('onmouseover');
}

// Contact
if(sPage.indexOf("contact_") == 0){
	$("#nav-main-contact").attr("src","images/nav_main_contact_o.gif");
	$("#nav-sub-contact").show();
	$("#main-contact").removeAttr('onmouseover'); 
}
// END TAB SPECIFIC FUNCTIONS **************************************************

	

// SECOND LEVEL SUB NAVIGATION SELECTORS  **************************************************

// Select corresponding Sub Nav button for section
if(sPage.indexOf("patient_common") == 0){      $("a[href='patient_common.html']").attr("class","selected"); }
if(sPage.indexOf("patient_cancer") == 0){     $("a[href='patient_cancer.html']").attr("class","selected"); }
if(sPage.indexOf("patient_men") == 0){        $("a[href='patient_men.html']").attr("class","selected"); }
if(sPage.indexOf("patient_women") == 0){      $("a[href='patient_women.html']").attr("class","selected"); }
if(sPage.indexOf("patient_pelvic") == 0){     $("a[href='patient_pelvic.html']").attr("class","selected");}
if(sPage.indexOf("patient_pediatrics") == 0){ $("a[href='patient_pediatrics.html']").attr("class","selected"); }
if(sPage.indexOf("patient_robots") == 0){     $("a[href='patient_robots.html']").attr("class","selected"); }
if(sPage.indexOf("contact_directions") == 0){ $("a[href='contact_directions.html']").attr("class","selected"); }

// Make selected appropriate Sub Sub Nav Buttons
if(sPage == "patient_women_overactive_bladder.html"){    $("a[href='patient_women_overactive_bladder.html']").parent().attr("class","current"); }
if(sPage == "patient_women_neuromodulation.html"){       $("a[href='patient_women_neuromodulation.html']").parent().attr("class","current"); }
if(sPage == "patient_women_pelvic_organ_prolapse.html"){ $("a[href='patient_women_pelvic_organ_prolapse.html']").parent().attr("class","current"); }
if(sPage == "patient_women_urinary_incontinence.html"){  $("a[href='patient_women_urinary_incontinence.html']").parent().attr("class","current"); }
if(sPage == "patient_women_urodynamics.html"){           $("a[href='patient_women_urodynamics.html']").parent().attr("class","current"); }
// END SECOND LEVEL SUB NAVIGATION SELECTORS  **************************************************


});

} ) ( jQuery );
