(function($){
    $.fn.extend({
      searchtabslide: function(options) {
		
		// START : LOOP THROUGH MATCHING ELEMENTS
		return this.each(function() {

			//Listen for clicks on objects passed to the plugin
			$(this).click(function(e, options) {			  
				
				// 1. if someone clicks the close button within a searchpanel
				if(getHrefAttribute(this) == 'jq_searchcontent_close')
				{
					// alert(getHrefAttribute(this));
					// alert($("body").find('a.search_tab_on'));
					$("body").find('a.search_tab_on').removeClass("search_tab_on").addClass("search_tab");
					$("body").find('div.search_tab_content:visible').animate({height: 'toggle', opacity: 'toggle'}, "slow");
					return false;				
				}
				
				// 2.
				// hide all open panels that are not connected to the clicked link
				$("body").find('div.search_tab_content').not('div#' + getHrefAttribute(this)).hide();
				
				// toggle selected panel 
				$("body").find('div#' + getHrefAttribute(this)).animate({height: 'toggle', opacity: 'toggle'}, "slow");
				
				// hide all tabs that are active EXCEPT the clicked tab
				$("body").find('a.search_tab_on').not('div#' + getHrefAttribute(this)).removeClass("search_tab_on").addClass("search_tab");	
				
				// the clicked tab you need to check if it is active then deactivate, or if inactive activate							
				if($(this).attr("class") == 'search_tab_on')
				{
					$(this).removeClass("search_tab_on");
					$(this).addClass("search_tab");
				}
				else
				{
					$(this).removeClass("search_tab");
					$(this).addClass("search_tab_on");
				}

				return false;
			});
		// END : LOOP THROUGH MATCHING ELEMENTS
		});
		
		// Recycle code by placement of codeblock in seperate function
		function getHrefAttribute(e){
			return e.getAttribute("href").replace("#", "");
		}
		
      }
  });
})(jQuery);

