/**
 * @fileOverview This file contains all Find a Physician code
 * @author <a href='http://wiki.element115.net/index.php/User:Eschleeper'>eschleeper</a> 
 */

var FindADoctor_SearchResultsURL = "/cs/Satellite?rendermode=previewnoinsite&pagename=eHA_CHS/eHA_LandingPage_C/eHA_CHS/SubTemplate/ProviderMainPage_Results";
var FindADoctor_FindADoctorSubTemplateURL = "/cs/Satellite?rendermode=previewnoinsite&pagename=eHA_CHS/eHA_LandingPage_C/eHA_CHS/SubTemplate/ProviderMainPage_Results";//+templateUrls();
var lastNameTypeAhead = "/cs/Satellite?rendermode=previewnoinsite&pagename=eHA_CHS/Physician/type_ahead&site=eHA_CHS&c=eHA_Dir_C&postName=advanced_search_lastname_text";
var clinicalInterestTypeAhead = "/cs/Satellite?rendermode=previewnoinsite&pagename=eHA_CHS/Physician/type_ahead&site=eHA_CHS&c=eHA_Dir_C&postName=advanced_search_condition_text";

Ajax.Request.prototype.abort = function() {
    this.transport.onreadystatechange = Prototype.emptyFunction;
    this.transport.abort();
    Ajax.activeRequestCount--;
    if($$('#content_body .ajax_loading')[0]){$$('#content_body .ajax_loading')[0].remove()}
};
/**
 * Our Physician Object.
 * @namespace
 */
