document.observe('dom:loaded',function(){
  if ($('link_practice')) {                                                                 // Check for presence of link
    $('link_practice').observe('click',function(event){                                     // Bind function to click event
      Event.stop(event);                                                                    // Stop normal link behavior
      if ($('sub_navigation_tools').visible()) {                                            // Is "Profit Tools" sub-navigation visible?
        new Effect.toggle('sub_navigation_practice','blind');                               // If so, blind "Build My Practice" open while...
        new Effect.toggle('sub_navigation_tools','blind');                                  // ... blinding "Profit Tools" closed.
      } else if ($('sub_navigation_performance').visible()) {                               // Is "Staff Performance" sub-navigation visible?
        new Effect.toggle('sub_navigation_practice','blind');                               // If so, blind "Build My Practice" open while...
        new Effect.toggle('sub_navigation_performance','blind');                            // ... blinding "Staff Performance" closed.
      } else if (!$('practice')) {                                                          // If neither of the other sub-navs are open ('else if'), AND we are not already inside the "Build My Practice" section (!$('practice'))...
        new Effect.toggle('sub_navigation_practice','blind');                               // Blind "Build My Practice" open...
        if ($('tools')) { new Effect.toggle('sub_navigation_tools','blind'); }              // ... and blind "Profit Tools" closed if it's open...
        if ($('performance')) { new Effect.toggle('sub_navigation_performance','blind'); }  // ... and blind "Staff Performance" closed if it's open.
      }
    });
  }
  if ($('link_tools')) {
    $('link_tools').observe('click',function(event){
      Event.stop(event);
      if ($('sub_navigation_practice').visible()) {
        new Effect.toggle('sub_navigation_tools','blind');
        new Effect.toggle('sub_navigation_practice','blind');
      } else if ($('sub_navigation_performance').visible()) {
        new Effect.toggle('sub_navigation_tools','blind');
        new Effect.toggle('sub_navigation_performance','blind');
      } else if (!$('tools')) {
        new Effect.toggle('sub_navigation_tools','blind');
        if ($('practice')) { new Effect.toggle('sub_navigation_practice','blind'); }
        if ($('performance')) { new Effect.toggle('sub_navigation_performance','blind'); }
      }
    });
  }
	if ($('link_performance')) {
		$('link_performance').observe('click',function(event){
			Event.stop(event);
			if ($('sub_navigation_practice').visible()) {
				new Effect.toggle('sub_navigation_performance','blind');
				new Effect.toggle('sub_navigation_practice','blind');
			} else if ($('sub_navigation_tools').visible()) {
				new Effect.toggle('sub_navigation_performance','blind');
				new Effect.toggle('sub_navigation_tools','blind');
			} else if (!$('performance')) {
				new Effect.toggle('sub_navigation_performance','blind');
				if ($('practice')) { new Effect.toggle('sub_navigation_practice','blind'); }
				if ($('tools')) { new Effect.toggle('sub_navigation_tools','blind'); }
			}
		});
	}
	if ($('location_selector')) { $('location_selector').observe('change',change_location); }
	if ($('is_aliasing')) { if ($F('is_aliasing') === 'true') { $$('form.disable_when_aliasing').invoke('disable'); } }
	if ($('link_back_to_top')) {
		$('link_back_to_top').observe('click',function(event){
			Event.stop(event);
			new Effect.ScrollTo('wrapper',{duration:0.5});
		});	
	}
	Element.monitorForms();
});
