/* 
Simple JQuery menu.

Copyright 2008 by Marco van Hylckama Vlieg

web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl

Free for non-commercial use
update: change of heart as per blog post here
http://www.i-marco.nl/weblog/archive/2008/05/08/simple_jquery_accordion_menu__
quote: If you want to use this commercially, just go ahead. It's better than all these people emailing me about compensation and then never get back to me. A donation is highly appreciated (at paypal@i-marco.nl) but don't feel obliged. But please, don't write me email promising one when you aren't gonna actually do it. Sorry if this sounds harsh but I'm really disappointed in how people dealt with this.

fyi... I (Paul Wagner) made a donation :)

Mods for timing and color fades by Paul Wagner at Brushfire Collective
web: http://brushfirecollective.com
email: paul@brushfirecollective.com
*/

/*
function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst ul:first').show();
	});
	$('ul.menu li a').click(
		function() {
			$('ul.menu > li').not(this).delay(100).fadeTo(150, .6); 
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp(200);
					
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp(200);
				checkElement.delay(50).slideDown(300).parent().fadeTo(200, 1);
				return false;
			}
		}
	);
	$('ul.menu li a.current').parents('li.menu-top').find('a:first').click();
}
$(document).ready(function() {initMenus();});
*/


//newsletter ajax



$(document).ready(function(){
var url='/campaign_monitor/subscribe/';
var email;
	$('#newsletter').submit(function(){
		
		
		formdiv = $(this);
		responsediv = $("#ajaxresponse");
		errordiv = $("#newsletter .error");
		input=$("#newsletter input:first");
		email=input.val();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		//if empty give empty error
		if (email.length === 0) {
			$(errordiv).html('Please enter your email address').delay(250).show();
			$(input).addClass('form-error');
			return false;
		}
		//if invalid
		else if(!emailReg.test(email)) {
            $(errordiv).html('Please supply a valid email address').delay(250).show();
            $(input).addClass('form-error');
            return false;
        }
        
        else {  
					$("#newsletter div.submit input").addClass('ajax-loader');
        }


		$.getJSON(url+email,function(json){
			$.each(json,function(i,response){
				if(response === true) {
					//if success give confirmation
					$(formdiv).hide();
					$(responsediv).hide().html(email+' has been successfully subscribed to our newsletter.').delay(250).fadeIn();
				} else {
					//if failure likely is invalid email... todo... better error handling
				   $(formdiv).hide();
				   $(responsediv).html('An unknown error occurred. A.P.C. has been notified and will attempt to correct the problem as soon as possible.').delay(250).fadeIn();
			   }
		
			});
		});
	return false; 
	});
	//$('#stores li:first').click().addClass('active');
	
	//selectors menu
	$('html').click(function() {
		$('.selectors ul').removeClass('active');
	});
	$('.selectors ul').click(function(event){
			event.stopPropagation();
			$('.selectors ul').removeClass('active');
			$(this).addClass('active');
	});
	
	
});



