/* Author: 

*/

$(document).ready(function() {

	$('.success .sending').delay('1000').animate({'height':'0'}, 600, function() {
		$(this).hide(); 
		$('.success .more').fadeIn('fast');
	});

	
	if( $('body').hasClass('map') ){	
	
	if(window.location.hash)
		var hash = window.location.hash.substring(1);
	else{
		var hash = '';
	}

		$('.program').each(function(){
			$(this).children('.info').data('oHeight', $(this).children('.info').outerHeight())
			var id = $(this).attr('id');
			if(hash != $(this).attr('id')){
				$(this).children('.info').height(0);
			}else{
				$(this).removeClass('closed');
			}
		});
		
		$('.program h2').click(function(){
			var $info = $(this).siblings('.info');
			
			
			
				if( $(this).parent().hasClass('closed')){
					$info.animate({'height':$info.data('oHeight')+'px'}, 600, function() {
						$(this).parent().removeClass('closed');
					});			
					
				}else{
				
					$info.animate({'height':'0'}, 600, function() {
						$(this).parent().addClass('closed');
					});
				}

		}); // end program h2 click
	
		
		//setup the map centered on USA/East Coast
		// cheers http://www.sitepoint.com/embellishing-your-google-map-with-css3-and-jquery/
		var myLatlng = new google.maps.LatLng(37.0625,-89.677068);
		var myOptions = {
		  zoom: 5,
		  center: myLatlng,
			zoomControl: true,
			zoomControlOptions: {
				style: google.maps.ZoomControlStyle.SMALL
			},
			mapTypeControl: false,
			panControl: false,
			streetViewControl: false,
			scrollwheel: false,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
		var pinkParksStyles = [
		                       {
		                         featureType: "all",
		                         stylers: [
		                           { saturation: -80 }
		                         ]
		                       },
		                       {
		                         featureType: "poi.park",
		                         stylers: [
		                           { hue: "#cccccc" },
		                           { saturation: -40 }
		                         ]
		                       }
		                     ];
		

		                     map.setOptions({styles: pinkParksStyles});		
	
		// fetch program locations	
		$.getJSON('/apply/programs/json/true', function(places) {
		var i = 0;
		  $(places).each(function() {  
		  	var place = this; 
		    
			  var marker = new google.maps.Marker({
			    position: new google.maps.LatLng(place.position[0], place.position[1]),  
			    map:      map,  
			    title:    place.title
			  });  // end marker
			   
			  google.maps.event.addListener(marker, 'click', function() {
					var top = $('#' + place.anchor).offset().top;

 					$('#' + place.anchor + ' h2').click();
					
	
				$("html:not(:animated),body:not(:animated)").delay(300).animate({ scrollTop: top},900);
		
			  }); // end event listener
		    
		  });  // end places loop
		}); // end json 
	}
	
}); //document ready end

