/* Rachel Thurston Javascript Sliding Nav */
/* UPDATING:
subnav_variablename - adjust width so the right border of the subnav is 16px from the end of the last word
if there are more than 3 links you will need another div column in the subnav and need to adjust widths accordingly */
// Navigation Variables - Tell if any subnavs are open
subWeddingOpen = 0;
subBirthOpen = 0;
subPeopleOpen = 0;
subTravelOpen = 0;
subContactOpen = 0;

// Remove hover effect from all nav items
function removeHover() {
		$("#nav_weddings").removeClass("nav_hoverstate");
		$("#nav_births").removeClass("nav_hoverstate");
		$("#nav_people").removeClass("nav_hoverstate");
		$("#nav_travel").removeClass("nav_hoverstate");
		$("#nav_contact").removeClass("nav_hoverstate");
}

$(document).ready(function(){
// Navigation onclick events
// If statements check if other subnavs are open so they can be closed before opening the corresponding subnav
// Weddings
$("#nav_weddings").click(function(){
	if(subWeddingOpen == 0) {
		$("#nav_weddings").addClass("nav_hoverstate");
		$("#nav_births").removeClass("nav_hoverstate");
		$("#nav_people").removeClass("nav_hoverstate");
		$("#nav_travel").removeClass("nav_hoverstate");
		$("#nav_contact").removeClass("nav_hoverstate");
		subWeddingOpen = 1;
		if(subBirthOpen == 1) {
			subBirthOpen = 0;
			$("#subnav_births").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_births").hide();
				$("#subnav_weddings").show();
				$("#subnav_weddings").animate({width:"285px"},600, "easeOutCirc");			
			});	
		} else if(subPeopleOpen == 1) {
			subPeopleOpen = 0;
			$("#subnav_people").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_people").hide();
				$("#subnav_weddings").show();
				$("#subnav_weddings").animate({width:"285px"},600, "easeOutCirc");			
			});	
		} else if(subTravelOpen == 1) {
			subTravelOpen = 0;
			$("#subnav_travel").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_travel").hide();
				$("#subnav_weddings").show();
				$("#subnav_weddings").animate({width:"285px"},600, "easeOutCirc");			
			});	
		} else if(subContactOpen == 1) {
			subContactOpen = 0;
			$("#subnav_contact").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_contact").hide();
				$("#subnav_weddings").show();
				$("#subnav_weddings").animate({width:"285px"},600, "easeOutCirc");			
			});	
		} else {
			$("#subnav_weddings").show();
			$("#subnav_weddings").animate({width:"285px"},600, "easeOutCirc");
		}
	}
	});
// Births
$("#nav_births").click(function(){
	if(subBirthOpen == 0) {
		$("#nav_weddings").removeClass("nav_hoverstate");
		$("#nav_births").addClass("nav_hoverstate");
		$("#nav_people").removeClass("nav_hoverstate");
		$("#nav_travel").removeClass("nav_hoverstate");
		$("#nav_contact").removeClass("nav_hoverstate");
		subBirthOpen = 1;
		if(subWeddingOpen == 1) {
			subWeddingOpen = 0;
			$("#subnav_weddings").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_weddings").hide();
				$("#subnav_births").show();
				$("#subnav_births").animate({width:"102px"},600, "easeOutCirc");			
			});	
		} else if(subPeopleOpen == 1) {
			subPeopleOpen = 0;
			$("#subnav_people").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_people").hide();
				$("#subnav_births").show();
				$("#subnav_births").animate({width:"102px"},600, "easeOutCirc");			
			});	
		} else if(subTravelOpen == 1) {
			subTravelOpen = 0;
			$("#subnav_travel").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_travel").hide();
				$("#subnav_births").show();
				$("#subnav_births").animate({width:"102px"},600, "easeOutCirc");			
			});	
		} else if(subContactOpen == 1) {
			subContactOpen = 0;
			$("#subnav_contact").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_contact").hide();
				$("#subnav_births").show();
				$("#subnav_births").animate({width:"102px"},600, "easeOutCirc");			
			});	
		} else {
			$("#subnav_births").show();
			$("#subnav_births").animate({width:"102px"},600, "easeOutCirc");																									 
		}
	}
	});
