$(document).ready(function(){
	
	//Preload the menu images
	jQuery.preloadImages = function(){
  		for(var i = 0; i<arguments.length; i++){
    		jQuery("<img>").attr("src", arguments[i]);
  		}
	}
	$.preloadImages("assets/images/bg.slider.png", "assets/images/heading.mothers2.png", "assets/images/heading.gowns2.png", "assets/images/heading.maids2.png", "assets/images/heading.tuxes2.png", "assets/images/heading.accessories2.png", "assets/images/heading.brides2.png", "assets/images/bg.content2.jpg", "assets/images/bg.content3.jpg");
	
	$.resetClasses = function(){
		$(".menu-bottom a:eq(0)").removeClass().addClass("gowns");
		$(".menu-bottom a:eq(1)").removeClass().addClass("maids");
		$(".menu-bottom a:eq(2)").removeClass().addClass("mothers");
		$(".menu-bottom a:eq(3)").removeClass().addClass("tuxes");
		$(".menu-bottom a:eq(4)").removeClass().addClass("accessories");
		$(".menu-bottom a:eq(5)").removeClass().addClass("brides");
		$(".info").hide("normal");
		$(".content").css({ "background": "url(assets/images/bg.content3.jpg) no-repeat #FFFFFF" });
	}
	
	$.resetInfo = function(){
		$(".info, .otherinfo").hide("normal");
	}
	
	$.resetSlider = function(){
		$("#slider").slideUp("normal", function(){
			$("ul.menu-bottom").animate({ "marginLeft" : "50px"}, 500);
			$(".open").addClass( $.thisClass );
			$(".menu-bottom a").show();
			$.resetClasses();
			$("#menu-items").html("");
		});
		return false;
	}
	
	$.resetAll = function(){
		$.resetClasses();
		$.resetInfo();
		$.resetSlider();
		$(".events").show('normal');
	}

	//BOTTOM MENU FUNCTIONS//
	$(".menu-bottom a").each(function(){
	
		$(this).click(function(){
			$(".menu-bottom a").show();
			$(this).hide();
			$.thisClass = $(this).attr("class");
			$.resetClasses();
			$.resetInfo();
			$(".events").hide('normal');
			if( $("#slider").is(":open") ) $("#slider").slideUp();
			if( $.thisClass=='brides' ){
				$(".content").css({ "background": "url(assets/images/bg.content2.jpg) no-repeat #FFFFFF" });
			} else {
				$(".content").css({ "background": "url(assets/images/bg.content3.jpg) no-repeat #FFFFFF" });
			}
			
			if( $.thisClass=='tuxes' ){
				$(".info").load( "tuxes.php #info div", {}, function(){ 
					$(this).fadeIn("normal", function(){
						$(".info div:first").click(function(){
							$(".events").show('normal');
							$.resetAll();
							return true;
						});
					});
					$("#ajax-loader").fadeOut("normal");
				});
			}
			
			$(this).removeClass().addClass("open");
			$("ul.menu-bottom").animate({ "marginLeft" : "225px"}, 500, function(){
				$("#ajax-loader").fadeIn("normal");
				$(".heading").attr({ "src" : "assets/images/heading." + $.thisClass + "2.png" });
				$("#slider").slideDown();
				$("#menu-items").load($.thisClass + ".php #menu-items li", {}, function(){
					$("#ajax-loader").fadeOut("normal");
					//Slider menu items
					$("#menu-items a").each(function(){
						
						if($(this).attr("class")!="download"){
						
						$(this).click(function(){
							$("#ajax-loader").fadeIn("normal");
							$.menuItemsUrl = $(this).attr("href");
							$("#menu-items a").parent().removeClass("selected");
							$(this).parent().addClass("selected")
							$(".info").load( $.menuItemsUrl + " #info div", {}, function(){ 
								$(this).fadeIn("normal", function(){
									$(".info div:first").click(function(){
										$(".info").fadeOut("normal");
										//$(".events").show('normal');
										return true;
									});
								});
								$("#ajax-loader").fadeOut("normal");
							});
							return false;
						});
						
						}
						
					});
				});
			});
			return false;
		});
		
		//Reset
		$(".heading").click(function(){
			$.resetAll();
		});

	}); //END BOTTOM MENU//
	
	$(".home").click(function(){
		$.resetAll();
		$(".events").show('normal');
		return false;
	});
		
	$.extralinks = function(){
		$(".news, .about, .tips, .tips2").click(function(){
			
			$.resetClasses();
			$.resetSlider();	
			
			$(".otherinfo").load( $(this).attr("href") + " .otherinfo div", {}, function(){ 
				if( $(".events").is(':visible') ) $(".events").hide('normal');
				$.extralinks();
	
				$(this).show("normal", function(){
					$(".otherinfo div:first").click(function(){
															 $(".events").show('normal');
						$.resetInfo();
						return true;
					});
				});
			});
			return false;
		});
	}
	$.extralinks();
	
});