//Custom JQUERY script

$(function(){
	
	
	$('#map_canva').css('color','#222');
	
	$('#map_canvas').googleMaps({
		markers: [{
				latitude: 	43.1800,
				longitude:  -83.7113,
				info: {
				    layer: '#address1'
				}
			}
			,{
				latitude: 	42.9649,
				longitude:  -83.7172,
				info: {
				    layer: '#address2'
				}
			},{
				latitude: 	44.3726,
				longitude:  -83.8358,
				info: {
				    layer: '#address3'
				}
			},{
				latitude: 	42.5665,
				longitude:  -83.9070,
				info: {
				    layer: '#address4'
				}
			},{
				latitude: 	46.2034,
				longitude:  -85.5908,
				info: {
				    layer: '#address5'
				}
			},{
				latitude: 	42.2288,
				longitude:  -83.7359,
				info: {
				    layer: '#address6'
				}
		},{
				latitude: 	43.240978,
				longitude:  -86.2036,
				info: {
				    layer: '#address7'
				}
		},{
				latitude: 	43.435457,
				longitude:  -85.283313,
				info: {
				    layer: '#address8'
				}
		},{
				latitude: 	42.327480,
				longitude:  -84.462850,
				info: {
				    layer: '#address9'
				}
		},{
				latitude: 	42.186065,
				longitude:  -86.286072 ,
				info: {
				    layer: '#address10'
				}
		},{
				latitude: 	41.8297222,
				longitude:  -86.2541667,
				info: {
				    layer: '#address11'
				}
		},{
				latitude: 	42.588233,
				longitude:  -83.305598,
				info: {
				    layer: '#address12'
				}
		}
		
		]
	});
	
	
	
	//hide bio if javascript is enabled
	$('p.bio-text').css('display','none');
	
	//Toggle bio text, slidedown if click 1, slideup if click 2
	
	
	$('a.bio-more').toggle(function(e){
		var parent = $(this).parent().parent();
		
		var id = $(this).attr('id') ;
		$('.on').text('View Biography');
		$('.on').removeClass('on');
		
		$(this).text('Close Biography');
		
		if(!id){
			parent.find('p.bio-text').fadeIn();
		}else{
			$(this).addClass('on');
			var content = parent.find('p.bio-text').text();
			$('#text-area').html(content).fadeIn();
		}
		
		e.preventDefault();
	},function(e){
		var parent = $(this).parent().parent();
		
		$('.on').text('Close Biography');
		$('.on').removeClass('active');
		
		$(this).text('View Biography');
		
		var id = $(this).attr('id') ;
		
		if(!id){
			parent.find('p.bio-text').slideUp();
		}else{
			$(this).addClass('on');
			$('#text-area').slideUp();
		}
		e.preventDefault();
	});
	
	
	
	$('#slider').s3Slider({
	timeOut: 6000
	});
	
	//Toggle FAQs question and answers
	$('p.answer').css('display','none');
	
	$('p.question').toggle(function(e){
		var parent = $(this).parent();
		parent.find('p.answer').fadeIn();
	},function(e){
		var parent = $(this).parent();
		parent.find('p.answer').slideUp("medium");
	});
	
	$('a.over').click(function(e){
		
	});
	
	//Enrollment browser side validation
	$('form#enrollment input:submit').click(function(e){
		var error = "";
		//for each for element check name and value
		$('form#enrollment input:text').each(function(i,val){
			var name = $(this).attr('name');
			if(name == 'firstname' || name == 'lastname' || name == 'p_home'){
				var value = $(this).val();
				if(!value){
					//Aplpy red border if empty
					$(this).animate({"border": "1px solid red"});
					error = 1;
				}else{
					//Else return green border
					$(this).animate({"border": "1px solid #648078"});
				}
			}
		});
		
		if(error == 1){
			//If error scroll form to top of the page
			$('html, body').animate({scrollTop:0}, 'slow');
			return false;
		}else{
			//else continue with form submit
			return true;
		}
		
	});
	
	
	
	
	
	//Contact browser side validation
	$('form#contact input:submit').click(function(e){
		var error = "";
		//foreach element check name and value
		$('form#contact input:text').each(function(i,val){
			var name = $(this).attr('name');
			if(name == 'firstname' || name == 'lastname' || name == 'phone' || name == 'email' ){
				var value = $(this).val();
				if(!value){
					//if empty apply red border
					$(this).animate({"border": "1px solid red"});
					error = 1;
				}else{
					//else return green border
					$(this).animate({"border": "1px solid #648078"});
				}
			}
		});
		
		if(error == 1){
			//if error, scroll form to top of the page
			$('html, body').animate({scrollTop:0}, 'slow');
			return false;
		}else{
			//Else continue on with form submit
			return true;
		}
		
	});
		 
		
});

