jQuery.noConflict();
jQuery(function($){
	
	var frontend = 
	{
		init:function()
		{
			this.fIClick();
			this.formMagic();
			this.IE6();
			this.bannerSlide();
			this.showMonths();
			this.blank();
		},
		
		fIClick:function()
		{
			if($("#FeaturedItems").length)
			{
				$("#FeaturedItems > div").hover(function()
				{
					$(this).css("cursor", "pointer");
				}).click(function()
				{
					var target = $(this).find("h3 a").attr("href");
					window.location = target;
				});
			}
		},
		
		formMagic:function()
		{
			$('div.text label').each(function()
			{
				if($(this).text().toLowerCase() == "other") $(this).parent().hide();	
			});
			
			$("ul.optionset").each(function()
			{
				$(this).find("input.radio").click(function()
				{
					if($(this).attr("value").toLowerCase() == "other" && $(this).get(0).checked)
					{
						$(this).parents("div.optionset").next().show();
					}
					else
					{
						$(this).parents("div.optionset").next().hide();
					}
				});
			});
			
			$("select").each(function()
			{
				$(this).change(function(){
					if($(this).children("option:selected").eq(0).attr("value").toLowerCase() == "other")
					{
						$(this).parents("div.dropdown").next().show();
					}
					else
					{
						$(this).parents("div.dropdown").next().hide();
					}
				})
			});
		},
		
		IE6:function()
		{
			$("ul#Main li")
				.hover(
					function(e){$(this).addClass("hover");},
					function(e){$(this).removeClass("hover");});
		},
		
		bannerSlide: function()
		{
			if ($('#BannerImages').length > 0) {
				var timeout = $('#BannerImages').attr("class").split(" ");
				timeout = timeout[0].split("-");
                timeout = timeout[1];
				if(isNaN(timeout)) timeout = 3000
				$('#BannerImages').cycle({
					pause: 1,
					speed: 800,
					timeout:timeout
				});
			}
		},
		
		showMonths:function()
		{
			if ($('#NewsArchive').length) {
				$("#NewsArchive ol ol").hide();
				this.showSection();
				$("#NewsArchive h3").wrapInner('<a href="#"></a>').css("cursor", "pointer").click(function(){
					$(this).next().slideToggle("normal");
					$(this).parent().toggleClass("section");
					$(this).parent().siblings().removeClass("section");
					$(this).parent().siblings().children("ol").slideUp("normal");
					return false;
				});
			}
		},
		
		showSection:function()
		{
			$("#NewsArchive ol ol a").each(function()
			{
				if (this.href == window.location.href) 
				{
					$(this).parent().parent().show();
				}
			})
		},
		
		blank:function()
		{
			$('.google-map a').attr('target', '_blank');
		}
		
	}
	frontend.init();
});