// JavaScript Document

// When the dom is ready
$(function () {
	
	// Add 'Actueel' to main menu
	$('#mainNav>ul>li.first').after('<li class="news"><a href="/nl/news">Actueel</a></li> ');
	$('#news .news').addClass('current');
	// Remove 'Actueel' from metaMenu
	$('#metaMenu li.news').remove();
	// Add spans before and after a href in main menu for corner images
	$('#mainNav>ul>li').prepend('<span class="left"/>').append('<span class="right"/>');
	// Copy current submenu to dedicated container
	$('#subMenu').append($('#mainNav>ul>li.current>ul'));
	
	// select one or more elements to be overlay triggers
	if ($('div.photos').length) {
		var toShowInFancyBox = $('a.trigger');
		toShowInFancyBox.fancybox({
			'titlePosition'	: 'over',
			'onComplete'	:	function () {
				$("#fancybox-wrap").hover(function () {
					$("#fancybox-title").show();
				}, function () {
					$("#fancybox-title").hide();
				});
			}
		});
	}	

	// Print current page when user clicks 'print'
	$('a.printBut').click(function () {
		window.print();
	});
	
	// Support placeholders fon non-webkit browsers		
	if ($('#fromLoc').length) {
		$('input[placeholder]').placeHoldize();
	}
	 
	/* load google map */
	function getDefaultMap() {
		$("#map").gmap3(
			{	action: 'init',
				options: {
					center: [53.322195, 6.857059],
					zoom: 13,
					mapTypeId: google.maps.MapTypeId.ROADMAP,
					mapTypeControl: true,
					mapTypeControlOptions: {
						style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
					},
					navigationControl: true,
					scrollwheel: true,
					streetViewControl: true
				}
			},
			{	action: 'addMarker',
				latLng: [53.322195, 6.857059],
				infowindow: {
					options: {
						content: "Mulder Appingedam<br/>Koningstraat 45, Appingedam"
					}
				},
				map: {
					center: true
				}
			}
		);
	}
	
	function getNewRoute() {
		$('#map').gmap3({
			action: 'getRoute',
			options: {
				origin: $('#fromLoc').val(),
				destination: 'Koningstraat 45, Appingedam',
				travelMode: google.maps.DirectionsTravelMode.DRIVING
		},
		callback: function (results) {
			if (!results) {
				return;
			}
			$(this).gmap3(
			{ action: 'init', 
				options: {
					center: [53.322195, 6.857059],
					zoom: 13,
					mapTypeId: google.maps.MapTypeId.ROADMAP,
					mapTypeControl: true,
					mapTypeControlOptions: {
						style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
					},
					navigationControl: true,
					scrollwheel: true,
					streetViewControl: true
				}
			},
			{ action: 'addDirectionsRenderer',
				options: {
					preserveViewport: false,
					draggable: true,
					directions: results
				}
			},
			{
				action: 'setDirectionsPanel',
				id: 'directionsPanel'
			});
		}
		});
	}
	
	if ($('#map').length) {
		getDefaultMap();
	}
	
	$('#getRouteButton').click(function () {
		getNewRoute();
	});
	
	$(document).ready(function()
	{
	    $("#hidden_link").fancybox({
	         'width' : 900,
	         'height' : 800,
	         'autoScale' : true,
	         'transitionIn' : 'none',
	         'transitionOut' : 'none',
	         'type' : 'iframe'
	    }).trigger('click');	
	});
});

