$(document).ready(function() {
	/* Create Flash Objects using jQuery SWFObject: */

	// Gallery
	$("#gallery").flash({
		swf: "assets/flash/gallery.swf",
		width: 585,
		height: 450,
		wmode: "transparent"
	});
	// In the News Video
	$("#in-the-news").flash({
		swf: "assets/flash/dr-goldstein-in-the-news.swf",
		width: 550,
		height: 400,
		wmode: "transparent"
	});

	/* Office Slideshow */
	StartSlideShow();

	/* Make the Logo link to the Home page */
	$("header .logo").click(function() {
		window.location = "index.html";
	});

	/* If Blockquote/Callout has a link, go to the page if you click ANYWHERE on the Blockquote/Callout */
	$("blockquote.link, .callout").click(function(){
		window.location=$(this).find("a").attr("href");
	});

	/* Initialize Report Form "Carousel" */
	$("aside #report").infiniteCarousel();

	/* Scrolling Animation */
	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
	});

	/* If you click the Report Button, Bring attention to the Report Form via an icon */
	$('a[href="#report"]').click(function () {
		$("#report .alert").remove();
		$("#report").append('<img src="assets/images/alert.png" class="alert" width="38" height="32" />');
		$(".alert").delay(1000).animate({
			opacity: 1,
			left: "-18px"
		}, function () {
			$(this).animate({
				left: "-23px"
			}, 250, function () {
				$(this).animate({
					left: "-18px"
				}, 500);
			});
		});
	});

	/* Remove Icon once user focuses on Report Form field */
	$("#free-report input").focus(function () {
		$(".alert").animate({
			left: "-28px",
			opacity: 0
		}, function () {
			$(this).remove();
		});
	});
});
$(window).load(function () {
	/* Adjust the padding on the Nav to extend all the way across */
	$("body > nav > ul").each(function () {
		var navWidth = $(this).width(),
		    difference = Math.floor((980 - navWidth)/2),
		    newPadding = 19 + difference;
		$(this).find(" > li:last-child a").css({ padding: "8px "+newPadding+"px" });
	});
});
