jQuery(document).ready(function() {

	String.prototype.toInt = function(){
		return this.replace(/px/, '') * 1;
	}
	Number.prototype.toInt = function(){
		return this;
	}


	// #page DIV height
	jQuery("html").css("height","100%");
	jQuery("body").css("height","100%");
	
	
	// Nav rollovers
	$(".roll img").css("opacity","0");
	$(".roll img").mouseenter(function(){ $(this).fadeTo(300, 0.5); });
	$(".roll img").mouseleave(function(){ $(this).fadeTo(300, 0.0); });
	
	// Close rollover
	$("#nav-close img").css("opacity","0");
	$("#nav-close img").mouseenter(function(){ $(this).fadeTo(300, 0.5); });
	$("#nav-close img").mouseleave(function(){ $(this).fadeTo(300, 0.0); });
	
	// Open rollover
	$("#nav-open div img").css("opacity","0");
	$("#nav-open div img").mouseenter(function(){ $(this).fadeTo(300, 0.5); });
	$("#nav-open div img").mouseleave(function(){ $(this).fadeTo(300, 0.0); });


	// Navigation accordion
	var is4 = "off";
	var is5 = "off";
	var is6 = "off";
	var navEnabled = true;
	
	$("#nav-4").click(function(){
		
		if(navEnabled==true){
			if(location.hash!="about"){ location.hash="about"; }
			navEnabled=false;
			if(is4=="off"){
				is4="on";
				
				$("#more-4").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } });
				if(is5=="on"){ is5="off"; $("#more-5").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } }); }
				if(is6=="on"){ is6="off"; $("#more-6").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } }); }
			} else {
				is4="off";
				$("#more-4").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } });
			}
		}
	});

	$("#nav-5").click(function(){
		
		if(navEnabled==true){
			if(location.hash!="contact"){ location.hash="contact"; }
			navEnabled=false;
			if(is5=="off"){
				is5="on";
				
				$("#more-5").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } });
				if(is4=="on"){ is4="off"; $("#more-4").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } }); }
				if(is6=="on"){ is6="off"; $("#more-6").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } }); }
			} else {
				is5="off";
				$("#more-5").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } });
			}
		}
	});
	
	$("#nav-6").click(function(){
		if(navEnabled==true){
			if(location.hash!="social"){ location.hash="social"; }
			navEnabled=false;
			if(is6=="off"){
				is6="on";
				
				$("#more-6").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } });
				if(is5=="on"){ is5="off"; $("#more-5").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } }); }
				if(is4=="on"){ is4="off"; $("#more-4").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } }); }
			} else {
				is6="off";
				$("#more-6").animate({height: 'toggle'}, {duration: 500, specialEasing: {height: 'linear'}, complete: function() { checkHeight(); enableNavSoon(); } });
			}
		}
	});
	
	$("#nav-close").click(function(){
		if(navEnabled==true){
			$("#page").slideToggle("medium");
			$("#nav-open").slideToggle("slow");
		}
	});
	
	$("#nav-open").hide();
	$("#nav-open").click(function(){
		$("#nav-open").slideToggle("false");
		$("#page").slideToggle("slow");
		navEnabled=true;
		setTimeout(doResizeNow,500);
	});
	
	
	
	
	// Arrangements, Accents, and Occasions
	$("#nav-1").click(function(){
		$.pauseNow();
		if(location.hash!="arrangements"){ location.hash="arrangements"; }
		$("#supersize").html("");
		
		setTimeout(runSetOne, 400);
	});
	function runSetOne(){
		$("#supersize").html(setContentsOne);
		nextslide();
		$(window).resize();
		setTimeout(removeBlack,1500);
		$.resumeNow();
	}
	
	$("#nav-2").click(function(){
		$.pauseNow();
		if(location.hash!="accents"){ location.hash="accents"; }
		$("#supersize").html("");
		
		setTimeout(runSetTwo, 400);
	});
	function runSetTwo(){
		$("#supersize").html(setContentsTwo);
		nextslide();
		$(window).resize();
		setTimeout(removeBlack,1500);
		$.resumeNow();
	}
	
	$("#nav-3").click(function(){
		$.pauseNow();
		if(location.hash!="occasions"){ location.hash="occasions"; }
		$("#supersize").html("");
		
		setTimeout(runSetThree, 400);
	});
	function runSetThree(){
		$("#supersize").html(setContentsThree);
		nextslide();
		$(window).resize();
		setTimeout(removeBlack,1500);
		$.resumeNow();
	}
	
	function removeBlack(){
		$("#removeme").remove();
	}
	
	function doResizeNow(){
		$(window).resize();
	}
	
	
	
	
	/* Body overflow hidden to get rid of scrollbar on tall browsers. */
	$(window).resize(function(){
		checkHeight();
	});
	
	var winh = $(window).height();
	var scrollheight = ($("#page").height() - $("#vert").height()) + 50;
	
	function checkHeight(){
		winh = $(window).height();
		scrollheight = ($("#page").height() - $("#vert").height()) + 50;
		
		if(winh>scrollheight){
			$("body").css("overflow","hidden");
				$("#footer").css("position","absolute");
				$("#footer").css("bottom","0px");
		} else {
			$("body").css("overflow","scroll");
			$("#footer").css("position","relative");
		}
		
		/* Now adjust the div#vert for vertical centering. */
		vertCenter("ease");
	}
	
	function vertCenter(when){
		
		if(winh>scrollheight){
			var diffh = winh - scrollheight;
			if(when=="now"){
				$("#vert").css("height",(diffh/2));
			} else {
				$("#vert").stop(true);
				$("#vert").animate({height: (diffh/2)},2000);
			}
		} else {
			if(when=="now"){
				$("#vert").css("height","10px");
			} else {
				$("#vert").stop(true);
				$("#vert").animate({height: "10"});
			}
		}
	}
	
	
	/* IE7 horizontal center fix */
	if (jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version)<8){
			var winw = $(document).width();
			$("#page").css("padding-left",((winw/2) - ($("#page").width()/2)));
		}
	}

	
	function enableNavSoon(){
		setTimeout(renableNavNow, 1700);
	}
	
	function renableNavNow(){
		navEnabled=true;
	}
	
	checkHeight();


});
