// JavaScript Document
document.write('<style type="text/css">body { display: none; }</style>');

$(document).ready(function(){
	
	$('style').remove();
	
// Coding for "Coda popups"
	$('input[type=submit]').hover( function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});

	$('div.co-order div').hide();
	
	$('div.co-order form input[type=submit]').val('');
	
	var clearMePrevious = 'Enter your .CO domains for General Availability pre-registration here.\n\n(One per line)';
	$('div.co-order form textarea').html(clearMePrevious);

	$('div.co-order form textarea').focus(function() {
		if($(this).val()==clearMePrevious) {
			$(this).val('');
		}
	});
	
	$('div.co-order li.general h3').before('<span class="arrow"></span>');
	$('div.co-order li.general div').show();
	$('div.co-order form textarea').css('margin-top', '96px');
	$('div.co-order li.general h3').css('background', '#f36f21').addClass('active');
	
	var lastGray = 'rgb(119, 119, 119)';
	$('div.co-order li h3').css('cursor', 'pointer').click( function() {
		if ($(this).next().is(':hidden')) {
			$('div.co-order li span.arrow').remove();
			$('div.co-order div').not(':hidden').slideUp();
			$('div.co-order li h3.active').animate({ backgroundColor: lastGray}, 500).removeClass('active');
			lastGray = $(this).css('background-color');
			$(this).css('background', '#f36f21').addClass('active');
			$(this).next().slideDown();
			$(this).before('<span class="arrow" style="display: none"></span>');
			$('span.arrow').fadeIn('medium');
	
			if ($(this).parent().hasClass('sunrisea')) {
				$('input[name=t]').val('sr');
				clearMePrevious = 'This stage has ended and is no longer available.';
				$('div.co-order textarea').animate({
					marginTop: '0px',
					color: '#aaa'
				}, 500, function() {
					$(this).html(clearMePrevious);
				});
				$('div.co-order form input').fadeOut();
			} else if ($(this).parent().hasClass('sunrise')) {
				$('input[name=t]').val('srb');
				clearMePrevious = 'This stage has ended and is no longer available.';
				$('div.co-order textarea').animate({
					marginTop: '32px',
					color: '#aaa'
				}, 500, function() {
					$(this).html(clearMePrevious);
				});
				$('div.co-order form input').fadeOut();
			} else if ($(this).parent().hasClass('landrush')) {
				$('input[name=t]').val('lr');
				clearMePrevious = 'This stage has ended and is no longer available.';
				$('div.co-order textarea').animate({
					marginTop: '64px',
					color: '#aaa'
				}, 500, function() {
					$(this).html(clearMePrevious);
				});
				$('div.co-order form input').fadeOut();
			} else {
				$('input[name=t]').val('ga');
				clearMePrevious = 'Enter your .CO domains for General Availability pre-registration here.\n\n(One per line)';
				$('div.co-order textarea').animate({
					marginTop: '96px',
					color: '#000'
				}, 500, function() {
					$(this).html(clearMePrevious);
				});
				$('div.co-order form input').fadeIn();
			}
		}
	});

	$('div.co-faq ul li div').hide();
	$('div.co-faq ul li h3').wrapInner('<a href="javascript:void(0)"></a>');
	$('div.co-faq ul li h3 a').prepend('<span class="more">Show</span>');
	$('div.co-faq ul li h3 a').click( function() {
		if ($(this).parent().next().is(':hidden')) {
			$(this).parent().next().slideDown('fast');
			$(this).prev().prev().addClass('click');
		} else {
			$(this).parent().next().slideUp('fast');
			$(this).prev().prev().removeClass('click');
		}
	});

	$('input[type=submit]').hover( function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});

	$('ul.co-launch li').each(function () {
			var distance = 10;
			var time = 250;
			var hideDelay = 200;
	
			var hideDelayTimer = null;
	
			var beingShown = false;
			var shown = false;
			
			$(this).children('h5').css({
				'cursor': 'pointer'
			});
			var trigger = $(this);
			var info = $('.popup', this).css('opacity', 0);
			
			var offset = $(this).offset();
			var ptop = offset.top - 110;
			var pleft = offset.left - 75;
	
			$(this).mouseover(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				if (beingShown || shown) {
					// don't trigger the animation again
					return;
				} else {
					// reset position of info box
					beingShown = true;
	
					info.css({
						top: ptop,
						left: pleft,
						display: 'block'
					}).animate({
						top: '-=' + distance + 'px',
						opacity: 1
					}, time, 'swing', function() {
						beingShown = false;
						shown = true;
					});
				}
	
				return false;
			}).mouseout(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					info.animate({
						top: '-=' + distance + 'px',
						opacity: 0
					}, time, 'swing', function () {
						shown = false;
						info.css('display', 'none');
					});
	
				}, hideDelay);
	
				return false;
			});
		});
	
	var path = location.pathname.substring(1);
	
	if ( path == 'domains/tld_xxx.php') {
	$(".toggle_container").hide();
	$(".toggle_container_ga").hide();

	$("h4.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
return false;
		});
	}

	if ( path == 'domains/tld_co.php') {
		$('ul.co-launch').pngFix();

		jQuery.validator.setDefaults({
			success: "valid"
		});

		$("#co-form").validate({
			rules: {
				email: {
				required: true,
				email: true
				},
				"confirm-email": {
				required: true,
				equalTo: '#email'
				}
			},
			messages: {
				"confirm-email": "Please make sure this matches your email."
			},
			submitHandler: function() {
				var siteid = $('input[name=siteid]').val();
				var email = $('input[name=email]').val();
				
				var params = '?siteid=' + siteid + '&email=' + email;
				
				$.ajax({
					type: "GET",
					url: "https://secure.mydomain.com/marketing/notify/dotco_email.php",
					data: params,
					dataType: "script",
					success: function(result) {
						$('#co-form').fadeOut('fast', function() {
							$('#co-form').html('<div class="success"><strong>Thanks!</strong> ... for requesting more information about the .CO launch. We&rsquo;ll update you the instant we post more information on our site.</div>');
							$('#co-form').fadeIn('fast');
						});
					}
				});
			}
		});
	}

});
