// 

$(document).ready(function(){

	// Open external window in new tab
	$("#content a[href^='http']:not([href*='bronxladies.com'])").click(function(){  
		window.open(this.href);  
		return false; 
	})

	// Contact Button
	var $contact = $("#menu-nav li:last").children("a");
	$("#menu-nav li:last").children("a")
		.after("<h6>" + $contact.html() + '</h6><ul class="contact sub-menu" style="display: none"><li>Bronx Ladies</li><li><a href="mailto:info@jordan.co.za">info@jordan.co.za</a></li><li>head office 2721 590 7000</li></ul>').remove();
	
	$(window).scroll(function(){
		if($(window).scrollTop() > 100){
			$("#access").stop().animate({"marginTop": ($(window).scrollTop() - 100) + "px"}, "slow" );
		}
		else{
			$("#access").stop().animate({"marginTop": "0px"}, "slow" );
		}
	});
	// End Contact Button

	// Menu
	$("#menu-nav ul").css("display", "none");
	$("li.current_page_parent").children("ul").css("display", "block");
	
	$("#menu-nav > li").has("ul").children("a").each(function(){
		$(this).after("<h6>" + $(this).html() + "</h6>");
		$(this).remove();
	});
	
	$("#menu-nav li:first > ul > li:last").addClass("see-all");
	$("#menu-nav li:last").addClass("last");
	// Write for Shoes
	// $("#menu-nav li:last").addClass("last").append("<span>Specials!</span>");
	
	$(".sub-menu").parent("li").children("h6").click(function(){
															  
		$(this).parent("li").find(".sub-menu").slideToggle(function(){
			$(".sub-menu:visible").not(this).slideToggle();
		});
		
	});
	
	if($("body").hasClass("archive")){
		$(".find-a-store h3").nextUntil().css("display", "none");
		$(".find-a-store h3").click(function(){
			$(this).nextUntil().slideToggle();
		});
	}
	// End Menu
		
	// What's your Vibe
	$(".vibe-excerpt").css("display", "none");
	$(".image-inner-container").hover(function(){
		$(".vibe-excerpt").css("display", "none");
		$(this).find(".vibe-excerpt").fadeIn(300);
	},function(){
		$(this).find(".vibe-excerpt").css("display", "none");
	});
	// End What's your Vibe
	
	// Archive
		if($("#latest li:nth-child(11)").length){
		$("#latest").append('<li id="archive"><a href="#">Archive</a></li>');
		$("#latest li:nth-child(10)").nextUntil("#archive").css("display", "none");
		
		$("#archive").click(function(){
			$("#latest li:nth-child(10)").nextUntil("#archive").slideToggle();	
			return false;
		});
	}
	// End Archive
	
});

$(window).load(function(){
						
	// If carousel images exit, remove the default image
	// If not, remove the controls
	if($("#carousel").find("img.carousel-image").length){
		$("#carousel img.default").remove();
		$("#carousel img.carousel-image").css("display", "none");
		$("#carousel img.carousel-image:first").css("display", "block");
	} 
	else{
		$("#carousel-controls").css("display", "none");
	}

	// Next controls
	$("#next").click(function(){
		if($("#carousel img:last").is(":visible")){
			$("#carousel img:visible").fadeOut(function(){
					$("#carousel img:first").fadeIn();	
			});
		}
		else{
			$("#carousel img:visible").fadeOut(function(){
					$(this).next().fadeIn();	
			});
		}
		return false;
	});
	// End Next controls
	
	// Previous controls
	$("#prev").click(function(){
		if($("#carousel img:first").is(":visible")){
			$("#carousel img:visible").fadeOut(function(){
					$("#carousel img:last").fadeIn();	
			});
		}
		else{
			$("#carousel img:visible").fadeOut(function(){
					$(this).prev().fadeIn();	
			});
		}
		return false;
	});
	// End Previous controls
	
	
	// Zoom
	$("#shoe-zoom ul li").click(function(){
		$("#zoom-large").attr("src", $(this).find("img").attr("src"));	
		return false;
	 });
	
		// Colour switcher
	$("#shoe-button-1").click(function(){
		$("#shoe-zoom ul li").css("display", "none");
		$("#shoe-zoom ul li.colour-1").css("display", "block");
		$("#zoom-large").attr("src", $("#shoe-zoom ul li.colour-1.first").find("img").attr("src"));
		return false;
	});
	
	$("#shoe-button-2").click(function(){
		$("#shoe-zoom ul li").css("display", "none");
		$("#shoe-zoom ul li.colour-2").css("display", "block");	
		$("#zoom-large").attr("src", $("#shoe-zoom ul li.colour-2.first").find("img").attr("src"));
		return false;
	});

	$("#shoe-button-3").click(function(){
		$("#shoe-zoom ul li").css("display", "none");
		$("#shoe-zoom ul li.colour-3").css("display", "block");	
		$("#zoom-large").attr("src", $("#shoe-zoom ul li.colour-3.first").find("img").attr("src"));
		return false;
	});
	
	$("#shoe-button-4").click(function(){
		$("#shoe-zoom ul li").css("display", "none");
		$("#shoe-zoom ul li.colour-4").css("display", "block");	
		$("#zoom-large").attr("src", $("#shoe-zoom ul li.colour-4.first").find("img").attr("src"));
		return false;
	});
	
	$("#shoe-button-53").click(function(){
		$("#shoe-zoom ul li").css("display", "none");
		$("#shoe-zoom ul li.colour-5").css("display", "block");	
		$("#zoom-large").attr("src", $("#shoe-zoom ul li.colour-5.first").find("img").attr("src"));
		return false;
	});
	// End Zoom
	
});
