// JavaScript Document

$(document).ready(function() {
        var over;
		
		$(".map3d a,.fac article a").click(function(){

			var full_url = this.href;
	
			var parts = full_url.split("#");
			var trgt = parts[1];

			var target_offset = $('[name='+trgt+']').offset();
			var target_top = target_offset.top;


			$('html, body').animate({scrollTop:target_top}, 500);
			
			return false;
		});

        $('.arr').mouseover(function() {
             
              $(this).parent().css("z-index","1000");
              $(this).animate({
                top: '+=0',
                height: 'toggle'
                 }, 150, function() {
                    $(this).parent().find(".name").animate({
                        top: '-=0',
                        height: 'toggle'
                        }, 150, function() {							
                         if(over!=null){closeFunc(over)};   
						 over = null; 
						 over = $(this).parent();
                    });			 		 
              });
        });
        $(".name").mouseout(function() {		
            //closeFunc($(this).parent())
        });		
        function closeFunc(over){
                                over.find(".name").animate({
                                    top: '+=0',
                                    height: 'toggle'
                                     }, 150, function() {
                                             $(this).parent().find(".arr").animate({
                                                top: '+=0',
                                                height: 'toggle'
                                                 }, 150, function() {
                                                     $(this).parent().css("z-index","999");
                                            });
                                  });
        }
        $("nav li").click(function(){
            window.location = $(this).find('a').attr("href");
        }); 
		
		
}); 



  var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map;
  var marker;
  function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    var myLatlng = new google.maps.LatLng(-36.906520361112044, 174.63691771030426);	
    var myOptions = {
      zoom:14,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: myLatlng
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);	
	
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));	
	
	 marker = new google.maps.Marker({
        position: myLatlng, 
        map: map,
        title:"Studio West"
    }); 
  }   
  function calcRoute() {
	marker.setMap(null);
    var start = document.getElementById("street").value + ", " + document.getElementById("city").value;
    var end = "16-20 Waikaukau Rd, Glen Eden, Auckland, New Zealand";
    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);
      }
    });
  }
