jQuery(document).ready(function($) {
  if ($('#productDetail') && $('h2.titleHeader').html() && $('h2.titleHeader').html().indexOf('*CUSTOM*') == -1) {
	// Remove useless divs
    $('#productDetail #freeShipping, #productDetail #printerFriendly').parent('div').remove();
	var visitors_date_object = new Date;
	// Visitor's unix time
	var visitors_unix = visitors_date_object.getTime();
	// Visitor's timezone offset
	var visitors_offset = -visitors_date_object.getTimezoneOffset() * 60000;
	// Current unix time (UTC)
	var current_utc = visitors_unix - visitors_offset;
	// Our unix time (EST)
	var our_unix = current_utc - 18000000;
	var our_date_object = new Date(our_unix);
	var our_month = our_date_object.getMonth();
	var our_day_month = our_date_object.getDate();
	var our_date = our_month+'/'+our_day_month;
	var our_day = our_date_object.getDay();
	var our_hour = our_date_object.getHours();
	var our_minutes = our_date_object.getMinutes();
	var our_seconds = our_date_object.getSeconds();
	var our_holidays = new Array('1/1','5/30','7/4','9/5','11/24','11/25','12/24');

	// It's not a Saturday
	if (our_day != 6) {
		// It's before 2pm here, and NOT a Friday
		if (our_hour < 14 && our_day != 5 && our_day != 0) {
			var hours_left = 13 - our_hour;
			// Today happens to be a holiday:
			if (jQuery.inArray(our_date, our_holidays) != -1) {
				if (next_business_day.getMonth() == 11) {
					if (next_business_day.getDate() == 24) {
						var hours_left = hours_left + 48;
					}
					else {
						var hours_left = hours_left + 24;
					}
				}
				if (next_business_day.getMonth() != 11) {
					var hours_left = hours_left + 24;
				}
			}
			var minutes_left = 60 - our_minutes;
			var add_me = hours_left * 3600000 + (minutes_left * 60000) + our_unix + (our_seconds * 1000);
			var next_business_day = new Date(add_me);
			var next_business_date = next_business_day.getMonth() + '/' + next_business_day.getDate();
			
			// The Ship date falls on a holiday
			if (jQuery.inArray(next_business_date, our_holidays) != -1) {
				if (next_business_day.getMonth() == 11) {
					if (next_business_day.getDate() == 24) {
						var hours_left = hours_left + 48;
						var add_me = add_me + 172800000;
						var next_business_day = new Date(add_me);
					}
					else {
						var hours_left = hours_left + 24;
						var add_me = add_me + 86400000;
						var next_business_day = new Date(add_me);
					}
				}
				if (next_business_day.getMonth() != 11) {
					var hours_left = hours_left + 24;
					var add_me = add_me + 86400000;
					var next_business_day = new Date(add_me);
				}
			}
			var output = '<div id="shipping-deadline-container"><div class="copy">If you place your order in the next</div><div class="countdown"></div><div class="copy">it will ship on <span>'+ next_business_day.toDateString() +'</span></div><a href="http://www.eventwristbands.com/shipping.html">(Click here for estimated arrival dates)</a></div>';
			$('#productDetail #extraDetails').append(output); 
			$('#shipping-deadline-container div.countdown').countdown({until: next_business_day, format: 'HMS'});
		}
		// It's after 2pm here, and NOT a Friday. Or if it's anytime on a Sunday
		if (our_hour >= 14 && our_day != 5) {
			var hours_left = 24 - our_hour + 13;
			// Today happens to be a holiday:
			if (jQuery.inArray(our_date, our_holidays) != -1 && our_day != 0) {
				if (next_business_day.getMonth() == 11) {
					if (next_business_day.getDate() == 24) {
						var hours_left = hours_left + 48;
					}
					else {
						var hours_left = hours_left + 24;
					}
				}
				if (next_business_day.getMonth() != 11) {
					var hours_left = hours_left + 24;
				}
			}
			var minutes_left = 60 - our_minutes;
			var add_me = hours_left * 3600000 + (minutes_left * 60000) + our_unix + (our_seconds * 1000);
			var next_business_day = new Date(add_me);
			var next_business_date = next_business_day.getMonth() + '/' + next_business_day.getDate();
			
			// The Ship date falls on a holiday
			if (jQuery.inArray(next_business_date, our_holidays) != -1) {
				if (next_business_day.getMonth() == 11) {
					if (next_business_day.getDate() == 24) {
						var hours_left = hours_left + 48;
						var add_me = add_me + 172800000;
						var next_business_day = new Date(add_me);
					}
					else {
						var hours_left = hours_left + 24;
						var add_me = add_me + 86400000;
						var next_business_day = new Date(add_me);
					}
				}
				if (next_business_day.getMonth() != 11) {
					var hours_left = hours_left + 24;
					var add_me = add_me + 86400000;
					var next_business_day = new Date(add_me);
				}
			}
			var output = '<div id="shipping-deadline-container"><div class="copy">If you place your order in the next</div><div class="countdown"></div><div class="copy">it will ship on <span>'+ next_business_day.toDateString() +'</span></div><a href="http://www.eventwristbands.com/shipping.html">(Click here for estimated arrival dates)</a></div>';
			$('#productDetail #extraDetails').append(output); 
			$('#shipping-deadline-container div.countdown').countdown({until: next_business_day, format: 'HMS'});
		}
		// It's before 2pm here, and Friday
		if (our_hour < 14 && our_day == 5 && our_day != 0) {
			var hours_left = 13 - our_hour;
			// Today happens to be a holiday:
			if (jQuery.inArray(our_date, our_holidays) != -1) {
				if (next_business_day.getMonth() == 11) {
					if (next_business_day.getDate() == 24) {
						var hours_left = hours_left + 48;
					}
					else {
						var hours_left = hours_left + 24;
					}
				}
				if (next_business_day.getMonth() != 11) {
					var hours_left = hours_left + 24;
				}
			}
			var minutes_left = 60 - our_minutes;
			var add_me = hours_left * 3600000 + (minutes_left * 60000) + our_unix + (our_seconds * 1000);
			var next_business_day = new Date(add_me);
			var next_business_date = next_business_day.getMonth() + '/' + next_business_day.getDate();
			
			// The Ship date falls on a holiday
			if (jQuery.inArray(next_business_date, our_holidays) != -1) {
				if (next_business_day.getMonth() == 11) {
					if (next_business_day.getDate() == 24) {
						var hours_left = hours_left + 48;
						var add_me = add_me + 172800000;
						var next_business_day = new Date(add_me);
					}
					else {
						var hours_left = hours_left + 24;
						var add_me = add_me + 86400000;
						var next_business_day = new Date(add_me);
					}
				}
				if (next_business_day.getMonth() != 11) {
					var hours_left = hours_left + 24;
					var add_me = add_me + 86400000;
					var next_business_day = new Date(add_me);
				}
			}
			var output = '<div id="shipping-deadline-container"><div class="copy">If you place your order in the next</div><div class="countdown"></div><div class="copy">it will ship on <span>'+ next_business_day.toDateString() +'</span></div><a href="http://www.eventwristbands.com/shipping.html">(Click here for estimated arrival dates)</a></div>';
			$('#productDetail #extraDetails').append(output); 
			$('#shipping-deadline-container div.countdown').countdown({until: next_business_day, format: 'HMS'});
		}
		// It's after 2pm here, and Friday
		if (our_hour >= 14 && our_day == 5 && our_day != 0) {
			var hours_left = 72 - our_hour;
			// Today happens to be a holiday:
			if (jQuery.inArray(our_date, our_holidays) != -1) {
				if (next_business_day.getMonth() == 11) {
					if (next_business_day.getDate() == 24) {
						var hours_left = hours_left + 48;
					}
					else {
						var hours_left = hours_left + 24;
					}
				}
				if (next_business_day.getMonth() != 11) {
					var hours_left = hours_left + 24;
				}
			}	
			var minutes_left = 60 - our_minutes;
			var add_me = hours_left * 3600000 + (minutes_left * 60000) + our_unix + (our_seconds * 1000);
			var next_business_day = new Date(add_me);
			var next_business_date = next_business_day.getMonth() + '/' + next_business_day.getDate();
			
			// The Ship date falls on a holiday
			if (jQuery.inArray(next_business_date, our_holidays) != -1) {
				if (next_business_day.getMonth() == 11) {
					if (next_business_day.getDate() == 24) {
						var hours_left = hours_left + 48;
						var add_me = add_me + 172800000;
						var next_business_day = new Date(add_me);
					}
					else {
						var hours_left = hours_left + 24;
						var add_me = add_me + 86400000;
						var next_business_day = new Date(add_me);
					}
				}
				if (next_business_day.getMonth() != 11) {
					var hours_left = hours_left + 24;
					var add_me = add_me + 86400000;
					var next_business_day = new Date(add_me);
				}
			}
			var output = '<div id="shipping-deadline-container"><div class="copy">If you place your order in the next</div><div class="countdown"></div><div class="copy">it will ship on <span>'+ next_business_day.toDateString() +'</span></div><a href="http://www.eventwristbands.com/shipping.html">(Click here for estimated arrival dates)</a></div>';
			$('#productDetail #extraDetails').append(output); 
			$('#shipping-deadline-container div.countdown').countdown({until: next_business_day, format: 'HMS'});
		}
	}
	// It's a Saturday
	if (our_day == 6) {
		var hours_left = 24 - our_hour + 24 + 13;
		// Today happens to be a holiday:
		if (jQuery.inArray(our_date, our_holidays) != -1) {
			if (next_business_day.getMonth() == 11) {
				if (next_business_day.getDate() == 24) {
					var hours_left = hours_left + 48;
				}
				else {
					var hours_left = hours_left + 24;
				}
			}
			if (next_business_day.getMonth() != 11) {
				var hours_left = hours_left + 24;
			}
		}
		var minutes_left = 60 - our_minutes;
		var add_me = hours_left * 3600000 + (minutes_left * 60000) + our_unix + (our_seconds * 1000);
		var next_business_day = new Date(add_me);
		var next_business_date = next_business_day.getMonth() + '/' + next_business_day.getDate();
		
		// The Ship date falls on a holiday
		if (jQuery.inArray(next_business_date, our_holidays) != -1) {
			if (next_business_day.getMonth() == 11) {
				if (next_business_day.getDate() == 24) {
					var hours_left = hours_left + 48;
					var add_me = add_me + 172800000;
					var next_business_day = new Date(add_me);
				}
				else {
					var hours_left = hours_left + 24;
					var add_me = add_me + 86400000;
					var next_business_day = new Date(add_me);
				}
			}
			if (next_business_day.getMonth() != 11) {
				var hours_left = hours_left + 24;
				var add_me = add_me + 86400000;
				var next_business_day = new Date(add_me);
			}
		}
		var output = '<div id="shipping-deadline-container"><div class="copy">If you place your order in the next</div><div class="countdown"></div><div class="copy">it will ship on <span>'+ next_business_day.toDateString() +'</span></div><a href="http://www.eventwristbands.com/shipping.html">(Click here for estimated arrival dates)</a></div>';
		$('#productDetail #extraDetails').append(output); 
		$('#shipping-deadline-container div.countdown').countdown({until: next_business_day, format: 'HMS'});
	}
  }	
});  

