$(document).ready(
	function() {
	
		//
		// BEGIN configuring superfish menu
		$("#nav").superfish({
			hoverClass: 'sfhover',			// the class applied to hovered list items
			pathClass: 'overideThisToUse',	// the class you have applied to list items that lead to the current page
			pathLevels: 1,					// the number of levels of submenus that remain open or are restored using pathClass
			delay: 0,						// the delay in milliseconds that the mouse can remain outside a submenu without it closing 
			animation: {opacity:'show'},	// an object equivalent to first parameter of jQuery's .animate() method
			speed: 'fast',					// speed of the animation. Equivalent to second parameter of jQuery's .animate() method 
			autoArrows:	false,				// if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance
			dropShadows: false				// disable drop shadows
		});
		// END configuring superfish menu
		//
		
		//
		// BEGIN dressing up search fields
		// alert($("#keywords").attr("class"));
		
		if ($("#keywords").attr("class") == "blog") {
			var search_text = "Search the blog archives...";
		} else if ($("#keywords").attr("class") == "calendar") {
			var search_text = "Search for an event...";
		} else if ($("#keywords").attr("class") == "news") {
			var search_text = "Search the news archives...";
		} else if ($("#keywords").attr("class") == "business") {
			var search_text = "Search the Business Directory...";
		} else if ($("#keywords").attr("class") == "living") {
			var search_text = "Search for a property...";
		} else if ($("#keywords").attr("class") == "space") {
			var search_text = "Search for a property...";
		}
		
		$("#keywords").attr("value", search_text);
				
		if ($("#keywords").attr("value") == null) {
			$("#keywords").attr("value", search_text);
		}
		
		$("#keywords").focus(function() {
			if ($("#keywords").attr("value") == search_text) {
				$("#keywords").attr("value", "");
			}
		});
		
		$("#keywords").blur(function() {
			if ($("#keywords").attr("value") == null || $("#keywords").attr("value") == "") {
				$("#keywords").attr("value", search_text);
			}
		});
		// END dressing up search fields
		//
			
		//
		// BEGIN alert if search form is submitted without any keywords
		$("#search-archives").submit(
			function() {
				if ($("#keywords").attr("value") == "" || $("#keywords").attr("value") == "Enter some search terms...") {
					alert("Enter some search terms first.");
					return false;
				}
				
			}
		);
		// END alert if search form is submitted without any keywords
		//
		
		//
		// BEGIN handling "prev/next month" links for calendar
		calendar_nav_links();
		// END handling "prev/next month" links for calendar
		//
		
		//
		// BEGIN adding misc. HTML
		$("#primary").append('<div id="ul" class="primary-corner"></div><div id="ur" class="primary-corner"></div><div id="ll" class="primary-corner"></div><div id="lr" class="primary-corner"></div>');
		$("#columns").append('<div class="clear"></div>');
		// END adding misc. HTML
		//

		//
		// BEGIN lightbox gallery
		$('ul.gallery a.lightbox').lightBox({
			imageLoading: '/themes/site_themes/2009/shared/images/lightbox/loading.gif',
			imageBtnClose: '/themes/site_themes/2009/shared/images/lightbox/close.gif',
			imageBtnNext: '/themes/site_themes/2009/shared/images/lightbox/next.gif',
			imageBtnPrev: '/themes/site_themes/2009/shared/images/lightbox/prev.gif'
		});
		// BEGIN lightbox gallery
		//
		
		$("#business-categories").treeview({
			animated: "fast",
			collapsed: true,
			persist: "location",
			unique: true
		});
		
		// BEGIN opening external resource URLs in new window
		$("a[href^='http:']:not([href*='" + window.location.host + "'][target='_blank'])").live('click', function(){
			$(this).attr('target','_blank');
		});
		// END opening external resource URLs in new window
		
		//
		// BEGIN handling gift card form fields
		var gift_card_qty_init = 0;
		
		$('select.gift_card_qty').each(function() {
			gift_card_qty_init += parseFloat($(this).val());
		});
		
		if (gift_card_qty_init < 4) {
			$('#shipping_options_list').prepend('<li class="shipping_first_class"><label><input name="shipping_option" type="radio" value="USPS First Class (1-5 Days)" />USPS First Class (1-5 Days) - $1.50</label></li>');
		}

		$('select.gift_card_qty').change(function() {
			var gift_card_qty = 0;
			$('select.gift_card_qty').each(function() {
				gift_card_qty += parseFloat($(this).val());
			});
			if (gift_card_qty > 4) {
				$('#shipping_options_list li.shipping_first_class').remove();
			} else {
				if ($('#shipping_options_list li.shipping_first_class').length == 0) {
					$('#shipping_options_list').prepend('<li class="shipping_first_class"><label><input name="shipping_option" type="radio" value="USPS First Class (1-5 Days)" />USPS First Class (1-5 Days) - $1.50</label></li>');
				}
			}
		});
		// END handling gift card form fields
		//
	}
);

calendar_nav_links = function() {

	$('#prev-month a').click(
		function() {
			$('#calendar-nav').load(this.href, calendar_nav_links);
			return false;
		}
	);

	$('#next-month a').click(
		function() {
			$('#calendar-nav').load(this.href, calendar_nav_links);
			return false;
		}
	);
	
};
