// JavaScript Document
function getFileName() {
	//this gets the full url
	var url = document.location.href;
	
	//this removes the anchor at the end, if there is one
	url = url.substring(0, (url.indexOf("#") == -1) ? url.length : url.indexOf("#"));
	
	//this removes the query after the file name, if there is one
	url = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));
	
	//this removes everything before the last slash in the path
	url = url.substring(url.lastIndexOf("/") + 1, url.length);
	return url;
}
function openForm(form) {
	$("aside form h3").addClass("opened");
	$("aside form")
	.animate({
		left: "-=213"
	}, 250);
}
$(document).ready(function() {
	/* Create Flash Objects using jQuery SWFObject: */
	
	// Gallery
	$("#gallery").flash({
		swf: "assets/flash/gallery.swf",
		width: 500,
		height: 450,
		wmode: "transparent"
	});
	// Banner
	$("header .banner").flash({
		swf: "assets/flash/banner.swf",
		width: 851,
		height: 185,
		wmode: "transparent"
	});
	
	/* Dropdowns */
	$("li")
		.mouseover(function() {
			$(this).children(".dropdown ul").show()
			.parents("li")
			.addClass("hover"); /* Adds class to LI so that you can keep the "hover state" when you're on the dropdowns */
		})
		.mouseout(function() {
			$(this).children(".dropdown ul").hide()
			.parents("li")
			.removeClass("hover");
		});
	// Animation
	$(".dropdown ul li a").hover(function () {
		$(this).stop(true).animate({ paddingLeft: "40px" }, 100, "easeOutBack");
	}, function () {
		$(this).stop(true).animate({ paddingLeft: "19px" }, 100, "easeOutBounce");
	});
	
	/* Form Placeholder Texts */
	H5F.listen(window,"load",function () {
		if ($("#aside-form").length != 0 && $("#survey").length != 0) {
			H5F.setup([document.getElementById("aside-form"),document.getElementById("survey")]);
		} else {
			H5F.setup(document.getElementById("aside-form"));
		}
	},false);
	
	/* Sliding Aside Form */
	
	// First Add "Slot" groove to the right
	$("aside form").after('<span id="form-slot"></span>');
	
	// Toggle Form when H3 is clicked
	$("aside form h3")
		.click(function() {
			if ($(this).hasClass("opened")) {
				$("aside form")
				.animate({
					left: "+=213"
				}, 250);
				$("aside form h3").removeClass("opened");
			} else {
				$(this).addClass("opened");
				$("aside form")
				.animate({
					left: "-=213"
				}, 250);
			}
		});

	//Get page URL, if it's "Contact Us," open the Contact Form
	var pageURL = getFileName();
	if (pageURL == "contact-us.html") {
		openForm("aside form");
	}
});
