$(document).ready(function(){

	$('.shadow').each(function(el){
		$(this).append("<span>" + $(this).text() + "</span>");
	});
	
	$('div.dropdown a').click(function(el){
		
		el.preventDefault();
		
		if(!$(this).hasClass('date')){
			popup = $(this).next('div');

			if($(this).hasClass('open')){
				$(popup).slideUp('fast');
				$(this).removeClass('open');
			}else{
				$(popup).slideDown('fast');	
				$(this).addClass('open');
			}
			
		}else{
			$(this).next('input').css({ visibility:'visible' }).datepicker('show');
		}
	
		
	});
	
	$('div.dropdown div img').bind('click', function(el){
		
		$(this).parent().removeClass('on');
		$(this).parent().slideUp('fast');
		selections = 0;
		
		$(this).parent().find('input').each(function(el){
			if($(this).is(":checked")) selections++;
		});
		
		var lnk = $(this).parent().parent().parent().find('a:first');
		
		$(lnk).find('span').remove();
		if(selections > 0){		
			$(lnk).append("<span>[ "+ selections +" selected ]</span>");
		}
		
	});
	
	try{
		$('div.dropdown input.datepicker_filter').datepicker({ onClose: function(dateText, inst){ $(this).prev('a.date').append("<span>[ "+ dateText +" ]</span>"); }});		
	}catch(e){}

	try{ $('input.datepicker').datepicker({dateFormat: 'm/d/yy' }); }catch(e){}
	try{ 
		$('div.trail p').hide();
		$('div.trail h4').click(function(el){ $(this).parent().find('p').toggle('fast'); }); 
	}catch(e){}
	
	$('form.remote').remoteForm();
	
	$('div.notice small').click(function(el){
		$(this).parent().fadeOut('slow').slideUp('slow').remove();
	});

	
	
});

function showRelevantRepeatSelect(value){

	$('li.repeat_options').hide();
	$('#repeat_' + value.toLowerCase()).show();

	if (value == 'Yearly') $('#repeat_monthly').show();

	$('#repeat_options').highlight();
}


jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})

jQuery.fn.remoteForm = function() {
  this.submit(function() {
    $.post(this.action, $(this).serialize(), null, "script");
    return false;
  })

  return this;
};

function validateGuideForm(){
	var valid=true;
	valid=($("#guide_form input[name='first_name']").val()=="") ? false : valid ;
	valid=($("#guide_form input[name='last_name']").val()=="") ? false : valid ;
	if ($("#guide_form input[name='email']").val()==""){
		valid = false;
	}
	else{
//		validate email address
	}
	valid=($("#guide_form input[name='street_address']").val()=="") ? false : valid ;
	valid=($("#guide_form input[name='city']").val()=="") ? false : valid ;
	valid=($("#guide_form input[name='state']").val()=="") ? false : valid ;
	valid=($("#guide_form input[name='zip']").val()=="") ? false : valid ;
	
	if (valid == false){
		alert("Please fill all fields");
		return valid;		
	}

}

function validateContactForm(){
	var valid = true;
	valid=($("#email").val()=="") ? false : valid;
	valid=($("#message").val()=="") ? false : valid;
	valid=($("#name").val()=="") ? false : valid;	
	if (valid==false){
		alert("Please fill all fields");
		return valid;		
	}

}





















