$(function() {

	var currentPage = location.href.substring(location.href.lastIndexOf("/") + 1);
	 
	if (currentPage == "") {
		currentPage = "index.php";
	}
	var current = "#main-nav a[href='" + currentPage + "']";
	$(current).addClass("selected");

	
	// projects
	var appendText = "<a href='#'><div class='close_btn'>X</div></a>\n";
	appendText += "<a href='#'><div class='next_btn'>&gt;</div></a>\n";
	appendText += "<a href='#'><div class='prev_btn'>&lt;</div></a>";
	$("div.project-holder").removeClass("project-holder").addClass("project-holder-positioned").append(appendText).hide();

	
	var current = null;
	var lastProject = $(".project-holder-positioned").filter(":last");
	var firstProject = $(".project-holder-positioned").filter(":first");
	
	$("#thumbnails a").click(function(e){
		if (current != null) {
			current.hide(1000);
		}
		current = $(".project-holder-positioned").filter(this.hash);
		current.show(1000);
		// alert(current.attr('id'));
		return false;
	});
	
	$(".close_btn").click(function(e){
		e.preventDefault();
		current.hide(1000);
		current = null;
		// alert(current);
		return false;
	});
	
	$(".next_btn").click(function(e){
		e.preventDefault();
		current.hide(1000);
		if (current.attr('id') == lastProject.attr('id')) {
			current = firstProject;
		} else {
			current = current.next();
		}
		current.show(1000);
		// alert(current.attr('id'));
		return false;
	}); 
	
	
	
	$(".prev_btn").click(function(e){
		e.preventDefault();
		current.hide(1000);
		if (current.attr('id') == firstProject.attr('id')) {
			current = lastProject;
		} else {
			current = current.prev();
		}
		current.show(1000);
		// alert(current.attr('id'));
		return false;
	});

	// sub-nav funcitonality
	if (currentPage == "facility.php"){
		var machineType = $("div[id^=mach]");
	
		machineType.hide().filter(":first").show();
		machineType.children("h1").addClass("remove");
		$("#sub-nav a").click(function(e){
			e.preventDefault();
			$("#sub-nav a").removeClass("selected");
			machineType.hide();
			$(this).addClass("selected");
			machineType.filter(this.hash).show();
			return false;
		}).filter(":first").click();
	}
});


