function regionSelectionHighlighting() {
	$('#advancedSearch-q').blur();	//blur search input
	//changing selected region links
	$('#searchRegionLinks a').addClass("blue-link").show();//.removeClass("hide"); //make all links blue + visible
	$('#searchRegionLinks span').hide(); //hide all plain text descriptions
	
	var searchAction = $('#search > form').attr("action"); //find current search action
	var region = searchAction.split("/")[1]; //get the region
	
	if(region == "search") region = "all"; //if the region is search then it should be all
	
	$('#'+region).hide(); //hide the selected region link
	$('#'+region).siblings().show(); //show the plain text region
	$('#'+region).siblings().children().show(); //show the plain text region selected text
}

function doSearch() {
	$('#search-q').val($('#advancedSearch-q').val()); //set search q to the adv search q 
	$('#search > form').submit(); //submit standard search
}

$().ready(function() {
	var theSearch = "/search/search.php"; //setting the search path

	$('#advancedSearchDialog').jqm({modal: true}); //setup for the adv search dialog
	$('#advancedSearchLink').show(); //display the adv search link if JS is enabled

	$('#advancedSearchLink').click(regionSelectionHighlighting); //upon click on dialog open
	
	$('#searchRegionLinks a').click( function() {
	
		//adjusting the search form action according to user selection
		var region = $(this).attr("id");

		if(region == "all") $('#search > form').attr("action",theSearch);
		else $('#search > form').attr("action","/"+region+theSearch);

		regionSelectionHighlighting();
	});

	//allow enter key to also submit adv search
	$("#advancedSearch-q").keyup(function(e) {
		if(e.keyCode == 13) {
			doSearch();
		}
	}); 

	//clicked adv search button
	$('#advancedSearch-submit').click( function() {
		doSearch();
	});

});