// JavaScript Document
var menuOn = false;
var onMenu = false;
var slideshowTimer;
var animating = false;
var loadingTimer;
$lastClickedOnLink = null;

$(document).ready(function() {
	
	 /* ================== Option for fancybox ======================= */
	
	
	$("a.inline").not(".notpopup").fancybox({
		 'scrolling':'no',
		 'width':680,
		 'height':400,	
		 'padding': 5,
		 'overlayColor':'#000'
	});
	
	/* ================== Home Page Slideshow ======================= */
	
	//Set some active elements if one is not set already
	if($("#homeSlideshow .active").length == 0) {
		$("#homeSlideshow .slide").first().addClass("active");
		$("#slideSelection").find("a").removeClass("active");
		$("#slideSelection").find("a").first().addClass("active");
	}
	
	$("#slideSelection a").click(function() {
		if(!animating && !$(this).hasClass("active")) {
			animating = true;
			//Get the index of NEXT and PREV
			var nextIndex = $(this).parent().index();
			var prevIndex = $("#slideSelection").find("a.active").parent().index()
			//If NEXT is to the right of PREV, slide everything left
			if(nextIndex > prevIndex) 
				slideLeft(nextIndex, prevIndex);
			else if (nextIndex < prevIndex)
				slideRight(nextIndex, prevIndex);
				
			//Reset the timer
			clearTimeout(slideshowTimer);
		}				
		return false;
	});
	
	
	// this section stop the slide show if the video was click
	$("div.mejs-container").live("click", function(){
	   clearTimeout(slideshowTimer);
	});
		
	slideshowTimer = setTimeout('nextSlide();', 5000);
	
	
		
		
	/* ================== Pyramid section ======================= */
	
	$(".tab_content").hide();  // Hide all the content for each tab
	
	
	$("#lowerSection table td").each(function() {
		$(this).find("td:first").addClass("first");
	});
	
		
	$("#pursuantLogo li a").hover(function() {		
		$("#initialContent").hide();
		$("#pyramidContent").show();  // Show the bubble first
		$(".tab_content").stop().css("opacity", 1).hide(); // Hide the content that's not selected
		
		
		
		$("#pursuantLogo li a").removeClass("active");  // remove all active calss on tab
		$(this).addClass("active"); // adding active so the current tab is highlighted
		var activeTab = $(this).attr("rel"); //Find the href attribute value to identify the active tab + content						  
		$(activeTab).fadeTo(400, 1);  // show the content
		//$("#pContent").animate( { height: $(".wrapper").outerHeight() + "px" }, 400 ); //animate the bubble length
		
		//$("#pyramidContent").animate( { height: $(".wrapper").outerHeight() + "px" }, 400 ); //animate the bubble length
		onButton = true;
	},function () {
		onButton = false; // check to see if button is current on or not
		setTimeout("hideMenu()",3000);
   
	});
	
	
	
	$(".tab_content").hover(function() { 
			menuOn = true; // set menu to on
	},function () {
			menuOn = false; // set menu to off
			setTimeout("hideMenu()",3000); // hide the content
	});
	
	
	
	/* ================== Add class to first item in Naivation ================= */
	$(".nav ul li").first().addClass("first");
	
	$(".nav ul li:last-child").addClass("last");
	
	
	$("#footerContactForm").submit(function() {
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var validEmail = true;
		$("#footerContactForm input").removeClass("error");
		//Validate firstname
		if($("#footerfirstname").val() == "")
			$("#footerfirstname").addClass("error");
		if($("#footerlastname").val() == "")
			$("#footerlastname").addClass("error");
		if($("#footeremail").val() == "")
			$("#footeremail").addClass("error");
		else if(!emailReg.test($("#footeremail").val())) {
            $("#footeremail").addClass("error");
			validEmail = false;
        }
		if($("#footerorganization").val() == "")
			$("#footerorganization").addClass("error");
		if($("#footertitle").val() == "")
			$("#footertitle").addClass("error");
			
		if($("#footerContactForm input.error").length > 0) {
			if(!validEmail && $("#footerContactForm input.error").length == 1)
				alert("Please enter a valid email address");
			else
				alert("Some of the fields on the form are required. Please check the highlighted fields and ensure the proper information is filled in.");
		}
		else {
			$("#footerloadingText").text("Processing").css("display", "inline");
			loadingTimer = setInterval("LoadingAnimation()", 500);
			$.post("/wp-content/themes/pursuant2011/ajax/addUser.php", {firstname: $("#footerfirstname").val(), lastname: $("#footerlastname").val(),
				email: $("#footeremail").val(), phone: $("#footerphone").val(), organization: $("#footerorganization").val(), title: $("#footertitle").val(),
				subject: "New Signup - " + $("#postTitle").text()},
				function(data) {
					//Add an iframe to the page to start the session in Silverpop
					var userData = $.parseJSON(data);
					var url = document.URL;
					if(url.indexOf("?") > 0)
						url = url + "&spMailingID=2009440&spUserID="+userData['RecipientID']+"&spJobID=31824646&spReportId=MzE4MjQ2NDYS1";
					else 
						url = url + "?spMailingID=2009440&spUserID="+userData['RecipientID']+"&spJobID=31824646&spReportId=MzE4MjQ2NDYS1";
						
					$('<iframe />', {
						name: 'myFrame',
						frameborder: "0",
						src: url,
						scrolling: "no",
						width: "1",
						height: "1"
					}).appendTo('body');
					
					$(".resourceDownload").each(function() {
						$(this).attr("href", $(this).data("href"));
					});
					$(".resourceDownload").unbind('click.fb');
					$("a.inline").not(".notpopup").fancybox({
						 'scrolling':'no',
						 'width':680,
						 'height':400,	
						 'padding': 5,
						 'overlayColor':'#000'
					});
					recordResource($($lastClickedOnLink).attr("resource"));
					
					clearInterval(loadingTimer);
					$("#footerloadingText").css("display", "none");
					
					if(!$($lastClickedOnLink).hasClass("inline")) {
						$.fancybox.close();
						
						if($($lastClickedOnLink).hasClass("newsletterSignup")){
							window.location = "/gen-web/thank-you/";	
						}else{
							window.location = $($lastClickedOnLink).attr("href");	
						}
						
						

					}
					else			
						$($lastClickedOnLink).click();
			});
		}
		return false;
	});
	
	$("#contactUsForm").submit(function() {
		$(".submit").attr("disabled", "disabled");
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var validEmail = true;
		$("#contactContactForm input").removeClass("error");
		//Validate firstname
		if($("#contactFirstName").val() == "")
			$("#contactFirstName").addClass("error");
		if($("#contactLastName").val() == "")
			$("#contactLastName").addClass("error");
		if($("#contactEmail").val() == "")
			$("#contactEmail").addClass("error");
		else if(!emailReg.test($("#contactEmail").val())) {
            $("#contactEmail").addClass("error");
			validEmail = false;
        }
		if($("#contactOrganization").val() == "")
			$("#contactOrganization").addClass("error");
			
		if($("#contactTitle").val() == "")
			$("#contactTitle").addClass("error");
			
		if($("#contactContactForm input.error").length > 0) {
			if(!validEmail && $("#contactContactForm input.error").length == 1)
				alert("Please enter a valid email address");
			else
				alert("Some of the fields on the form are required. Please check the highlighted fields and ensure the proper information is filled in.");
			$(".submit").removeAttr("disabled");
		}
		else {
			$("#contactloadingText").text("Processing").css("display", "inline");
			loadingTimer = setInterval("LoadingAnimation()", 500);
			var comments = "I am interested in:";
			for(var i = 1; i <= 8; i++)
				if($("#resource" + i).is(':checked'))
					comments += "\n- " + $("#resource" + i).val();
			comments += "\n\nAdditional Comments: " + $("#contactComments").val();
			
			$.post("/wp-content/themes/pursuant2011/ajax/addUser.php", {firstname: $("#contactFirstName").val(), lastname: $("#contactLastName").val(),
				email: $("#contactEmail").val(), phone: $("#contactPhone").val(), organization: $("#contactOrganization").val(), publication: $("#contactPublication").val(), title: $("#contactTitle").val(),
				subject: $("#contactSubjectLine").val(), comments: comments,  vertical: $("#contactVertical").val(), ein: $("#contactEIN").val()},
				function(data) {
					//Add an iframe to the page to start the session in Silverpop
					var userData = $.parseJSON(data);
					//If there wasn't already a recipientID set
					if(document.cookie.indexOf('recipientID') == -1) {
						var url = document.URL;
						if(url.indexOf("?") > 0)
							url = url + "&spMailingID=2009440&spUserID="+userData['RecipientID']+"&spJobID=31824646&spReportId=MzE4MjQ2NDYS1";
						else 
							url = url + "?spMailingID=2009440&spUserID="+userData['RecipientID']+"&spJobID=31824646&spReportId=MzE4MjQ2NDYS1";
							
						$('<iframe />', {
							name: 'myFrame',
							frameborder: "0",
							src: url,
							scrolling: "no",
							width: "1",
							height: "1"
						}).appendTo('body');
					}
					clearInterval(loadingTimer);
					
					//$("#contactloadingText").text("Thank you for your feedback.  Someone will be in touch soon.");
					window.location = "http://www.pursuantgroup.com/success/"
			});
		}
		return false;
	});
	
	$("#searchform").submit(function(){
		if($(".searchBox").val() == "" || $(".searchBox").val() == "Search")
			return false;
	});
	
	$("#ourWorkForm select").change(function() {
		//I need to hide all of the solution options that don't have the same category id as the option I selected here
		if($(this).attr("id") == "challengeDropDown") {
			var val = $(this).val();
			$("#solutionDropDown > option").each(function() {
				if(val != "0" && this.value != "0" && this.value != val)
					$(this).hide();
				else
					$(this).show();
			});
		}
		//I need to hide all of the challenge options that don't have the same category id as the option I selected here
		else if($(this).attr("id") == "solutionDropDown") {
			var val = $(this).val();
			$("#challengeDropDown > option").each(function() {
				if(val != "0" && this.value != "0" && this.value != val)
					$(this).hide();
				else
					$(this).show();
			});
		}
		
		//Hide vertical options that we don't have available
		if($(this).attr("id") == "challengeDropDown" || $(this).attr("id") == "solutionDropDown") {
			if($("#challengeDropDown").val() == "0" && $("#solutionDropDown").val() == "0")
				$("#verticalDropDown > option").show();
				
			else
			//Make ajax call to find out what options are available in the database
			$.get("/ajax/", {"action" : "getVerticals", "selectedCats" : $(this).val()}, function(data) {
				var ids = $.parseJSON(data);
				//Hide all options in the vertical dropdown
				$("#verticalDropDown > option").each(function() {
					if($(this).val() != "0" && $.inArray($(this).val(), ids) == -1)
						$(this).hide();
					else
						$(this).show();
				});
			});
		}
		//Hide challenge/solution options
		else {
			if($("#verticalDropDown").val() == "0")  {
				if($("#challengeDropDown").val() == "0" && $("#solutionDropDown").val() == "0") {
					$("#challengeDropDown > option").show();
					$("#solutionDropDown > option").show();
				}
			}
			else {
				//Make ajax call to find out what options are available in the database
				$.get("/ajax/", {"action" : "getSolutions", "selectedCats" : $(this).val()}, function(data) {
					var ids = $.parseJSON(data);
					//Hide all options in the vertical dropdown
					$("#challengeDropDown > option, #solutionDropDown > option, ").each(function() {
						if($(this).val() != "0" && $.inArray($(this).val(), ids) == -1)
							$(this).hide();
						else
							$(this).show();
					});
				});
			}
		}
		//Remove current portfolio elements
		$("#portfolioList .listItem, #portfolioList h2, #portfolioList p").fadeOut(200, function() {
			$(this).remove();
		});
		//Remove any pagination
		$(".wp-pagenavi").children("a, span").remove();
		var vertCat = $("#verticalDropDown").val();
		var solCat = Math.max(parseInt($("#solutionDropDown").val()), parseInt($("#challengeDropDown").val()));
		//Get the new posts to show
		$.get("/ajax/", {"action" : "getPosts", "vertCat" : vertCat, "solCat":solCat}, function(data) {
			var posts = $.parseJSON(data);
			//Add in the new posts to show
			for(var i = 0; i < posts['posts'].length; i++) {
				var html = '<div class="listItem newListItem" style="display:none">' + 
					'<div class="imageHolder"><a href="'+posts['posts'][i]['link']+'" target="_blank"><img src="'+posts['posts'][i]['portfolioImage']+'" alt="" /></a></div>' + 
					'<div class="itemContent">' + 
					'<h2>'+posts['posts'][i]['clientName']+'</h2>' + 
					'<h3>'+posts['posts'][i]['campaignName']+'</h3>' + 
					'<p>'+posts['posts'][i]['excerpt']+'</p>' + 
					'<p><a href="'+posts['posts'][i]['link']+'" class="link">'+posts['posts'][i]['portfolioName']+'</a></p>' + 
					'</div>' + 
					'</div>';
				$("#portfolioList").append(html);
			}
			if(posts['posts'].length == 0) {
				$("#portfolioList").append('<h2 class="newListItem" style="display:none;">NO RESOURCES FOUND</h2>');
                $("#portfolioList").append('<p class="center newListItem" style="display:none;">Sorry, but no resources fit your qualifications.  Please try again.</p>');	
			}
			
			//Figure out if pagination is necessary
			var maxNum = parseInt(posts['max-num-pages']);
			if(maxNum > 1) {
				//Make the pagination querystring
				var vertCat = $("#verticalDropDown").val();
				var solCat = Math.max(parseInt($("#solutionDropDown").val()), parseInt($("#challengeDropDown").val()));
				var querystring = "?andCats=" + vertCat + "," + solCat;
				//We will always be on the first page
				$(".wp-pagenavi").append('<span class="pages" style="display:none;">Page</span><span class="current" style="display:none;">1</span>');
				//Add in the rest of the numbers
				for(var i = 2; i < 10 && i < maxNum; i++) 
					$(".wp-pagenavi").append('<a href="/our-work/page/'+i+'/'+querystring+'" class="page larger" style="display:none;">'+i+'</a>');
			}
			//Show the new ones
			$(".newListItem").fadeIn(200, function() {
				$(this).removeClass(".newListItem");
			})
			//Show the pagination if it exists
			$(".wp-pagenavi").children("a, span").fadeIn(200);
		});
	});
	
	$("#fcormForm").submit(function() {
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var validEmail = true;
		$("#fcormForm input").removeClass("error");
		//Validate firstname
		if($("#fcormFirstName").val() == "")
			$("#fcormFirstName").addClass("error");
		if($("#fcormLastName").val() == "")
			$("#fcormLastName").addClass("error");
		if($("#fcormEmail").val() == "")
			$("#fcormEmail").addClass("error");
		else if(!emailReg.test($("#fcormEmail").val())) {
            $("#fcormEmail").addClass("error");
			validEmail = false;
        }
		if($("#fcormOrganization").val() == "")
			$("#fcormOrganization").addClass("error");
		if($("#fcormTitle").val() == "")
			$("#fcormTitle").addClass("error");
		
		if($("#fcormWebVisitors").val() == "" || isNaN($("#fcormWebVisitors").val()))
			$("#fcormWebVisitors").addClass("error");
		if($("#fcormNumGifts").val() == "" || isNaN($("#fcormNumGifts").val()))
			$("#fcormNumGifts").addClass("error");
		if($("#fcormAvgGift").val() == "" || isNaN($("#fcormAvgGift").val()))
			$("#fcormAvgGift").addClass("error");
		
		if($("#fcormForm input.error").length > 0) {
			if(!validEmail && $("#fcormForm input.error").length == 1)
				alert("Please enter a valid email address");
			else
				alert("Some of the required fields are empty or not valid. Please check the highlighted fields and ensure the proper information is filled in.");
		}
		else {
			$("#fcormLoadingText").text("Processing").css("display", "inline");
			var comments = "Number Web Visitors: " + $("#fcormWebVisitors").val() + "\n";
			comments += "Average Number Gifts Per Month: " + $("#fcormNumGifts").val() + "\n";
			comments += "Average Gift Amount:" + $("#fcormAvgGift").val() + "\n";
			
			loadingTimer = setInterval("LoadingAnimation()", 500);
			$.post("/wp-content/themes/pursuant2011/ajax/addUser.php", {firstname: $("#fcormFirstName").val(), 
				lastname: $("#fcormLastName").val(), email: $("#fcormEmail").val(), phone: $("#fcormPhone").val(),
				organization: $("#fcormOrganization").val(), title: $("#fcormTitle").val(), webVisitors:$("#fcormWebVisitors").val(),
				numGifts: $("#fcormNumGifts").val(), avgGifts: $("#fcormAvgGift").val(), subject: "FCORM Form Submission", 
				comments: comments, vertical: $("#fcormVertical").val()},
				function(data) {
					//Add an iframe to the page to start the session in Silverpop
					var userData = $.parseJSON(data);
					
					//If there wasn't already a recipientID set
					if(document.cookie.indexOf('recipientID') == -1) {
						var url = document.URL;
						if(url.indexOf("?") > 0)
							url = url + "&spMailingID=2009440&spUserID="+userData['RecipientID']+"&spJobID=31824646&spReportId=MzE4MjQ2NDYS1";
						else 
							url = url + "?spMailingID=2009440&spUserID="+userData['RecipientID']+"&spJobID=31824646&spReportId=MzE4MjQ2NDYS1";
							
						$('<iframe />', {
							name: 'myFrame',
							frameborder: "0",
							src: url,
							scrolling: "no",
							width: "1",
							height: "1"
						}).appendTo('body');
					}
					clearInterval(loadingTimer);
					
					//Calculate the different amounts
					var organization = $("#fcormOrganization").val();
					var avgGift = parseFloat($("#fcormAvgGift").val());
					var avgGiftNPO = 80.80;
					var avgGiftDiff = roundNumber(((avgGift-avgGiftNPO)/avgGiftNPO)*100,2);
					
					var conversionRate = parseFloat($("#fcormNumGifts").val()) / parseFloat($("#fcormWebVisitors").val()) * 100;
					var conversionRateNPO = 2.05;
					var conversionRateDiff = roundNumber(((conversionRate-conversionRateNPO)/conversionRateNPO)*100,2);
					
					var webTraffic = parseInt($("#fcormWebVisitors").val());
					var webTrafficNPO = 11040;
					var webTrafficDiff = roundNumber(((webTraffic-webTrafficNPO)*1.0/webTrafficNPO)*100,2);
					
					var revenue = parseFloat($("#fcormAvgGift").val()) * parseFloat($("#fcormNumGifts").val());
					var revenueNPO = 18299.33;
					var revenueDiff = roundNumber(((revenue-revenueNPO)/revenueNPO)*100,2);				
					
					//Set the style and text
					$(".orgName").text(organization);
					$(".avgGift").text(roundNumber(avgGift, 2));
					$(".avgGiftNPO").text(avgGiftNPO);
					$(".avgGiftDiff").text(avgGiftDiff);
					
					$(".avgGiftDesc").text((avgGift > avgGiftNPO) ? "Above" : ((avgGift < avgGiftNPO) ? "Below" : "Same as"))
					if (avgGift > avgGiftNPO)
						$("#avgGiftImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/uarr.png");
                    else if (avgGift < avgGiftNPO)
                    	$("#avgGiftImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/darr.png");
                    else
				   		$("#avgGiftImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/sarr.png");
					

					$(".conversionRate").text(roundNumber(conversionRate, 2));
					$(".conversionRateNPO").text(conversionRateNPO);
					$(".conversionRateDiff").text(conversionRateDiff);
					
					$(".conversionRateDesc").text((conversionRate > conversionRateNPO) ? "Above" : ((conversionRate < conversionRateNPO) ? "Below" : "Same as"))
					if (conversionRate > conversionRateNPO)
						$("#conversionRateImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/uarr.png");
                    else if (conversionRate < conversionRateNPO)
                    	$("#conversionRateImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/darr.png");
                    else
				   		$("#conversionRateImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/sarr.png");
					
					
					$(".webTraffic").text(roundNumber(webTraffic, 0));
					$(".webTrafficNPO").text(webTrafficNPO);
					$(".webTrafficDiff").text(webTrafficDiff);
					$(".webTrafficDesc").text((webTraffic > webTrafficNPO) ? "Above" : ((webTraffic < webTrafficNPO) ? "Below" : "Same as"))
					
					if (webTraffic > webTrafficNPO)
						$("#webTrafficImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/uarr.png");
                    else if (webTraffic < webTrafficNPO)
                    	$("#webTrafficImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/darr.png");
                    else
				   		$("#webTrafficImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/sarr.png");
					
					
					$(".revenue").text(roundNumber(revenue, 2));
					$(".revenueNPO").text(revenueNPO);
					$(".revenueDiff").text(revenueDiff);
					$(".revenueDesc").text((revenue > revenueNPO) ? "Above" : ((revenue < revenueNPO) ? "Below" : "Same as"))
					
					if (revenue > revenueNPO)
						$("#revenueImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/uarr.png");
                    else if (revenue < revenueNPO)
                    	$("#revenueImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/darr.png");
                    else
				   		$("#revenueImg").attr("src", "/wp-content/themes/pursuant2011/images/fcorm/sarr.png");
					//Fade out the fcorm form 
					$("#fcormContactForm").fadeOut(200, function() {
						$("#fcormResults").fadeIn(200);
					});
					//Fade in the results
					
			});
		}
		return false;
	});
						   
});

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function hideMenu(){
	if (menuOn == false && onButton == false){
		$("#pyramid li a").removeClass("active"); // remove all active elements
		$(".tab_content").hide(); // hide all content
		$("#initialContent").fadeIn(); // bring back initial content
		//$("#pContent").animate( { height: $(".wrapper").outerHeight() + "px" }, 400 ); //animate the bubble length
		//$("#pyramidContent").animate( { height: $(".wrapper").outerHeight() + "px" }, 400 ); //animate the bubble length
	};
	
};



