function content_switch(switchto){
    // Hide and show script replaced with IE8 compliant script
    // as spacing was not correct with hide show version
    $("div[class='content']").each(function (index) {
        if ($(this).attr("id") != switchto){
            $(this).hide();
        } else {
            if ($(this).is(':visible')){
                // Do nothing, already visible
            } else {
                $(this).toggle();
            }
        }
    });
    
    // Hide all content blocks
    // $(".content").hide();
    
    // Show only specific block
    // $("#" + switchto).show();
}

function show_women_menu(){
	// Set the positioning of the div
	calculate_menu_positions();

	// Show the div
	$("#menu-women").fadeIn('fast');
	$("#menu-women-shadow").show();
	
	// Keep menu item tall and styled
	$("#navbar-item-women").attr("style","height:25px;background-color:#fff;");
	$("#navbar-item-women").children().css('color', '#858688');
}

function hide_women_menu(){
	$("#menu-women").fadeOut('fast');
	$("#menu-women-shadow").hide();

	// Reduce the menu item height
	$("#navbar-item-women").attr("style","height:20px;background-color:transparent;");
	$("#navbar-item-women").children().css('color', '#fff');	
}

function show_men_menu(){
	// Set the positioning of the div
	calculate_menu_positions();

	$("#menu-men").fadeIn('fast');
	$("#menu-men-shadow").show();

	// Keep menu item tall and styled
	$("#navbar-item-men").attr("style","height:25px;background-color:#fff;");	
	$("#navbar-item-men").children().css('color', '#858688');	
}

function hide_men_menu(){
	$("#menu-men").fadeOut('fast');
	$("#menu-men-shadow").hide();

	// Reduce the menu item height
	$("#navbar-item-men").attr("style","height:20px;background-color:transparent;");
	$("#navbar-item-men").children().css('color', '#fff');	
}

function calculate_menu_positions(){
	position = $("#logo").position();
	left_position = position.left;
	left_position = left_position + 30;
	menu_women_height = $("#menu-women").height();
	menu_men_height = $("#menu-men").height();
	
	$("#menu-women").attr("style", "left:" + left_position + "px;");
	$("#menu-women-shadow").attr("style", "left:" + left_position + "px;" );
	$("#menu-men").attr("style", "left:" + left_position + "px;");
	$("#menu-men-shadow").attr("style", "left:" + left_position + "px;");

    // Set heights
	$("#menu-women-shadow").height(menu_women_height + 20);
	$("#menu-men-shadow").height(menu_men_height + 20);
}

function admin_off(){
    $(".admin").hide();
    $(".admin-on").show();
    $("#wpadminbar").hide();
}

function admin_on(){
    $(".admin").show();
    $(".admin-on").hide();
    $("#wpadminbar").show();
}

$(document).ready(function () {
	// Get window width
	var window_width = $(window).width();

	// Set actions for nav items which show menus
	$("#navbar-item-women").bind("mouseenter",function(){hide_men_menu();show_women_menu();});
	$("#navbar-item-men").bind("mouseenter",function(){hide_women_menu();show_men_menu();});

	// Set actions to hide menus
	$("#navbar-item-home").bind("mouseenter",function(){hide_men_menu();hide_women_menu();});
	$("#navbar-item-aboutus").bind("mouseenter",function(){hide_men_menu();hide_women_menu();});
	$("#navbar-item-clinics").bind("mouseenter",function(){hide_men_menu();hide_women_menu();});
	$("#navbar-item-medicalteam").bind("mouseenter",function(){hide_men_menu();hide_women_menu();});
	$("#navbar-item-contactus").bind("mouseenter",function(){hide_men_menu();hide_women_menu();});
	$(".key_container").bind("mouseenter",function(){hide_men_menu();hide_women_menu();});
	$("#menu-men").bind("mouseleave",function(){hide_men_menu();});
	$("#menu-women").bind("mouseleave",function(){hide_women_menu();});
	
	// If the user resizes the widow, we need to recalulate the menu positioning
	$(window).bind("resize", function(){
		if (window_width != $(window).width()){
			// Close menus
			hide_men_menu();
			hide_women_menu();
			
			// Recalc window width
			window_width = $(window).width();
		}
	})	
	
    if (jQuery.browser.msie && jQuery.browser.version == '6.0'){
        ie6 = true;
        
        // Also fix header images
        $('#logo_image').attr("src", $('#logo_image').attr("src").replace(".png","_ie6.png"));
        $('#pioneering_image').attr("src", $('#pioneering_image').attr("src").replace(".png","_ie6.png"));
        $('#book_your_consultation_image').attr("src", $('#book_your_consultation_image').attr("src").replace(".png","_ie6.png"));
    } else {
        ie6 = false;
    }
    
	// Set-up the menu item mouseenter and mouseleave for all menu-items
    $("li[class='menu-item']").each(function (index) {
		// Set the event handlers
		$(this).bind("mouseenter", function(){
			// Set inner items to have white text
			if (ie6){
                // Nothing
            } else {
                $(this).children().css('color', '#fff');            
            }
		});
		$(this).bind("mouseleave", function(){
			$(this).children().css('color', '#858688');
		});
	});

    if (jQuery.browser.safari){
        $('#safari-spacer').show();
    }
	
    /*
    // Hide any answer items
    $("p[class='answer']").each(function (index) {
        // Hide
		$(this).hide();
	});

    // Get all questions and bind the click function to them
    $("a[class='question']").each(function (index) {
		// Set the event handlers
		$(this).bind("click", function(index2){
            // Show the related answer text, which we select by the anchor
            href = $(this).attr("href");
            href = href.replace("#","");
            selector = "a[name*=" + href + "]";
            $(selector).parent().toggle();
            return(false);
		});
	});
    */
    
    // Register global error handler
    window.onerror = function (message, uri, line) {
        // An unplanned exception occured, it should not stop
        // the form working however, as we've caught it here.  We know
        // that typically it is a cosmetic UI error in JQuery on IE8.
        // Return true to prevent the browser from raising an exception.
        return true;
    }
});  