var Physician = {
	/**
	* initializes all the objects under Physician namespace. Loads AJAX if there is a hash value present.
	* @function
	*/
	init:function(){
		this.ajax.init(this.uiController);
		this.resultsUI.init();
		this.searchUI.init();
		this.uiController.init(this.resultsUI,this.searchUI);
		this.ajax.controller = this.uiController;
		this.typeAhead.load();
		this.mapUtil.init();
		this.urlChangeHandler.init(this.ajax.loadFromURL);
		if(SWFAddress.getValue().length > 1){this.ajax.loadFromURL()}
		document.observe('physicianEvent:urlChange',this.ajax.loadFromURL.bind(this));
	},
	/**
	 * uiController maps physician search events to the UI Components
	 * @namespace
	 */
	uiController:{
		/**
		 * initializes UI controller
		 * @function
		 * @param {Physician.resultsUI} passResults resultsUI Object
		 * @param {Physician.searchUI} passSearch searchUI Object
		 */
		init:function(passResults,passSearch){
			this.results=passResults;
			this.search=passSearch;
			this.isSearchUI=true;
			document.observe('physicianEvent:reset',this.setSearchUI.bind(this));
			document.observe('physicianEvent:xhrCreate',this.showLoading.bind(this));
			document.observe('physicianEvent:xhrComplete',this.appendResults.bind(this));
		},
		/**
		 * Clears the results, Hides the Search form
		 * @function
		 */
		setResultsUI:function(){
			this.search.hide();this.results.clear();this.isSearchUI=false;
		},
		/**
		 * Clears the results, Shows the Search form
		 * @function
		 */
		setSearchUI:function(){
			this.results.clear();this.search.show();this.isSearchUI=true;
		},
		/**
		 * calls appendResults on resultsUI object
		 * @function
		 * @param {Object} event Object from protoype fire. Contains transport Object from Ajax.Request
		 */
		appendResults:function(event){$$('body')[0].removeClassName('loading');this.results.appendResults(event.memo.transport.responseText); },
		/**
		 * adds class="loading" to the body
		 * @function
		 * @param {Object} event Object from protoype fire.
		 */
		showLoading:function(event){$$('body')[0].addClassName('loading');this.search.clear();}
	},
	/**
	 * Object that manages the search forms.  Used by {@link Physician.uiController}
	 * @namespace
	 */
	searchUI: {
		/**
		 * assigns functions to events for the search forms
		 * @function
		 */
		init:function(){
			this.loadingImage = new Element("img",{'src':'/um_core/css/big_spin.gif','alt':'Please Wait.'});
			this.loadingImage.addClassName("ajax_loading");
			this.searchForms=$('forms');
			$$('div#content_body form input').each(function(element){
				element.observe('focus',function(){this.addClassName('input_focus');this.siblings().each(function(label){label.addClassName('label_focus');})});
				element.observe('blur',function(){this.removeClassName('input_focus');this.siblings().each(function(label){label.removeClassName('label_focus');})});
			});
			this.isSliderActive = false;
			if($('advanced_search')){
				//$('advanced_search').setStyle({display:'none'})
			}
			$('forms').select('form').each(function(element){
				element.setAttribute('autocomplete','off');
				//alert(element.down('fieldset'));
				if(element.down('fieldset').getAttribute('id')!='advanced_search'){
					element.down('div.submit input').observe('click', function(){
						$('forms').select('input[type="text"]').each(function(element){
							element.value=element.value.gsub('%', '%23');
						});
						SWFAddress.setValue(this.up('form').serialize());
						$('forms').select('input[type="text"]').each(function(element){
							element.value=element.value.gsub('%23', '%');
						});
						return false;
					}).observe('mouseover',function(){this.addClassName('submit_hover')}).observe('mouseout',function(){
						this.removeClassName('submit_hover')});
				}
				else {
					//this.advancedSearchForm = element;
					//Physician.mapUtil.init(element);
					element.down('div.submit input').observe('click', function(event){
						document.fire('physicianEvent:mainFormSubmit');return false;
					}).observe('mouseover',function(){
						this.addClassName('submit_hover')
					}).observe('mouseout',function(){
						this.removeClassName('submit_hover')
					});
				}
			});
			/*if($('advanced_more_options_button')){
				//this.searchForm.insert($('advanced_more_options_button'));
				$('advanced_more_options_button').observe('click',this.toggleAdvancedSearch.bindAsEventListener(this));
			}*/
			if($('distance')!=null){
				this.distanceInput=$('distance');
				this.sliderDiv=$('distance_slider');
				this.startSlider();
			}
		},
		/*toggleAdvancedSearch:function(){
			if($('advanced_more_options_button').hasClassName('less')==true){$('advanced_more_options_button').removeClassName('less');}
			else{$('advanced_more_options_button').addClassName('less');}
			Effect.toggle('advanced_search', 'blind',{duration:0.5,afterFinish:function(){this.startSlider()}.bind(this)});
		},*/
		/**
		 * attach scriptaculous slider to the divs.
		 * @function
		 */
		startSlider:function(){
			if(!this.isSliderActive){
				new Control.Slider(this.sliderDiv.down('.handle'), this.sliderDiv, {
					range:  $R(1,50),
					values: $R(1,50),
					sliderValue: 10,
					onSlide: function(value) {this.distanceInput.value=value+"miles";}.bind(this),
					onChange: function(value) {this.distanceInput.value=value+"miles";}.bind(this)
				});
				this.isSliderActive=true;
				this.sliderDiv.down('.handle').observe('mouseover',function(){this.addClassName('slider_hover')});
				this.sliderDiv.down('.handle').observe('mouseout',function(){this.removeClassName('slider_hover')});
				this.sliderDiv.down('.handle').observe('mousedown',function(){this.up().addClassName('slider_div_hover')});
				this.sliderDiv.down('.handle').observe('mouseup',function(){this.up().removeClassName('slider_div_hover')});
			}
		},
		/**
		 * show the search form and remove results divs.
		 * @function
		 */
		show:function(){
			if(this.searchForms){
				if($('results')){
					if($('no_results')==null){
						$('results').remove();
					}
					if($('lat')!=null){
						$('lat').value='';
						$('lon').value='';
					}
				}
				if($('content_workspace')!=null){
					$('content_workspace').remove();
				}
				$('content_body').select('h1.category_title')[0].update('Find a Physician');
				$("content_body").removeClassName('search_results_container');
				if($(this.searchForms)){this.searchForms.show();}
			}
		},
		/**
		 * hide the search form
		 * @function
		 */
		hide:function(){
			if(this.searchForms){
				if($(this.searchForms)){this.searchForms.hide();}
			}
			$("content_body").addClassName('search_results_container');
		},
		clear:function(loadingImage){		
			if($("results")) {$("results").update(this.loadingImage);}
			else{$("content_body").insert(this.loadingImage);}
			this.hide();
			//if($('bread_crumbs')){$('bread_crumbs').remove();}
		}
	},
	/**
	 * Object that manages the results. Used by {@link Physician.uiController}
	 * @namespace
	 */
	resultsUI: {
		init:function(){
			this.clear;
			this.slider={};
		},
		imagesToolTips:new Array(),
		show:function(){
		},
		clear:function(){		
			//if($('bread_crumbs')){$('bread_crumbs').remove();}
		},
		/**
		 * displays search results and assigns events
		 * @function
		 * @param {String} htmlText Results of the search- HTML loaded from server with AJAX.
		 */
		appendResults:function(htmlText){
			this.clear();
			var hashParams = SWFAddress.getValue().toQueryParams();
			$('content_body').select('h1.category_title')[0].update('Physician Search Results');
			if($$('#content_body .ajax_loading')[0]){$$('#content_body .ajax_loading')[0].remove()}
			if($('content_workspace')!=null){
				if($('results')!=null){$('results').remove();}
				$$('.category_title')[0].insert({'after':htmlText});
				if($('no_results')!=null){
					Physician.uiController.setSearchUI(false);
				}
				else{
					this.slider.setValue(parseInt(hashParams['distance']));
				}
			}
			else{
				if($('results')!=null){$('results').remove();}
				$$('.category_title')[0].insert({'after':htmlText});
				if($('no_results')!=null){
					Physician.uiController.setSearchUI(false);
				}
				else {
					if($('filter_apply')){$('filter_apply').observe('click', function(event){
						Event.stop(event);$('startindex').value='1';
						document.fire('physicianEvent:filterFormSubmit');
						//SWFAddress.setValue($('filter_form').serialize());
					});}
					if($('filter_distance')){
						var sliderDiv=$('filter_distance_slider');
						var distanceInput=$('filter_distance');
						this.slider = new Control.Slider(sliderDiv.down('.handle'), sliderDiv, {
							range:  $R(1,50),
							values: $R(1,50),
							sliderValue: hashParams['distance'],
							onSlide: function(value) {distanceInput.value=value+"miles";}.bind(this),
							onChange: function(value) {distanceInput.value=value+"miles";}.bind(this)
						});
						sliderDiv.down('.handle').observe('mouseover',function(){this.addClassName('slider_hover')});
						sliderDiv.down('.handle').observe('mouseout',function(){this.removeClassName('slider_hover')});
						sliderDiv.down('.handle').observe('mousedown',function(){this.up().addClassName('slider_div_hover')});
						sliderDiv.down('.handle').observe('mouseup',function(){this.up().removeClassName('slider_div_hover')});
						/*if($("search_form_form")){
							if($("search_form_form").down("noscript")){
								$("search_form_form").down("noscript").remove();
							}
						}*/
					}
					if($("filter_form")){
						if($("filter_form").down("noscript")){
							$("filter_form").down("noscript").remove();
						}
					}
					if(Prototype.Browser.IE6){
						$$('div#content div.provider_search div#content_body div#results ul').each(function(element){
							element.setStyle({margin:'0px 5px'})
						})
						$$('li.result').each(function(element){
							element.setStyle({margin:'4px'})
						})
					}
				}
			}
			if($('filter_form')!=null){
				$('filter_form').select('input').each(function(element){
					if(hashParams[element.name]){
						//if(hashParams[element.name]!=null){
							element.value=hashParams[element.name];
						//}
					}
				});
				$('filter_form').select('select').each(function(element){
					var valueToFind=hashParams[element.name];
					var options=element.select('option');
					for(var i=0;i<options.length;i++){
						if(valueToFind==options[i].value){element.selectedIndex=i}
					}
				});
			}
			if($('search_form_startindex')!=null){
				if($("search_form_startindex").down("noscript")){
					$("search_form_startindex").down("noscript").remove();
				}
					$('search_form_startindex').observe('submit',function(event){
						Event.stop(event);
						SWFAddress.setValue($('search_form_startindex').serialize())}
					);
				}
			//$$('#results .result .actions .favorites a').each(function(element){element.observe('click',function(){this.addItemToFavorites(element)}.bind(this));}.bind(this));
			//if()
			$$('div.results_pagination li a').each(function(element){element.observe('click',function(event){
				var element=event.element();
				Event.stop(event);
				element.href="javascript:void(0)";
				var paginationAParentElement = element.up('li');
				if(paginationAParentElement.hasClassName('next')==false&&paginationAParentElement.hasClassName('previous')==false&&paginationAParentElement.hasClassName('page_selected')==false){			
					$('startindex').value=element.innerHTML;
					document.fire('physicianEvent:filterFormSubmit');
				}
				else if(paginationAParentElement.hasClassName('next')==true){
					if($('filter_form').select('input[name="startindex"]')[0].value==''){$('filter_form').select('input[name="startindex"]')[0].value='1'}
					$('filter_form').select('input[name="startindex"]')[0].value=parseInt($('filter_form').select('input[name="startindex"]')[0].value)+1;
					document.fire('physicianEvent:filterFormSubmit');
				}
				else if(paginationAParentElement.hasClassName('previous')==true){
					if($('filter_form').select('input[name="startindex"]')[0].value==''){$('filter_form').select('input[name="startindex"]')[0].value='1'}
					$('filter_form').select('input[name="startindex"]')[0].value=parseInt($('filter_form').select('input[name="startindex"]')[0].value)-1;
					document.fire('physicianEvent:filterFormSubmit');
				}
			});});
			$$('div.results_per_page_pagination div.results_inner a').each(function(element){
				element.observe('click',function(event){
					Event.stop(event);
					$('directory_results_per_page').value=Event.element(event).innerHTML;
					$('filter_form').select('input[name="startindex"]')[0].value=1;
					document.fire('physicianEvent:filterFormSubmit');
				});
			})
			$$('.actions ul').each(function(element){
				element.setStyle({display:'block'});
				element.insert(new Element('li').addClassName('see_more').insert(new Element('a',{'href':'javascript:void(0)'}).update('Show Locations').observe('click',function(event){
					Effect.toggle(Event.element(event).up('li.result').select('.locations')[0], 'blind',{duration:0.5,afterFinish:function(obj){
						var anchor=obj.element.up('li').select('li.see_more a')[0];
						if(anchor.innerHTML=='Show Locations'){anchor.update('Hide Locations')}
						else if (anchor.innerHTML=='Hide Locations'){anchor.update('Show Locations')}
					}})
				})));
				element.up('li.result').select('.locations')[0].hide();
			});
			$$('div#results ul div.picture_biography').each(function(element){
				this.imagesToolTips.push(new Tooltip(element.up('li').select('h3')[0], element,'absolute'));
				$('content').insert(element);
			}.bind(this))
			mediaDirectory.assignMediaEvents();
		},
		addItemToFavorites:function(element){
			var resultID=element.getAttribute('id').replace('result_a_','');
			$("favorites").down("p").hide();
			Effect.Appear('favorites_wrapper');
			if($('result'+resultID)){
				var resultDiv=$('result'+resultID);
				var currentFavoritesCookie = Cookie.getData("eHA_FindADoctor_Favorites");
				if(currentFavoritesCookie){
					if(currentFavoritesCookie.length>0){currentFavoritesCookie = currentFavoritesCookie+"-"+resultID;}
					else{currentFavoritesCookie = resultID;}
					Cookie.setData("eHA_FindADoctor_Favorites",currentFavoritesCookie,365);
				}
				else{Cookie.setData("eHA_FindADoctor_Favorites",resultID,365);}
				if(!$("favorite_"+resultID)){
					resultDiv.addClassName("favorite");
					var newDIV = new Element("div",{id:"favorite_"+resultID},{display:"none"}).addClassName("favorite_item");;
					var newH4 = new Element("h4").appendChild(resultDiv.select("h3 a")[0].cloneNode(true));
					var newUL = new Element("ul");
					if(resultDiv.select("div.specialties").length>0){newUL.appendChild(new Element("li",{className:"specialties"}).update(resultDiv.select("div.specialties")[0].innerHTML))}
					//if(resultDiv.select(".affiliation p").length>0){newUL.appendChild($CE("li",{className:"affiliation"}).update(resultDiv.select(".affiliation p")[0].innerHTML))}
					//if(resultDiv.select(".phone p").length>0){newUL.appendChild($CE("li",{className:"phone"}).update(resultDiv.select(".phone p")[0].innerHTML))}
					newDIV.appendChild(newH4);	
					newDIV.appendChild(new Element("a",{href:"javascript:void(0)",className:"delete",title:"Remove this from Favorites"}).update("Remove this from Favorites").observe('click',function(event){this.removeItemFromFavorites(event)}.bind(this)));
					newDIV.appendChild(newUL);
					$('favorites').appendChild(newDIV);
					Effect.Appear("favorite_"+resultID,{duration:0.5});
				}
				else{Effect.Appear("favorite_"+resultID,{duration:0.5});}
			}
		},
		removeItemFromFavorites:function(event){
			var favoriteDiv = Event.element(event).up('.favorite_item');
			Effect.Fade(favoriteDiv.id,{duration:0.2});
			$(favoriteDiv.id).remove();
			$(favoriteDiv.id.replace("favorite_","result")).removeClassName("favorite");
			var currentFavoritesCookie = Cookie.getData("eHA_FindADoctor_Favorites");
			if(currentFavoritesCookie){
				var resultID = favoriteDiv.id.replace("favorite_","");
				// this string manipulation may leave a trailing hyphen. that is acceptable
				currentFavoritesCookie = currentFavoritesCookie.replace(resultID,"").replace(/--/g,"-");
				Cookie.setData("eHA_FindADoctor_Favorites",currentFavoritesCookie,365);
			}else{
			// an error has occured.  if there is a favorite, there should be a cookie unless user agent will not allow cookies
			}
			//display default message if no selected results in favorites
			if($("favorites").down("div")==undefined){
			$("favorites").down("p").show();		
			}

			return false;
		}
	},
	/**
	 * all ajax calls go through this object
	 * @namespace
	 */
	ajax: {
		/**
		 * initializes vars and objects needed
		 * @function
		 * @param {Physician.uiController} controller uiController from Physician namespace
		 */
		init:function(controller){
			this.currentXHRObj={};
			this.isLoading=false;
			this.loadingImage = new Element("img",{'src':'/um_core/css/big_spin.gif','alt':'Please Wait.'});
			this.loadingImage.addClassName("ajax_loading");
			this.uiController=controller;
			this.serverCall=FindADoctor_FindADoctorSubTemplateURL;
		},
		/**
		 * loads HTML from the server, params are fetched from the hash in the url
		 * @function
		 */
		loadFromURL:function(){
			if(this.isLoading==true){this.currentXHRObj.abort();}
			//if(this.uiController.isSearchUI==true){
			if(!$('results')){
				this.serverCall=FindADoctor_FindADoctorSubTemplateURL;
			}
			else{
				this.serverCall=FindADoctor_SearchResultsURL;
			}
			var ajaxParams=SWFAddress.getValue().replace('/','');
			var paramsObj=ajaxParams.toQueryParams();
			if(paramsObj.showfilters=='false'&&$('content_workspace')==null){
				paramsObj.showfilters='true';
				ajaxParams=Object.toQueryString(paramsObj);
			}
			if(paramsObj.showfilters=='true'&&$('content_workspace')!=null){
				paramsObj.showfilters='false';
				ajaxParams=Object.toQueryString(paramsObj);
			}
			if(SWFAddress.getValue().indexOf('=')!=-1){
				document.fire('physicianEvent:xhrOpen');
				this.isLoading=true;
				this.currentXHRObj = new Ajax.Request(this.serverCall,{
					method:'get',
					asynchronous:true,
					parameters: decodeURI(ajaxParams).gsub('%2f20',' '),
					onCreate: function(){document.fire('physicianEvent:xhrCreate')},
					onSuccess: function(transport){/*this.uiController.appendResults(transport.responseText);displayActions();*/},
					onComplete: function(transport){
						document.fire('physicianEvent:xhrComplete',{transport:transport});
						this.isLoading=false;
					}.bind(this),
					onFailure: function(){/*alert('Something went wrong...');*/}
				});
			}
			else{this.uiController.setSearchUI(false);}
			
		}
	},
	/**
	 * attaches functions to SWFAddressEvent
	 * @namespace
	 */
	urlChangeHandler: {
		/**
		 * attaches functions to SWFAddressEvent
		 * @function
		 * @param {function} func
		 */
		init:function(func){
			//this.handleChange=func;
			SWFAddress.addEventListener(SWFAddressEvent.INTERNAL_CHANGE, this.handleChange);
			SWFAddress.addEventListener(SWFAddressEvent.EXTERNAL_CHANGE, this.handleChange);
		},
		/**
		 * physicianEvent protoype's fire is called on the document
		 * @function
		 */
		handleChange:function(){
			//this.Physician.ajax.loadFromURL();
			document.fire('physicianEvent:urlChange');
			//Physician.mapUtil.gecodeAddress();
		}
	},
	/**
	 * attaches functions to events to run scriptaculous autocompleter on text inputs
	 * @namespace
	 */
	typeAhead: {
		load:function(){
			this.loadLastNames();
		},
		/**
		 * loads last names from server via AJAX and creates autocompleter for last name text input
		 * @function
		 */
		loadLastNames:function(){
			new Ajax.Request(lastNameTypeAhead,{
				method:'get',
				//parameters: "postName="+postName,
				onCreate: function(){},
				onSuccess: function(transport){
					$('advanced_search_lastname_text_typeAhead').setStyle({background:"#fff",border:"1px solid #888"});
					new Autocompleter.Local("advanced_search_lastname_text","advanced_search_lastname_text_typeAhead",(transport.responseText).evalJSON(true),{fullSearch:true,partialChars:2});
					this.loadConditions();
				}.bind(this),
				onFailure: function(){/*alert('Something went wrong...');*/}
			}); 
		},
		/**
		 * loads conditions from server via AJAX and creates autocompleter for last name text input
		 * @function
		 */
		loadConditions:function(){
			new Ajax.Request(clinicalInterestTypeAhead,{
				method:'get',
				//parameters: "postName="+postName,
				onCreate: function(){},
				onSuccess: function(transport){
					$('advanced_search_condition_text_typeAhead').setStyle({background:"#fff",border:"1px solid #888"});
					new Autocompleter.Local("advanced_search_condition_text","advanced_search_condition_text_typeAhead",(transport.responseText).evalJSON(true),{fullSearch:true,partialChars:2});
				}.bind(this),
				onFailure: function(){/*alert('Something went wrong...');*/}
			}); 
		},
		createAutoCompleter:function(){
		}
	},
	/**
	 * this Object does geo coding with Google Maps API
	 * @namespace
	 */
	mapUtil:{
		/**
		 * creates Objects and vars needed to run geocoder
		 * @function
		 */
		init:function(){
			this.geocoder = new GClientGeocoder();
			this.zipRegex = /^\d{5}([\-]\d{4})?$/;
			//this.searchForm=form;
			document.observe('physicianEvent:mainFormSubmit',function(){this.gecodeAddress();}.bind(this))
			document.observe('physicianEvent:filterFormSubmit',function(){this.gecodeAddressFilter();}.bind(this))
		},
		/**
		 * geocodes address and puts lat and long into advanced search form. Then calls setValue on SWFAddress.
		 * @function
		 */
		gecodeAddress:function(){
			if(this.isZipCode($('zipcode').value)){
				this.geocoder.getLatLng(($('zipcode').value),
				function(point){
						if(point){$('lat').value=point.lat();$('lon').value=point.lng();}
						SWFAddress.setValue($('search_form_form').serialize());
					}.bind(this)
				);
			}
			else{
				$('lat').value='';$('lon').value='';
				SWFAddress.setValue($('search_form_form').serialize());
			}
		},
		/**
		 * geocodes address and puts lat and long into filter form. Then calls setValue on SWFAddress.
		 * @function
		 */
		gecodeAddressFilter:function(){
			if(this.isZipCode($('zipcode').value)){
				this.geocoder.getLatLng(($('zipcode').value),
				function(point){
						if(point){$('filter_lat').value=point.lat();$('filter_lon').value=point.lng();}
						SWFAddress.setValue($('filter_form').serialize());
					}.bind(this)
				);
			}
			else{
				$('filter_lat').value='';$('filter_lon').value='';
				SWFAddress.setValue($('filter_form').serialize());
			}
		},
		/**
		 * Uses this.zipRegex to test val to see if it's a valid zipcode
		 * @function
		 * @param {String} val a possible zipcode value
		 * @returns {boolean} true if val is a zipcode
		 */
		isZipCode:function(val){
  			return (this.zipRegex.test(val));
		}
	}
}
/**
 * Object namespace for Physician Profile related actions and data
 * @namespace
 */
