jQuery(document).ready(function() {

	// Fix missing PNG-transparency for IE 5.5 & 6
	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {
		jQuery.getScript("/js/lib/jquery.pngFix.js", function() {
			try {
				jQuery(document).pngFix({ blankgif:'/images/blank.gif' });
			} catch(e) {
				alert('An error has occurred: ' + e);
			}
		});
	}
	
	// Attach Google Analytics event tracking to document downloads, external links, etc.
	jQuery('a').each(function(index, a) {
		var href = a.href;
		if (/^\/documents/i.test(href)) {
			jQuery(this).click(function() {
				_gaq.push(['_trackEvent', 'Download', href]);
			});
		} else if (/\/external\//i.test(href) 
				|| (/^https?\:/i.test(href) && !new RegExp(location.hostname, "i").test(href))) {
			jQuery(this).click(function() {
				_gaq.push(['_trackEvent', 'External Link', href]);
			});
		} else if (/^mailto\:/i.test(href)) {
			jQuery(this).click(function() {
				_gaq.push(['_trackEvent', 'Email', href]);
			});
		}
	});
	
	// Attach Google Analytics event tracking to form submissions
	jQuery('form').each(function(index, form) {
		jQuery(form).submit(function(event) {
			_gaq.push(['_linkByPost', form]);
		});
	});

	// Highlight the current section in the navigation bar
	if (typeof(navHolderObjectId) !== "undefined" && typeof(currentSectionPath) !== "undefined"
			&& jQuery(navHolderObjectId + ' a[href^="' + currentSectionPath + '"]').length) {
		jQuery(navHolderObjectId + ' a[href^="' + currentSectionPath + '"]').attr('class', 'selected');
	}

	//Inserts Sharing Tool into an HTML Element
	if(typeof(addthisObjectId) !== "undefined" && jQuery(addthisObjectId).length) {
		jQuery(addthisObjectId).append(
			'<div class="addthis_toolbox addthis_default_style "><a href="http://www.addthis.com/bookmark.php?v=250&amp;pubid=wgswi" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span>'+
			'<a class="addthis_button_facebook"></a>'+
			'<a class="addthis_button_linkedin"></a>'+
			'<a class="addthis_button_twitter"></a>'+
			'<a class="addthis_button_google"></a></div>');
		jQuery.getScript("http://s7.addthis.com/js/250/addthis_widget.js#async=1", function() {
			window.addthis_config = {
				ui_use_css: false,
				username: "wgswi",
				data_ga_property: 'UA-12336570-3',
				data_track_clickback: true
			};
			addthis.init();
		});
	}
	
	// Academy Course expand/collapse
	if(jQuery('.expandedSchedule').length) {
		
		var obj = jQuery('.expandedSchedule');
		var button = '<a href="#" id="scheduleToggle">' + scheduleToggleClosedText + '</a>';

		obj.hide().parent().parent().append(button);
		
		jQuery('#scheduleToggle').toggle(function() {
			jQuery(this).text(scheduleToggleOpenedText);
			obj.show();
			return false;
		}, function() {
			jQuery(this).text(scheduleToggleClosedText);
			obj.hide();
			return false;
		});
	}

	$('#accordion h3').click(function()
	{
		$.fn.toggleContent(this);
	});
	
	$('#archivedEventsLink').click(function()
	{
		$.fn.openContent($("#archivedOccurrencesHeader"));
		
	});
	
	$('#upcomingEventsLink').click(function()
	{
		$.fn.openContent($("#upcomingOccurancesHeader"));
	});
	
	
	
	$.fn.toggleContent = function(activeH3)
	{
		if($(activeH3).hasClass("ui-state-active"))
		{
			$.fn.closeContent(activeH3);
		}
		else
		{
			$.fn.openContent(activeH3);
		}
	};
	
	$.fn.openContent = function(parentH3)
	{		
		if(!$(parentH3).hasClass("ui-state-active"))
		{
			$(parentH3).addClass("ui-state-active");
			$contentHolder = $(parentH3).next();
			$contentHolder.show("slow");
		}
	};
	
	$.fn.closeContent = function(parentH3)
	{		
		$(parentH3).removeClass("ui-state-active");
		$contentHolder = $(parentH3).next();
		$contentHolder.hide("slow");
	};

	if (jQuery("#slideshow").length) {
		jQuery("ul#slides").cycle({
			fx: 'fade',
			pause: 1
		});
	}
	
	//Plugs in default text to the search field
	$searchBox = jQuery("form#searchForm input");
	$altTagValue = $searchBox.attr("alt");
	$searchBox.attr("value", $altTagValue);
	$searchBox.focus(function(){  
	    if($(this).attr("value") == $altTagValue) $(this).attr("value", "");  
	});  
	$searchBox.blur(function(){  
	    if($(this).attr("value") == "") $(this).attr("value", $altTagValue);  
	});  


});