function LoadingAnimation() {
	if($("#footerloadingText").text().length == 10)
		$("#footerloadingText, #fcormLoadingText, #contactloadingText").text("Processing .");	
	else if($("#footerloadingText").text().length == 12)
		$("#footerloadingText, #fcormLoadingText, #contactloadingText").text("Processing . .");
	else if($("#footerloadingText").text().length == 14)
		$("#footerloadingText, #fcormLoadingText, #contactloadingText").text("Processing . . .");
	else
		$("#footerloadingText, #fcormLoadingText, #contactloadingText").text("Processing");
}

function slideLeft(nextIndex, prevIndex) {	
		//NEXT will refer to the next slide to show
		//PREV will refer to the slide currently showing
		$(".animation").stop().fadeOut(500, function() {
			$(this).css("display", "none");
		});
		//Move NEXT to the far right side of the container
		$($("#homeSlideshow .slide").get(nextIndex)).css("left", $("#homeSlideshow").width() + "px");
		$($("#homeSlideshow .slide").get(nextIndex)).addClass("active");
		$($("#homeSlideshow .slide").get(nextIndex)).animate({left: "0px"}, 1000, function() {
			$(this).find(".animation").fadeIn(2000);
			animating = false;
			if($(this).find(".animation").length != 0)
				animateBG();
		});
		$($("#homeSlideshow .slide").get(prevIndex)).animate({left: "-" + $("#homeSlideshow").width() + "px"}, 1000, function() {$(this).removeClass("active");});

		$("#slideSelection").find("a").removeClass("active");
		$($("#slideSelection").find("a").get(nextIndex)).addClass("active");
	}
