$(document).ready(function(){
	//OMG MORE DROPDOWN
	$(".dropdown").mouseover(
		function(){
			eOffset = $(this).offset();
			eHTML = '<div id="omg-more-dropdown-div">' + 
					'<ul id="omg-more-list">' + 
                	'<li><a href="press.php">Recent Press</a></li>' + 
                	'<li><a href="shipping-returns.php">Shipping / Returns</a></li>' + 
                	'<li><a href="http://grahamwithers.tumblr.com" target="_blank">Our Blog</a></li>' + 
                	'</ul></div>';
			$("#menu-dropdown").css({'display' : 'block', 'top' : eOffset.top, 'left' : eOffset.left}).html(eHTML);
			$("#omg-more-hidden-bg").css({'display' : 'block'});
		});
	$("#omg-more-hidden-bg").mouseover(function(){
		$("#omg-more-hidden-bg").css({'display' : 'none'});
		$("#menu-dropdown").css({'display' : 'none', 'top' : 0, 'left' : 0}).html("");
	});
	
	//TALK BUBBLE
	$(".item-related-sold-out").hover(
		function(){
			var thisId = $(this).attr('id');
			talkBubs("Sorry, this item is sold out :-(", thisId)
		},
		function(){
			 $("#talk-bubble").css({'top' : 0, 'left' : 0, 'display' : 'none'}).html('');
		}
	);

	//COLLECTION SUB NAV CLICKS
	var selectedGroup;
	$(".collection-sub-nav-list-a").click(function(){
		selectedGroup = $(this).attr('id').replace("sub-nav-", "");
		$(".collection-sub-nav-list-a").removeClass('collection-sub-nav-list-a-selected');
		$(this).addClass('collection-sub-nav-list-a-selected');
		$(".collection-wrapper").fadeOut(function(){
			$("#" + selectedGroup + "-wrapper").fadeIn();
		});
	});		
	
	//BACK TO TOP BUTTON CLICK
	$("#back-to-top").click(function(){
		if($(document).scrollTop() > 0){
			$("html,body").animate({scrollTop:0}, 'slow', function(){
				$(document).scrollTop(0);	
			});
		}
	});
	
	//CONTACT INPUT VALIDATION
	$("#contact-send-btn").click(function(){
		var name = $("#contact-name");
		var email = $("#contact-email");	
		var message = $("#contact-message");
		var spammer = $("#contact-spammer");
		var nameRegex = /^[a-zA-Z '-]{1,40}$/;
		var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		if(name.val() == ""){
			$("#contact-alert-div").html("Silly goose!  You forgot to enter your name...");
			$("#contact-alert-bg, #contact-alert-div").fadeIn().delay(2000).fadeOut(function(){
				$("#contact-alert-div").html("");
			});
		}
		else if(!nameRegex.test(name.val())){
			$("#contact-alert-div").html("Please re-enter your name");
			$("#contact-alert-bg, #contact-alert-div").fadeIn().delay(2000).fadeOut(function(){
				$("#contact-alert-div").html("");
			});
		}
		else if(email.val() == ""){
			$("#contact-alert-div").html("Please enter your return email address");
			$("#contact-alert-bg, #contact-alert-div").fadeIn().delay(2000).fadeOut(function(){
				$("#contact-alert-div").html("");
			});
		}
		else if(!emailRegex.test(email.val())){
			$("#contact-alert-div").html("Please re-enter your email address");
			$("#contact-alert-bg, #contact-alert-div").fadeIn().delay(2000).fadeOut(function(){
				$("#contact-alert-div").html("");
			});
		}
		else if(spammer.val() !== "8"){
			$("#contact-alert-div").html("You must pass the spam test!");
			$("#contact-alert-bg, #contact-alert-div").fadeIn().delay(2000).fadeOut(function(){
				$("#contact-alert-div").html("");
			});
		}
		else{
			$("#contact-alert-div").html("Sending...");
			$("#contact-alert-bg, #contact-alert-div").fadeIn();
			var jqxhr = $.post('ajax/contact_sendmail.php',{Name: name.val(), Email: email.val(), Message: message.val()},function(data){
				$("#contact-alert-div").html(data);
				$("#contact-alert-bg, #contact-alert-div").delay(2000).fadeOut(function(){
					$("#contact-alert-div").html("");
				});
			})
			.error(function() { alert("error"); });
		}
		
	});
	
	//WINDOW LOAD
	$(window).load(function(){
	//COLLECTION ITEM THUMBNAIL CLICKS
	$(".item-thumbnail-images").click(function(){
		var itemNum = $(this).attr('id').replace('item-thumbnail-image-', '');
		$(".item-big-images").hide();
		$("#item-big-image-" + itemNum).show();
	})
	
	});
});