// People
$("#nav_people").click(function(){
	if(subPeopleOpen == 0) {
		$("#nav_weddings").removeClass("nav_hoverstate");
		$("#nav_births").removeClass("nav_hoverstate");
		$("#nav_people").addClass("nav_hoverstate");
		$("#nav_travel").removeClass("nav_hoverstate");
		$("#nav_contact").removeClass("nav_hoverstate");
		subPeopleOpen = 1;
		if(subBirthOpen == 1) {
			subBirthOpen = 0;
			$("#subnav_births").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_births").hide();
				$("#subnav_people").show();
				$("#subnav_people").animate({width:"92px"},600, "easeOutCirc");			
			});
		} else if(subWeddingOpen == 1) {
			subWeddingOpen = 0;
			$("#subnav_weddings").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_weddings").hide();
				$("#subnav_people").show();
				$("#subnav_people").animate({width:"92px"},600, "easeOutCirc");			
			});
		} else if(subTravelOpen == 1) {
			subTravelOpen = 0;
			$("#subnav_travel").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_travel").hide();
				$("#subnav_people").show();
				$("#subnav_people").animate({width:"92px"},600, "easeOutCirc");			
			});		
		} else if(subContactOpen == 1) {
			subContactOpen = 0;
			$("#subnav_contact").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_contact").hide();
				$("#subnav_people").show();
				$("#subnav_people").animate({width:"92px"},600, "easeOutCirc");			
			});	
		} else {
			$("#subnav_people").show();
			$("#subnav_people").animate({width:"92px"},600, "easeOutCirc");																								 
		}
	}
	});
// Travel
$("#nav_travel").click(function(){
		if(subTravelOpen == 0) {
		$("#nav_weddings").removeClass("nav_hoverstate");
		$("#nav_births").removeClass("nav_hoverstate");
		$("#nav_people").removeClass("nav_hoverstate");
		$("#nav_travel").addClass("nav_hoverstate");
		$("#nav_contact").removeClass("nav_hoverstate");
		subTravelOpen = 1;
		if(subBirthOpen == 1) {
			subBirthOpen = 0;
			$("#subnav_births").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_births").hide();
				$("#subnav_travel").show();
				$("#subnav_travel").animate({width:"184px"},600, "easeOutCirc");			
			});
		} else if(subWeddingOpen == 1) {
			subWeddingOpen = 0;
			$("#subnav_weddings").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_weddings").hide();
				$("#subnav_travel").show();
				$("#subnav_travel").animate({width:"184px"},600, "easeOutCirc");			
			});
	} else if(subPeopleOpen == 1) {
			subPeopleOpen = 0;
			$("#subnav_people").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_people").hide();
				$("#subnav_travel").show();
				$("#subnav_travel").animate({width:"184px"},600, "easeOutCirc");			
			});
		} else if(subContactOpen == 1) {
			subContactOpen = 0;
			$("#subnav_contact").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_contact").hide();
				$("#subnav_travel").show();
				$("#subnav_travel").animate({width:"184px"},600, "easeOutCirc");			
			});	
		} else {
			$("#subnav_travel").show();
			$("#subnav_travel").animate({width:"184px"},600, "easeOutCirc");																								 
		}
	}
	});
// Contact
$("#nav_contact").click(function(){
		if(subContactOpen == 0) {
		$("#nav_weddings").removeClass("nav_hoverstate");
		$("#nav_births").removeClass("nav_hoverstate");
		$("#nav_people").removeClass("nav_hoverstate");
		$("#nav_travel").removeClass("nav_hoverstate");
		$("#nav_contact").addClass("nav_hoverstate");
		subContactOpen = 1;
		if(subBirthOpen == 1) {
			subBirthOpen = 0;
			$("#subnav_births").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_births").hide();
				$("#subnav_contact").show();
				$("#subnav_contact").animate({width:"98px"},600, "easeOutCirc");			
			});
		} else if(subWeddingOpen == 1) {
			subWeddingOpen = 0;
			$("#subnav_weddings").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_weddings").hide();
				$("#subnav_contact").show();
				$("#subnav_contact").animate({width:"98px"},600, "easeOutCirc");			
			});
	} else if(subPeopleOpen == 1) {
			subPeopleOpen = 0;
			$("#subnav_people").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_people").hide();
				$("#subnav_contact").show();
				$("#subnav_contact").animate({width:"98px"},600, "easeOutCirc");			
			});
		} else if(subTravelOpen == 1) {
			subTravelOpen = 0;
			$("#subnav_travel").animate({width:"0px"},500, "easeOutCirc", function() { 
				$("#subnav_travel").hide();
				$("#subnav_contact").show();
				$("#subnav_contact").animate({width:"98px"},600, "easeOutCirc");			
			});	
		} else {
			$("#subnav_contact").show();
			$("#subnav_contact").animate({width:"98px"},600, "easeOutCirc");																								 
		}
	}
	});
	//
});