
function initZipSearch(z){
	var zipCode = z;
	var zipRegEx = /^\d{5}([\-]\d{4})?$/;
	var z;
	if(zipRegEx.test(z)){
		window.open("locations.php?zip=" + z,"_self");
	}
	else{
		alert("Please enter a valid zip code");	
	}	
}

$(document).ready(function() {
	
	var oneDay = 1000*60*60*24;               // 1 Day
	var startNum = 35524;                      // Waiting on final number from client
	
	var startDate = new Date(2011, 1, 22);	  // feb 22 2011
	var curDate = new Date();				  // Current date/time
	
	var daysSinceLaunch = Math.ceil((curDate.getTime() - startDate.getTime()) / oneDay);
	
	var numLocations = 5;				   
	var treesPerDay = numLocations * 16;
	
	var treesPlanted = startNum + (daysSinceLaunch * treesPerDay);
		
	var url = 'http://192.168.1.200/Clients/16Handles/';
	var bodyID = '#' + document.body.id;
	
	$(bodyID).fadeOut(0);
	
	$("#home-store-locator-button").click(function(){
		z = $("#home-store-locator-input").val();
		initZipSearch(z);	
	});
	
	$("#home-store-locator-input").keyup(function(e){
		if(e.keyCode == '13'){
			z = $(this).val();
			initZipSearch(z);	
		}
	});
		
	
$(window).load(function() {
	
	$(bodyID).fadeIn(600);
	
	$('.psuedo-selector').click(function(){
		var id = '#' + $(this).attr('id');
		var tabID = id.replace('psuedo-', '');
		var divID = tabID.replace('active', 'contents');
		
		$('html,body').animate({scrollTop: 0}, 600);
		
		$('.psuedo-selectors img').css({'z-index' : '30', 'display' : 'none'});
		$(tabID).css({'z-index' : '31', 'display' : 'block'});
		$('.tab-contents-div').hide(0);
		$(divID).show(0);
	});
	
	$('.navigation-item').click(function(){
		
		var page = $(this).attr('id');
		var page = page.replace('-nav', '');
		$(bodyID).fadeOut(600, function(){
			if( page == "index" )
			{ window.location = '/'; }
			else{
			window.location = page + '.php';
			}
			$(bodyID).delay(2000).fadeIn(0);
		});
	});
	
	$('#yogurt-nav, .yogurt-sub-nav').hover(
		function(){$('.yogurt-sub-nav').show(); $('.pink-div #yogurt-nav').css('background-color','#FCB040'); $('.orange-div #yogurt-nav, .green-div #yogurt-nav').css('background-color','#ED217C');},
		function(){$('.yogurt-sub-nav').hide(); $('.pink-div #yogurt-nav').css('background','none'); $('.orange-div #yogurt-nav').css('background','none'); $('.green-div #yogurt-nav').css('background','none');
	});		
	
	$('#story-nav, .story-sub-nav').hover(
		function(){$('.story-sub-nav').show(); $('.pink-div #story-nav').css('background-color','#FCB040'); $('.orange-div #story-nav, .green-div #story-nav').css('background-color','#ED217C');},
		function(){$('.story-sub-nav').hide(); $('.pink-div #story-nav').css('background','none'); $('.orange-div #story-nav').css('background','none'); $('.green-div #story-nav').css('background','none');
	});	
	
	$('.connect-selector-li').click(function(){
			var thisId = $(this).attr('id');
			var thisBg = thisId.replace('selector','bg');
			$('#connect-tweets-bg').css('z-index','4');
			$('#connect-contact-bg').css('z-index','3');
			$('#' + thisBg).css('z-index','5'); 
			
		});
		
	$("#press-icons-wrapper .press-lightbox").click(function(){
			
		var thisId = $(this).attr("id");
		var docHeight = $(document).height();
		var imgSrc;
		
		
		if (thisId == "press-nymag"){
			imgSrc = "images/story/press/article-images/newyorkmag-grubstreet.jpg";
		}
		if (thisId == "press-nypost"){
			imgSrc = "images/story/press/article-images/nypost.jpg";
		}
		if (thisId == "press-talk-of-the-town"){
			imgSrc = "images/story/press/article-images/TalkoftheTown2012.jpg";
		}
		if (thisId == "press-skinny-website"){
			imgSrc = "images/story/press/article-images/theskinnywebsite.jpg";
		}
		if (thisId == "press-us-weekly"){
			imgSrc = "images/story/press/article-images/USWeekly.jpg";
		}
		if (thisId == "press-zagat-2011"){
			imgSrc = "images/story/press/article-images/Zagat-16-Handles-2011.jpg";
		}
		if (thisId == "press-nytimes"){
			imgSrc = "images/story/press/article-images/nytimes.gif";
		}
		if (thisId == "press-cebu"){
			imgSrc = "images/story/press/article-images/cebu.jpg";
		}
		if (thisId == "press-parents"){
			imgSrc = "images/story/press/article-images/parentsconnect.jpg";
		}
		if (thisId == "press-nypress"){
			imgSrc = "images/story/press/article-images/nypress.jpg";
		}
		if (thisId == "press-inc"){
			imgSrc = "images/story/press/article-images/Inc.jpg";
		}
	
		$("#press-article-image").attr('src',imgSrc);
		$("#press-lightbox-div").show();
	});
		
	$("#lightbox-close-btn").click(function(){
		$("#press-lightbox-div,#job-app-lightbox-div").fadeOut();
		$("#press-article-image").attr('src',"");
	
	}); 
	
	$("#press-icons-wrapper .press-linkout").click(function(){
		
		var thisId = $(this).attr("id");
		
		if (thisId == "press-abc"){
			window.open("http://www.youtube.com/watch?v=ne9fRiRg_2c&feature=player_embedded");
		}
		if (thisId == "press-businesscamp"){
			window.open("http://www.youtube.com/watch?v=jp852hNnPoU")
		}
		if (thisId == "press-16h"){
			window.open("http://www.youtube.com/watch?v=Hrxa3-zIGqA")
		}
		if (thisId == "press-timeout"){
			window.open("http://www.youtube.com/watch?v=-vsASOgYTGA")
		}
		if (thisId == "press-inc"){
			window.open("http://incmagazine.coverleaf.com/incmagazine/201112?pg=22#pg22")
		}
		
	});
	
	
	$("#connect-careers-selector").click(function(){
		$("#job-app-lightbox-div").fadeIn();
	});
	
	
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	
//
//HOME
//
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	

		
		//SOCIAL MEDIA ICONS ON HOME AND CONTACT PAGES
		$("#home-facebook,#locationsFR-facebook,#connect-facebook").click(function(){window.open("http://www.facebook.com/16Handles")});
		$("#home-twitter,#locationsFR-twitter,#connect-twitter").click(function(){window.open("http://twitter.com/16handles")});
		$("#home-foursquare,#locationsFR-foursquare,#connect-foursquare").click(function(){window.open("http://www.foursquare.com")});
		$("#connect-youtube").click(function(){window.open("http://www.youtube.com/sixteenhandles")});





///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	
//
//LOCATIONS
//
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	
		
/*		$('.locations-list-additional-location').click( function(){
				
			var text = $(this).text();
			
			if(text.indexOf('Handling Soon') < 0 && text.indexOf('Opening') < 0){
				var location_id = $(this).attr('id');
				var location_id = location_id.replace('locations-goto-','');
				var storeName;
				
				switch(location_id)
				{
				case "1":
				  storename = "ev";
				  break;
				case "2":
				  storename = "bocaraton";
				  break;
				case "3":
				  storename = "rio";
				  break;
				case "4":
				  storename = "kentlands";
				  break;
				case "5":
				  storename = "gsp";
				  break;
				case "6":
				  storename = "jericho";
				  break;
				case "7":
				  storename = "ues";
				  break;
				case "8":
				  storename = "uws";
				  break;
				case "9":
				  storename = "cliftonpark";
				  break;
				case "10":
				  storename = "fairfield";
				  break;
				case "11":
				  storename = "port";
				  break;
				default:
				  alert('this location does not exist!');
				}
				var url_id = 'http://www.16handles.com/store/' + storename + '.php';
				window.open(url_id,"_blank");
				
			}
		
		});
		
		$('.locations-list-additional-location').hover(function()
		{
			var text = $(this).text();
			if(text.indexOf('Handling Soon') < 0 && text.indexOf('Opening') < 0)
			{
				$(this).css({ 'color' : '#ED217C'});
			}
			
		}, 
		function()
		{
			var text = $(this).text();
			if(text.indexOf('Handling Soon') < 0 && text.indexOf('Opening') < 0)
			{
				$(this).css({ 'color' : '#FFFFFF'});
			}
		});*/
			
		$(".locations-map-image").mouseover(function(){
			var thisId = $(this).attr('id');
			$("#" + thisId + "-hover").show();
		});
			
		$(".locations-map-image-hover").mouseout(function(){
			var thisId = $(this).attr('id');
			$("#" + thisId).hide();
		});
	
	$(".locations-map-image-hover").click(function(){
			var thisId = $(this).attr('id');
			var newId = thisId.replace('-hover','-click');
			var i;
			
			for(i = 1; i < 11; i++){
				
				if(i != 10){
					$("#locations-map-image-0" + i + "-click").hide();
				}
				else{
					$("#locations-map-image-" + i + "-click").hide();
				}
			}
				
			$("#" + newId).show();
			
				
			switch(thisId){
				case "locations-map-image-07-hover":
				//Florida
					$(".locations-store-div").hide();
					$("#Florida-Store-Location").show();
					$("#locations-map-copy").html("One 16 Handles Exists In This Region");
					enableScroll();
					break;
					
				case "locations-map-image-09-hover":
				//NJ and NY
					$(".locations-store-div").hide();
					$("#New-York-Store-Location, #New-Jersey-Store-Location").show();
					$("#locations-map-copy").html("Seven 16 Handles Exist In This Region");
					enableScroll();
					break;
					
				case "locations-map-image-08-hover":
				//Maryland
					$(".locations-store-div").hide();
					$("#Maryland-Store-Location, #District-of-Columbia-Store-Location").show();
					$("#locations-map-copy").html("Two 16 Handles Exist In This Region");
					enableScroll();
					break;
					
				case "locations-map-image-10-hover":
				//CT
					$(".locations-store-div").hide();
					$("#Connecticut-Store-Location").show();
					$("#locations-map-copy").html("One 16 Handles Exist In This Region");
					enableScroll();
					break;
					
				default:
				
				$("#locations-map-copy").html("No 16 Handles exists here. Would you be interested in opening a Franchise?<br /><u><span id='locations-goto-franchise-page'>View Franchise Page</span></u>");
				$(".locations-store-div").hide();
				$(".locations-store-div").show();
				enableScroll();
	
				$('#locations-goto-franchise-page').click(function(){
					$('#locations').fadeOut(600, function(){
						window.location = 'franchise.php';
						$('#locations').delay(2000).fadeIn(0);
					});
				});
			}
			
			$(".locations-list-h1").FontEffect({ 
				outline :true, 
				outlineColor1 :"#FFF", 
				outlineWeight :2
			});
			
		});
		
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	
//
//SHOP
//
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////		
		
		
		$(".flaunt-mens-shirt-thumb").click(function(){
			thisId = $(this).attr('id');
			replaceId = thisId.replace('thumb','big');
			
			$(".flaunt-mens-shirt-big").hide();
			$("#" + replaceId).fadeIn();
		});
		
		$(".flaunt-womens-shirt-thumb").click(function(){
			thisId = $(this).attr('id');
			replaceId = thisId.replace('thumb','big');
			
			$(".flaunt-womens-shirt-big").hide();
			$("#" + replaceId).fadeIn();
		});
		
		$("#flaunt-men-handle,#flaunt-men-sel").click(function(){
			$("#flaunt-women-div,#flaunt-women-handle,#flaunt-paypal-form").hide();
			$("#flaunt-men-div,#flaunt-men-handle").show();
		});
		
		$("#flaunt-women-handle,#flaunt-women-sel").click(function(){
			$("#flaunt-women-div,#flaunt-women-handle,#flaunt-paypal-form").show();
			$("#flaunt-men-div,#flaunt-men-handle").hide();
		});
		
		$("#flaunt-wearit-sel-off").click(function(){
			$("#flaunt-share-it,#flaunt-shareit-sel-on,#flaunt-wearit-sel-off").hide();
			$("#flaunt-wear-it,#flaunt-wearit-sel-on,#flaunt-shareit-sel-off").show();
		});
		
		$("#flaunt-shareit-sel-off").click(function(){
			$("#flaunt-wear-it,#flaunt-wearit-sel-on,#flaunt-shareit-sel-off").hide();
			$("#flaunt-share-it,#flaunt-shareit-sel-on,#flaunt-wearit-sel-off").show();
		});
		
		$("#flaunt-shareit-cart-button").click(function(){
			window.open("http://www3.myicard.net/","_blank");
		});



///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	
//
//FRANCHISE
//
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	

$('#franchise-brochure').click(function(){
			window.open("documents/franchise-brochure.pdf","_blank");
		});

$('#franchise-submit-btn').click(function(){
				var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
				var firstName = $('#franchise-first-name');
				var lastName = $('#franchise-last-name');
				var phone = $('#franchise-phone');
				var email = $('#franchise-email');
				var city = $('#franchise-city');
				var state = $('#franchise-state');
				var zip = $('#franchise-zip');
				var ownedAndOperated = $('#franchise-owned-and-operated');
				var ownedAndOperatedOther = $('#franchise-owned-and-operated-other');
				var netWorth = $('#franchise-net-worth');
				var capitalToInvest = $('#franchise-capital-to-invest');
				var portionFinanced = $('#franchise-portion-financed');
				var portionFinancedExplain = $('#franchise-portion-financed-explain');
				var areaOfInterest = $('#franchise-area-of-interest');
				var areaOfInterestOther = $('#franchise-area-of-interest-other');
				var howDidYouHear = $('#franchise-how-did-you-hear');
				var whenStart = $('#franchise-when-start');
				
				var checkEmail = emailRegex.test(email.val());
				
				var errors = "";
				
				
				if(firstName.val() == ""){
					alert("Please enter your First Name");
				}
				else if(lastName.val() == ""){
					alert("Please enter your Last Name");
				}
				else if(phone.val() == ""){
					alert("Please enter your Phone Number");
				}
				else if(!checkEmail){
					alert("Please enter your Email");
				}
				else if(city.val() == ""){
					alert("Please enter your City");
				}
				else if(state.val() == ""){
					alert("Please enter your State");
				}
				else if(zip.val() == ""){
					alert("Please enter your Zip");
				}
				else{
			
					var urlString = "FirstName=" + firstName.val() + "&LastName=" + lastName.val() + "&Phone=" + phone.val() + "&Email=" + email.val() + "&City=" + city.val() + "&State=" + state.val() + "&Zip=" + zip.val() + "&OwnedAndOperated=" + ownedAndOperated.val() + "&OwnedAndOperatedOther=" + ownedAndOperatedOther.val() + "&NetWorth=" + netWorth.val() + "&CapitalToInvest=" + capitalToInvest.val() + "&PortionFinanced=" + portionFinanced.val() + "&PortionFinancedExplain=" + portionFinancedExplain.val() + "&AreaOfInterest=" + areaOfInterest.val() + "&AreaOfInterestOther=" + areaOfInterestOther.val() + "&HowDidYouHear=" + howDidYouHear.val() + "&WhenStart=" + whenStart.val();
			
					$("#franchise-alert").fadeIn();
					
					$.ajax({
						type: "POST",
						url: "ajax/franchise/sendFranchiseInquiry.php",
						data: urlString,
						success: function(msg){
						alert("Email Sent!");
						}
					});
					
				}//end if statement
		
		});
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	
//
//ABOUT
//
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	

		$("#about-tree-counter-numbers").html("0000" + treesPlanted);
		

///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	
//
//FLAVORS
//
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	


			
		$('#flavors-ingredients-btn').click(function(){
			window.open("documents/16H_Ingredients.pdf","_blank");
		});
		$('#flavors-nutrition-facts-btn').click(function(){
			window.open("documents/nutrition-facts.pdf","_blank");
		});
		
		$('.flavors-content-ul-li').hover(
			function(e){
				var thisId = '#' + $(this).attr("id");
				var hoverId = thisId.replace(/-hover/,'-nf-hover');
				
				var leftVal = $(this).offset().left;
				var itemWidth = $(this).width();	
				
				var viewWidth = $(window).width();	
				var widthOffset = (viewWidth / 2) - 50;	
						
				if(leftVal > widthOffset){
					$(hoverId).css({'left': (leftVal - 376)});
					$(hoverId).show();
				}
				else{
					$(hoverId).css({'left': (leftVal + itemWidth)});
					$(hoverId).show();
				}
				
			},
			function(){
				$(".flavors-popup").hide();
			}
		);

///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	
//
//CONTACT
//
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////		
$('#connect-contact-submit').click(function(){
			
			var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
			var email = $("#connect-contact-email-input");
			var checkEmail = emailRegex.test(email.val());
			
			if(!checkEmail){
				alert("Please enter a valid email address");
			}
			else{
		
				for(i=0; i<document.connectContactUs.elements.length; i++)
					{
					var connectContactUsString;
					connectContactUsString += document.connectContactUs.elements[i].name + ": " + document.connectContactUs.elements[i].value + ".\n";
					connectContactUsString = connectContactUsString.replace(/undefined/i, "");
					}
			
					
				$.post('ajax/connect/sendContactUs.php', {ConnectContactUsString : connectContactUsString}, function(msg){
					alert("Message Sent");
						
				});
				
			}//End if
		
		
		});	
		$('#connect-job-app-submit').click(function(){
			
			var storeLocation = $("#job-app-location").val();
			
			for(i=0; i<document.jobAppForm.elements.length; i++)
				{
				var JobAppFieldString;
				JobAppFieldString += document.jobAppForm.elements[i].name + ": " + document.jobAppForm.elements[i].value + ".\n";
				JobAppFieldString = JobAppFieldString.replace(/undefined/i, "");
				}
				
				$.post('ajax/connect/sendJobApp.php', {jobAppFieldString : JobAppFieldString, location : storeLocation}, function(msg){
					alert("Message Sent");
					$("#job-app-lightbox-div").fadeOut();
					
				});
		
			
		
		});	
		
		$("#job-app-days-avail-sun,#job-app-days-avail-mon,#job-app-days-avail-tues,#job-app-days-avail-wed,#job-app-days-avail-thurs,#job-app-days-avail-fri,#job-app-days-avail-sat").click(function(){
			
			var thisId = $(this).attr('id');
			var inputId = thisId + "-input";
			
			
			if($(this).attr("checked") == true){
				$("#" + inputId).removeAttr('disabled');
				$("#" + inputId).css({'background':'#FFFFFF','color':'#000000','cursor':'text'});
			}
			else{
				$("#" + inputId).attr('disabled',true);
				$("#" + inputId).css({'background':'#EBEBEB','color':'#C0C0C0','cursor':'pointer'});
			}
			
		});
				
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	
//
//FONTS
//
///////////////////////////////////////////////////////	
///////////////////////////////////////////////////////	

		Cufon.replace('.home-mailing-list-p, .flavors-header-h1, .flavors-chalet-p, .toppings-chalet-p, .locationsFR-h1, .locationsFR-h2, .locationsFR-h2-first');	
		
/*		$(".franchise-application-h1").FontEffect({ outline :true,
			outlineColor1 :"#FFF",
			outlineWeight :2});
			
		$(".franchise-h1").FontEffect({ outline :true,
			outlineColor1 :"#FFF", 
			outlineWeight :2});*/
			
		$(".locations-list-h1").FontEffect({ outline :true, // Apply the outline effect 
			outlineColor1 :"#FFF", // [find contrasting] The upper left outline color 
			outlineWeight :2});
			
		$(".flaunt-men-women-p").FontEffect({ outline :true, // Apply the outline effect 
			outlineColor1 :"#FFF", // [find contrasting] The upper left outline color 
			outlineWeight :2});
			
		$(".connect-h1").FontEffect({ outline :true, // Apply the outline effect 
			outlineColor1 :"#FFF", // [find contrasting] The upper left outline color 
			outlineWeight :2});
	
});  // End Document Load
	
}); // End Document Load


