jQuery(document).ready(function(){
	if(jQuery("#maryland_map")){
		setupMap();
	}
	
	if(jQuery("#course_google_map")){
		setupGoogleMap();
	}
});

function submitCourseSearch(id){
	//get the variables
	var method = jQuery("#"+id).attr("method");
	var search_string = jQuery('#'+id).find(".course_name").val();
	
	//send them
	window.location = method+search_string;
}

function setupMap(){
	jQuery("map[name='mapmap']").find('area').each(function(){
		//get name of image
		var name = jQuery(this).attr('alt').toLowerCase().split(' ').join('_');
		
		//load images
		var image = new Image();
		image.setAttribute('src','/app/modules/courses/images/'+name+'.jpg');
		
		//bind mouseover
		jQuery(this).bind('mouseover',function(){
			swapMap(name);
		});
		
		//bind mouseout
		jQuery(this).bind('mouseout',function(){
			swapMap();
		});
	});
}

function swapMap(image){
	if(image){
		jQuery("#maryland_map").attr('src','/app/modules/courses/images/'+image+'.jpg');
	} else {
		jQuery("#maryland_map").attr('src','/app/modules/courses/images/map.gif');
	}
}

function setupGoogleMap(){
	if(!document.getElementById('course_google_map')) return;
	
	//get latitude and longitude
	var latlng = document.getElementById('course_google_map').getAttribute('rel').split('|');
	
	//remove the attribute
	document.getElementById('course_google_map').setAttribute('rel','')
	
	//get the coords
	var coords = new google.maps.LatLng(latlng[0],latlng[1]);

	//map options
	var map_options = {
		zoom: 11,
		center:coords,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	//setup map
  	var map = new google.maps.Map(document.getElementById("course_google_map"), map_options);
	
	//setup marker
	var marker = new google.maps.Marker({
		position:coords, 
		map: map,
		title:""
	});

}

function checkKeyword(ele,val){
	if(ele.value == ''){
		ele.value = val;
	} else if(ele.value == val){
		ele.value = '';
	}
}
