$(document).ready(function(){
	
	//CountDown
	var austDay = new Date();
	austDay = new Date(austDay.getFullYear() + 1, 0, 26);
	$('#counter').countdown({until: austDay, format: 'd', layout: '{dn}'});
	$('#counter').countdown('pause');
	

	//Cufon
	Cufon.replace('h2, h3, #counter')
	Cufon.now();
	
	
	//Lightbox
	$("a[rel*='lightbox']").lightBox();
	
		//Fancy Box Popups
	$("#n-09").fancybox({
		'overlayColor' : '#000000',
		'overlayOpacity'	: 0.7,
		'padding' :  0,
		'width' : 750,
		'height' : 460,
		'scrolling' : 'no',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});			
	$('#pop-close').click(function() {
  	$.fancybox.close();
	});
	
	// Subscription Validation
	$("#butt-add").click(function() {
		// Set Validation Variables
		var error = 0;
		var msg ='';
		var errormsg = 'Please correct the following issues and try again:\n\n';			
		// Run Checks	
		if (!document.getElementById('htc').checked &&!document.getElementById('updates').checked) { 
			error = 1;
			msg = 'Choose at least one mailing list\n';
			errormsg += msg;
		}						
		// Name
		if (document.getElementById('name').value.length == 0) { 
			error = 1;
			msg = 'Name field cannot be blank\n';
			errormsg += msg;
		}				
		// Email
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value) == false) { 
			error = 1;
			msg = 'Email Address must be valid\n';
			errormsg += msg;	
		}			
		
		// Error
		if (error == 1) {
			alert(errormsg);			
		}
		else {
			
			// Serialize form values to be submitted with POST
			var str = $("#pop-subform").serialize();			
			//Hide the Form
			$("#pop-subform").fadeOut();
			// Submit the form via ajax
			$.ajax({
				url: document.getElementById('cog').value,
				type: "POST",
				data: str,
				success: function(html){
					$("#pop-subthanks").fadeIn();
					setTimeout(function() { $.fancybox.close(); }, 4000);
				}
			});
		}		  	
		return false;														 		
	}); 	

	//Load Popup if cookies enabled and cookie not set
	$.cookie("cookact", 1, { path: '/'});
	if (($.cookie("cookact") == 1) && ($.cookie("popcook") != 1))
	{
		$("#n-09").trigger('click');		
		$.cookie("popcook", 1, { path: '/', expires: 365});
	}

		
	
	
	
	
	
	
	
	
});


function popitup(url) {
	newwindow=window.open(url,'name','height=450,width=580, scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}
