$(document).ready(function(){
	$('#callouts img,#home-callouts img').hover(function(){
		$(this).stop().animate({left:0,top:0},150);
	},function(){
		$(this).stop().animate({left:10,top:14},150);
	});
	$('#nav > div').hover(function(){
		var h = 13;
		// h = (number of items * 32) + (number of multi-row items * 20) + 34
		if($(this).is('.services')) h = 182;
		if($(this).is('.pricing')) h = 130;
		if($(this).is('.location')) h = 226;
		$(this).find('.subnav').stop().animate({height:h},500);
	},function(){
		$(this).find('.subnav').stop().animate({height:13},500);
	});
	$('#topnav > li').hover(function(){
		var h = 23 + ($(this).find('li').length*18);
		$(this).siblings('li').find('> a').stop().css({color:'#c7c8ca'});
		$(this).find('div').stop().animate({height:h},500);
	},function(){
		$(this).siblings('li').find('> a').stop().css({color:'#28206c'});
		$(this).find('div').stop().animate({height:0},500);
	});
	$('.d3').each(function(){
		$('<div/>').css({position: 'absolute', right: -9, top: 0, width: '9px', height: 11, background: 'url(/images/tr.png)'}).addClass('notcontent').appendTo($(this));
		$('<div/>').css({position: 'absolute', left: 0, bottom: -11, width: '9px', height: 11, background: 'url(/images/bl.png)'}).addClass('notcontent').appendTo($(this));
	});
	$('#shade').click(function(){
		$('#shade').fadeOut(500);
		$($(this).data('current')).fadeOut(250);
	});
	$('.alt,.expand').each(function(){$(this).find('li:odd').css('background','#e1e0e9');});
	$('#myspot .select .selectbutton, #myspot .select .selected, #reg .select .selectbutton, #reg .select .selected').click(function(){
		var select=$(this).siblings('.choices');
		if(select.height()==0){
			$('.choices').stop().animate({height:0},150);
			select.stop().animate({height:Math.min(200,select.find('li:visible').length*select.find('li:first').height())},150,function(){
				if($(this).height()>=200) select.css({overflowY:'scroll'});
			});
			select.css({borderColor:'#28206c'});
			select.parent().css({borderColor:'#28206c'});
		} else {
			select.stop().animate({height:0},150);
			select.css({borderColor:'#ffffff'});
			select.parent().css({borderColor:'#ffffff'});
		}
		return(false);
	});
	$('#myspot .select li, #reg .select li').click(function(){
		var select = $(this).parent(), merchantid='test';
		var val = $(this).find('span').length?$(this).find('span').html():$(this).html();
		select.siblings('.selected').html($(this).html().replace(/\<span.*span\>/ig,''));
		select.siblings('input').attr('value',val);
		$('#formfile').attr('href','/pdf/authform-'+val+'.pdf');
		$('#googlecheckout').attr('action','https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/'+merchantid);
		$('#buynow').attr('src','https://checkout.google.com/buttons/buy.gif?merchant_id='+merchantid+'&w=117&h=48&style=white&variant=text&loc=en_US');
		select.stop().animate({height:0},150);
		select.css({borderColor:'#fcd647'});
		select.parent().css({borderColor:'#fcd647'});
	});	$('#myspot .region .choices li, #reg .region .choices li').click(function(){
		$('.location .choices .'+($(this).find('span').html())).css({display:'block'});
		$('.location .choices :not(.'+$(this).find('span').html()+')').css({display:'none'});
		var f = $('.location .choices li:visible:first').html();
		$('.location .selected').html(f.replace(/\<span.*span\>/ig,''));
	});
	
	$('#myspot label .north-florida').css({display:'inline'});
	$('#myspot ul .north-florida').css({display:'block'});
});

function box(boxid,h3,region,id,json) {
	$('#shade').data('current',boxid).css({opacity:0,display:'block'}).stop().animate({opacity:.8},500);
	if(!$(boxid).find('.close').length) {
		$('<div class="close">X</div>').css({position: 'absolute', right: 20, top: 25, width: 15, height: 15, fontSize: '15px', fontWeight: 'bold', fontFamily: 'sans-serif', cursor: 'pointer'}).click(function(){
			$('#shade').fadeOut(250);
			$($('#shade').data('current')).fadeOut(250);
		}).appendTo(boxid);
	}
	if(json) $.each(json,function(i,v){
		$(boxid).find('[name='+i+']').attr('value',v);
	});
	if(h3) { $(boxid).find('h3').html(h3); }
	if(region) {
		$('#myspot .region input[name=region]').attr('value',region);
		$('#myspot .region .selected').html(ucwords(region.replace(/\-/g,' ').replace(' and ',' & ')));
		$('#myspot .location .choices .'+region).css({display:'block'});
		$('#myspot .location .choices :not(.'+region+')').css({display:'none'});
	}
	if(id){
		$('#myspot .location input[name=location]').attr('value',id);
		$('#myspot .location .selected').html(ucwords(id.replace(/\-/g,' ').replace(' and ',' & ')));
	}
	$(boxid).css({display:'none',left:'50%'});
	$(boxid).fadeIn(250);
	return(false);
}

function setlocation(region,regionname,id,location) {
	$('#myspotmap',top.document).fadeOut(250);
	$('.region input[name=region]',top.document).attr('value',region);
	$('.region .selected',top.document).html(regionname);
	$('.location input[name=location]',top.document).attr('value',id);
	$('.location .selected',top.document).html(location);
}
function myspotvalidate(frm) {
	var err='';
	if(frm.firstname.value.length<2) err += '- Please enter your First Name\n';				
	if(frm.lastname.value.length<2) err += '- Please enter your Last Name\n';						
	if(!/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.test(frm.birthdate.value)) err += '- Please enter your Date of Birth in mm/dd/yyyy format\n';	
	if(frm.address.value.length<2) err += '- Please your Street Address\n';	
	if(frm.phonetype.value.length<2) err += '- Please choose a Contact Type\n';
	if(frm.phone.value.replace(/[^\d]/g,'').length!=10) err += '- Please enter a valid 10-digit Phone Number\n';
	if(frm.email.value!='') if(!/^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(frm.email.value)) err += '- Email address is not formatted correctly.\n';
	if(frm.region.value.length<2) err += '- Please select a region\n';
	if(frm.location.value.length<2) err += '- Please select a location\n';

    $.ajax({
        url: "/checkcaptcha.php",
        type: "POST",
        data: 'captcha_code=' + frm.captcha_code.value,
        dataType: 'json',
        cache: false,
        error: function(a,b,c){ console.log('wrong'); },
        success: function(json){
            if(json.error_captcha_incorrect || json.error_captcha_missing){
                err += '- Please fill out a correct security code\n';
            }
            if(err=='') { $('.elements,.submit').fadeOut(250); $('#myspot .wait').fadeIn(250); frm.submit(); } else { alert('There has been one or more errors in your form submission.\n\n'+err); return(false); }
        }
    });
    return(false)
}
function zipcodecheck(zipcode){ return(true); if(/^\d\d\d\d\d$/.test(zipcode)) return(true);	alert('Please enter a 5-Digit Zip Code');	return(false);}
function ucwords (str) {return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1){return $1.toUpperCase();});}

