// Initialize functions

// scrollto animate
function scrollTo(o,s){ var d = $(o).offset().top; $("html:not(:animated),body:not(:animated)").animate({ scrollTop: d}, s); } 

// toggle
$(document).ready(function() {
	var currentPosition;
    $(".toggle").click(function () {
		if($("div.top_hidden").css('top') == '-400px') {
			currentPosition = $(document).scrollTop();
      		$("div.top_hidden").animate({top: '+=400'});
		} else {	
      		$("div.top_hidden").animate({top: '-=400'});
			$("html:not(:animated), body:not(:animated)").animate({ scrollTop: currentPosition}, 300);
		}
    });

// image loaders uitgesckakeld
    var img = new Image();
    $(img).load(function() {
        $(this).css('display', 'none');
        $('#loader').removeClass('loading').append(this);
        $(this).fadeIn('slow');
    }).attr('src', 'img/infographic_werkwijze.png');


  $('a.logo')
	.hover(
      function(){
        $(this).stop()
          .animate({
            'opacity': 0.4
          }, 250);
	  },
	  function(){
        $(this).stop()
          .animate({
            'opacity': 1
          }, 250);
	  }
	);
	
  $('a.button_meer')
	.hover(
      function(){
        $(this).stop()
          .animate({
            'opacity': 0.4
          }, 250);
	  },
	  function(){
        $(this).stop()
          .animate({
            'opacity': 1
          }, 250);
	  }
	);
	
  $('a.button_sluiten')
	.hover(
      function(){
        $(this).stop()
          .animate({
            'opacity': 0.4
          }, 250);
	  },
	  function(){
        $(this).stop()
          .animate({
            'opacity': 1
          }, 250);
	  }
	);
	
	$('a.button_versturen')
	.hover(
      function(){
        $(this).stop()
          .animate({
            'opacity': 0.4
          }, 250);
	  },
	  function(){
        $(this).stop()
          .animate({
            'opacity': 1
          }, 250);
	  }
	);
});

// gmaps + gdirections
var directionDisplay;
	var directionsService = new google.maps.DirectionsService();

	function initialize() {
		var latlng = new google.maps.LatLng(51.837506,5.883398);
		directionsDisplay = new google.maps.DirectionsRenderer();
		var myOptions = {
            scrollwheel: false,
			zoom: 14,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			mapTypeControl: false
		};

		var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
		directionsDisplay.setMap(map);
		directionsDisplay.setPanel(document.getElementById("directionsPanel"));
		var marker = new google.maps.Marker({
			position: latlng, 
			map: map, 
			title:"WD On | Digitale Communicatie"
		}); 

	}

	function calcRoute() {
		var start = document.getElementById("routeStart").value;
		var end = "51.837506,5.883398";
		var request = {
			origin:start,
			destination:end,
			travelMode: google.maps.DirectionsTravelMode.DRIVING
		};

		directionsService.route(request, function(response, status) {
			if (status == google.maps.DirectionsStatus.OK) {
				directionsDisplay.setDirections(response);
			}
		});
	}