function slideRight(nextIndex, prevIndex) {
	//NEXT will refer to the next slide to show
	//PREV will refer to the slide currently showing
	$(".animation").stop().fadeOut(500, function() {
		$(this).css("display", "none");
	});

	//Move NEXT to the far right side of the container
	$($("#homeSlideshow .slide").get(nextIndex)).css("left", "-" + $("#homeSlideshow").width() + "px");
	$($("#homeSlideshow .slide").get(nextIndex)).addClass("active");
	$($("#homeSlideshow .slide").get(nextIndex)).animate({left: "0px"}, 1000, function() {
		$(this).find(".animation").fadeIn(2000);
		animating = false;
		if($(this).find(".animation").length != 0)
			animateBG();
	});
	$($("#homeSlideshow .slide").get(prevIndex)).animate({left: $("#homeSlideshow").width() + "px"}, 1000, function() {$(this).removeClass("active");});
	$("#slideSelection").find("a").removeClass("active");
	$($("#slideSelection").find("a").get(nextIndex)).addClass("active");
}

function rotateWidget(elementID, time) {
	//If they are on the first bullet, make the next one to see the last bullet
	var nextIndex = $("#" + elementID).find(".active").next().index();
	if(nextIndex == -1)
		nextIndex = $("#" + elementID).find("img").first().index();
	
	$($("#" + elementID).find("img").get(nextIndex)).fadeIn(600, function() { $(this).addClass("active"); });
	$("#" + elementID).find(".active").fadeOut(600, function() { $(this).removeClass("active") });
	
	setTimeout("rotateWidget('"+ elementID +"', " + time + ");", time);
}

function recordResource(name) {
	$.post("/wp-content/themes/pursuant2011/ajax/addAudit.php", {name: name});
}

function nextSlide() {
	//If there is one next
	if($("#slideSelection .active").parent().next().length > 0)
		$("#slideSelection .active").parent().next().find("a").click();
	else
		$("#slideSelection a").first().click();
	slideshowTimer = setTimeout('nextSlide();', 5000);
};

