// ShinyAnt Global jQuery Functions - JavaScript Document
$(document).ready(function(){
	
	//Get the last LI in the Navigation List and assign a class of 'last'
	$('body#blog #content h2:first').addClass('mrg-top-none');
	$('#navigation li:last').addClass('last');
	$('#content table.bdr-bottom-none tr:last').addClass('last');

	//Show-Hide Script for all Arrows that upon click will reveal a Hidden Div and Point Downwards
	if ($('a.show-contact').length > 0){
		// hide divs
		$('div.more-contact').hide();
		// slide effect
		$('a.show-contact').click(function(){
			$('div.more-contact').slideToggle('fast');
				if($(this).hasClass('showing')){
						$(this).removeClass('showing');
					}
					else {
						$(this).addClass('showing');
					}		
			return false;
		});
	}
	
	//Show-Hide Script for all Browsing Modules
	if ($('a.collapse').length > 0){
		// hide divs
		$('div.hidden').hide();
		//show-hide
		$('a.collapse').click(function(){
			$(this).parent().next('div').slideToggle('fast');
				if($(this).hasClass('activated')){
						$(this).removeClass('activated');
					}
					else {
						$(this).addClass('activated');
					}		
			return false;
		});
	}

	//Show-Hide Script for Showing Expandable Information on Practitioner Profile
	if ($('a.expand').length > 0){
		// hide divs
		$('div.collapsed').hide();
		// slide effect
		$('a.expand').click(function(){
			$(this).parent().next('div').slideToggle('fast');
				if($(this).hasClass('active')){
					$(this).removeClass('active');
				}
				else {
					$(this).addClass('active');
				}		
			return false;
		});
	}
	//Exception for Affiliated Organizations and Institutions
		$('a.expanded').click(function(){
			$(this).parent().next('div').slideToggle('fast');
				if($(this).hasClass('collapsed')){
					$(this).removeClass('collapsed');
				}
				else {
					$(this).addClass('collapsed');
				}		
			return false;
		});
	
	//Show-Hide Script for Showing Editable Profile Fields in the Admin
	if ($('a.edit-section').length > 0){
		// hide divs
		$('tbody.edit-section-hidden').hide();
		// slide effect
		$('a.edit-section').click(function(){
			$(this).parent().parent().parent().next('tbody').slideToggle('fast');
				if($(this).hasClass('active')){
					$(this).removeClass('active');
				}
				else {
					$(this).addClass('active');
				}		
			return false;
		});
	}

	//Slide in the Report Module when the Side Function Report link is clicked
	if ($('a.report').length > 0){
		// hide those divs
		$('div.report-module').hide();
		// slide effect
		$('a.report').click(function(){
			$('div.report-module').slideDown('fast');
			return false;
		});
	}
	//Hide the Report when Hide is Clicked
		if ($('a.hide-report').length > 0){
		$('a.hide-report').click(function(){
			$('div.report-module').slideUp('fast');
			return false;
		});
	}
	
	//Hide the Reminder when Hide is Clicked
		if ($('a.hide-reminder').length > 0){
		$('a.hide-reminder').click(function(){
			$('div.reminder-module').slideUp('fast');
			return false;
		});
	}

	//Show-Hide Script for Showing Expandable Information on Practitioner Profile
	if ($('a.add-suffix').length > 0){
		// hide divs
		$('span.hidden-suffix').hide();
		// slide effect
		$('a.add-suffix').click(function(){
			$(this).next('span').slideDown('fast');
			$(this).slideUp('fast');
		return false;
		});
	}

	//Show-Hide Hidden Toggle
	if ($('a.showhide').length > 0){
		// hide those divs
		$('div.hidden').hide();
		// slide effect
		$('a.showhide').click(function(){
			$('div.hidden').slideToggle('fast');
			return false;
		});
	}

	//Show a "Page Updated Div that Fades In When Changes Are Saved
	if ($('input.show-updated, a.show-updated').length > 0){
		// hide those divs
		$('span.updated-message').hide();
		// slide effect
		$('input.show-updated, a.show-updated').click(function(){
			$('span.updated-message').fadeIn('2000');
			return false;
		});
	}
	
	//Show a "Page Updated Div that Fades In When Changes Are Saved
	if ($('a.flag-review').length > 0){
		// hide those divs
		$('span.review-flagged').hide();
		// slide effect
		$('a.flag-review').click(function(){
			$('span.review-flag').slideUp('fast');
			$('span.review-flagged').slideDown('fast');
			return false;
		});
	}
	
	//Show an "Error Message that Fades In When a Button with a class of "show-error" is clicked
	if ($('input.show-error').length > 0){
		// hide those divs
		$('div.page-error').hide();
		// slide effect
		$('input.show-error').click(function(){
			$('div.page-error').fadeIn('2000');
			return false;
		});
	}

	//Show a "Page Updated Div that Fades In When Changes a New Page Loads
		$('div.alert-message, span.auto-notify').hide();
		$('div.alert-message, span.auto-notify').fadeIn('3000');


	$('p.review-filters a').click(function(){
			$('p.review-filters a').removeClass('current');
			$(this).addClass('current');
			return false;
	});
	
	//Hide an Alert when the Hide Alert Link is Clicked On
	$('a.hide-alert').click(function(){
			$('div.alerts').slideUp('fast');
			return false;
	});
	
	//Show the Respond to a Review Form when link is clicked
	if ($('a.respond').length > 0){
		// hide divs
		$('div.user-review-respond').hide();
		//show-hide
		$('a.respond').click(function(){
			$(this).parent().parent().next('div').slideDown('fast');
			return false;
		});
	}

	//Show-Hide Script for Showing a Time Range for Cost if the Treatment is a Medicine, Herb or Nutraceutical
	if ($('#treatment-visit').length > 0){
		// hide div with a class of hidden
		$('span.cost-timeframe').hide();
		// slide effect
		$('#treatment-medicine, #treatment-herb, #treatment-nutraceutical').click(function(){
			$('span.cost-timeframe').fadeIn('fast');
			});
		$('#treatment-select, #treatment-visit').click(function(){
			$('span.cost-timeframe').fadeOut('fast');
			});
		}

	//Edit flyout button
	if ($('a.edit-row').length > 0){
		// hide that button
		$('a.edit-row').hide();
		// show it when hovering over the table row
		$('a.edit-row').parent().parent('td').hover(function(){
			$(this).find('.editable a.edit-row').show();
			},
			function(){
			$(this).find('.editable a.edit-row').hide();
			});
	}
	
	$("td").hover(
  		function () {
		    $(this).addClass("hover");
		  },
		  function () {
		    $(this).removeClass("hover");
		  }
	);

	//Script for Livesearch (Autocomplete) from jQuery UI Library 1.8
	$(function() {
		var availableTags = ["Brigham and Womens' Hospital", "Beth Israel Deaconness Medical Center", "Boston Medical Center", "Jamaica Plain Health Center", "Aveeno Spa", "Jill's Spa", "Example Clinic", "Dr. Jeffreys Skin Care", "Hospital Name"];
		$("#livesearch").autocomplete({
			source: availableTags
		});
	});
	
//Script for Livesearch (Autocomplete) from jQuery UI Library 1.8
	$(function() {
		var availableTags = ["Anxiety", "Depression", "Skin Problems", "Stress", "Neck Pain", "Back Pain", "Insomnia", "Restless Leg Syndrome"];
		$("#condition-names").autocomplete({
			source: availableTags
		});
	});

	//Any link with a class of .email formed like greg(at)shinyant.com with the same text will become a Mailto: link
	$('.email').mailto();
	
	//Dynamically clears out any text in the input fields
	if ($('.focus-blur').length > 0){
			//$.getScript('/jillslist.com/trunk/theme/jillslist/js/jquery.valueFx.js',function(){ 
				// Execute this function once the plugin is loaded
				$('.focus-blur').valueFx();
		//});
	}
	
});
