$(document).ready(function() {
	
	//initialize $_GET variable
	var $_GET = {};
	document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
		function decode(s) {
			return decodeURIComponent(s.split("+").join(" "));
		}

		$_GET[decode(arguments[1])] = decode(arguments[2]);
	});
	
	// declare rounded corners
	$('.rounded_gray').corner();
	$('.rounded').corner();
	$('#content_inside_left').corner();
	
	if(!$.browser.msie){
		$('div#img_slider_fade').corner();
	}
	
	// Image Hover Swap
	$('img.hover').hover(function(){
		orig_image = $(this).attr('src');
		new_image = orig_image.replace('.png', '_s.png');
		$(this).attr('src', new_image);
	},function() {
		orig_image = $(this).attr('src');
		new_image = orig_image.replace('_s.png', '.png');
		$(this).attr('src', new_image);
	});

	
	// The bottom of the iframe on the home page for the google map gets corners in ie but not firefox. This hides the manual image for rounded
	// corners in IE but lets it through in FF/etc. Haven't tested chrome/opera/safari yet
	if($.browser.msie) {
		$('.ie_hide').hide();
	}
	
	// basic image hover swap
	$(".imgover").hover(
		function()
		{
			this.src = this.src.replace(".jpg","_s.jpg");
		},
		function()
		{
			this.src = this.src.replace("_s.jpg",".jpg");
		}
	);
	
	// Accordion - i.e. Gift Card page FAQ
	
	if($("#accordion").length > 0) {
		
		$('.accordion_question a').click(function(){
			
			var answer_div = $(this).parent().next();
			answer_div.stop(true, true);
			answer_div.slideToggle('slow','linear');
			return false;
		
		});
	}

	// Tabs
	if($("#tabs").length > 0) {
		var $tabs = $("#tabs").tabs();

		if($_GET["tab"]) {
			active_tab = "#" + $_GET["tab"];
			$tabs.tabs('select', active_tab);
		}
	}
	
	// Data Tables Init
	if($("#directory_table").length > 0) {
		
		$("#directory_table").dataTable({
			"bPaginate": false,
			"bLengthChange": false,
			"bFilter": true,
			"bSort": true,
			"bInfo": false,
			"bAutoWidth": true,
			"aoColumns"	: [
				null,
				null,
				{ "bSortable": false },
				null
			],
			"oLanguage": {
				"sZeroRecords": "Sorry, no results match your search.",
				"sSearch": ""
			}
		});
		
		// if there's a "q" get var use it to populate the input box
		// otherwise put in some default text
		if($_GET["q"]) {
			var filter_query = $_GET["q"];
			$("#directory_table_filter input").focus().val(filter_query);
			$("#directory_table_filter input").trigger('keyup');
		}
		else {
			var default_filter_text = "START TYPING KEYWORDS HERE";
			$("#directory_table_filter input").val(default_filter_text);
			$("#directory_table_filter input").click(function() {
				if($(this).val() == default_filter_text) {
					$(this).val("");
				}
			});
		}
		
		// add small div to right of search box explaining column sort
		
		var column_sort_copy = "<div id='dir_showall'>";
		column_sort_copy += "<p>SHOW ALL</p>";
		column_sort_copy += "</div>";
		
		$("#directory_table_filter").before(column_sort_copy);
		
		/*
		$("#directory_table tbody tr td:first-child").css({
			"font-family": "TeXGyreAdventorBold"
		});
		*/
		
		// Hide single versions of multi category directory items, then show and hide multi versions if category is selected as sort
		$(".multi_cat_single").hide();
		
		
		// click on non cat header makes sure multi_cat is shown and singles are hidden
		$("#directory_table th").click(function() {
			if($(this).attr("id") == "category_header") {
			
			} 
			else {
				$(".multi_cat_single").hide();
				$(".multi_cat").show();
			}
		});
		
		// click on cat header hides multi_cat and shows singles
		$("#category_header").click(function() {
			$(".multi_cat_single").show();
			$(".multi_cat").hide();
		});
		
		// colorbox map links
		$(".colorbox_map").colorbox({
			opacity: 0.5
		});
	
	}
	
	// Colorbox Links
	$(".colorbox_link").colorbox({
		opacity: 0.5
	});

	// Fix for large google map on info/map page in ie8
	if($('#map_driving_directions').length > 0) {
		
	}
	
	// Homepage Image Cycle (Attractions)
	$('#img_slider').cycle('scrollLeft');
	
	// Homepage Slider
	

		$('#img_slider_fade').nivoSlider({
			directionNav: false, // Next & Prev navigation
			manualAdvance: false,
			captionOpacity: 1,
			effect: 'fade',
			pauseTime: 5000
		});

	
	//$('#img_slider_fade').cycle('fade');
	$('.nivo-controlNav a').html("&nbsp;");
		
	// Form input behavior
	
	$('input[type=text]').focus(function() {
		$(this).css('backgroundColor', '#DEDEDE');
		$(this).css('borderColor', '#DEDEDE');
	});
	$('input[type=text]').blur(function() {
		$(this).css('backgroundColor', '#CCC');
		$(this).css('borderColor', '#CCC');
	});
	
	$('.rounded_gray input[type=text]').focus(function() {
		$(this).css('backgroundColor', '#999');
	});
	$('.rounded_gray input[type=text]').blur(function() {
		$(this).css('backgroundColor', '#333');
	});
	
	$('textarea').focus(function() {
		$(this).css('backgroundColor', '#DEDEDE');
		$(this).css('borderColor', '#DEDEDE');
	});
	$('textarea').blur(function() {
		$(this).css('backgroundColor', '#CCC');
		$(this).css('borderColor', '#CCC');
	});
	
	//SHOW ALL button behavior
	$('div#dir_showall').click(function(){
		$("#directory_table_filter input").focus().val('');
		$("#directory_table_filter input").trigger('keyup');
	});
	
	//APS 11-7-2011 - colorbox for holiday hours
	$(".holiday_image").colorbox({
		rel: 'holiday_image',
		innerWidth: 575,
		innerHeight: 730,
		transition: 'none'
	});
	
	//APS 12-16-2011 - colorbox for video
	$("a.video_popup").colorbox({
		html:"<div id='i_78079567' style='width: 576px; height: 324px;'></div><script type='text/javascript' src='http://services.fliqz.com/smart/20100401/applications/5fe4564d61f54b389916c5f5d2a1c6d1/assets/b5a6f1b1544d409f8492d4a1e35f0675/containers/i_78079567/smarttag.js?width=100%25&amp;height=100%25'></script>",
		innerWidth: 574,
		innerHeight: 322,
		transition: 'none',
		scrolling: false
	});
	
});