var PhysicianProfile = {
	init:function(){
		this.tabs.init();
	},
	tabs: {
		init:function(){
			this.currentIndex=0;
			$('profile_tab_links').select('ul li').each(function(element,i){
				if(i==0){element.addClassName('selected');}
				element.addClassName('tab_nav').observe('click',function(event){Event.stop(event);PhysicianProfile.tabs.setSelectedTab(Event.element(event).up('li'),i)});
			});
			this.profileDiv=$('physician_profile');
			this.tabContentDivs=$('physician_profile').childElements();
			this.tabContentDivs.each(function(element,i){if(i!=0){element.hide();}});
			//this.tabContentDivs=$('physician_profile').childElements[0].show();
		},
		setSelectedTab:function(element,index){
			element.siblings().invoke('removeClassName','selected');
			element.addClassName('selected');
			Effect.Fade(this.tabContentDivs[this.currentIndex], { duration: .2,afterFinish:function(){PhysicianProfile.tabs.showSelectedTab(index)} });
			this.profileDiv.setStyle({height:this.tabContentDivs[index].getHeight()+'px'});
		},
		showSelectedTab:function(index)
		{	
			Effect.Appear(this.tabContentDivs[index], { duration: .2 });
			this.currentIndex=index;
		}
	}
};

/**
 * fires when Find a Physician's filter search form is submitted by click
 * @name physicianEvent:filterFormSubmit
 * @event
 */

/**
 * fires when Find a Physician's main search form is submitted by click
 * @name physicianEvent:mainFormSubmit
 * @event
 */
