// JavaScript Document
//Created by Dave Alberts

//NOTE THIS IS SITE WIDE JQUERY - INDIVIDUAL JQUERY IS CONTAINED WITHIN SPECIFIC PAGE CLASSES (mysite/code)

 $(document).ready(function(){
//OVERLAY FUNCTIONS

  //Class Descriptions Actions
  $('dt.className').toggle(
  function(){
      $(this).next().css("opacity", 0).slideDown().animate({opacity:1})

  },
  function(){
      $(this).next().animate({opacity:0}).slideUp();
  });

//Class PDF Schedules
   $('h2.emptySched').find('span.clickforPDF').remove();
    $('ul.emptySched').css("opacity", 0).slideDown().animate({opacity:1});
   $('span.clickforPDF').toggle(
   function(){
       $(this).text("Hide the file list").parent().next().css("opacity", 0).slideDown().animate({opacity:1});

   },
   function(){
       $(this).text("Show the file list again").parent().next().animate({opacity:0}).slideUp();;
   }


);

 //Map

$('div#directions').html("<form id='gdir'>Get directions - input your address: <input type='text' name='originLoc' id='originLoc' size=60><br />Are you: <select id='mode'><option value='DRIVING'>Driving</option><option value='WALKING'>Walking</option><option value='BICYCLING'>Bicycling</option></select>  <input type='submit' value='Submit'></form>");
 if ($('#gmap').length) {
var directionDisplay;
var directionsService;
var map;
var marker;
var raintree;
  raintree = new google.maps.LatLng(40.553803,-105.098004);
   directionsDisplay = new google.maps.DirectionsRenderer();
   directionsService = new google.maps.DirectionsService();
    var myOptions = {
      zoom: 16,
      center: raintree,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("gmap"), myOptions);
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));
     marker = new google.maps.Marker({
      position: raintree,
      map: map,
      title:"Raintree Athletic Club"
  });
  $('form#gdir').submit(function(){
   
     calcRoute($('input#originLoc').val());
     return false;
  });
  function calcRoute(origin) {
  var start = origin;
  var end = "2555 S. Shields St. Fort Collins, CO";
    var mode =   document.getElementById("mode").value;

  var request = {
    origin:start,
    destination:end,
    travelMode: google.maps.DirectionsTravelMode[mode]
  };
  directionsService.route(request, function(result, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(result);
    }
  });
}

  }





//CALENDAR FEED DROPS

$('.feedSubscriptions p.feedHeader').toggle(
   function(){
       $(this).text("Hide these subscription options").next('ul').css("opacity", 0).slideDown().animate({opacity:1});

   },
   function(){
       $(this).text("Show me the subscription options again").next('ul').animate({opacity:0}).slideUp();
   }


);







   //END COMMUNICATION
 });
