// JavaScript Document
$(function() {

	// Add '>>' to various elements
	$('#footer div.col2 li, #footer div.col3 li, #content .column>ul>li>a').prepend('&raquo; ');
	// Add '>' to second level li>a elements
	$('#content .column>ul>li>ul>li>a').prepend('&rsaquo; ');
	// Add '-' to third level li>a elements
	$('#content .column>ul>li>ul>li>ul>li>a').prepend('- ');
	
	
	// Add 'intro' class to first paragraphs -> bold
	$('.col1 p').first().addClass('intro');
	$('.col2 p').first().addClass('intro');
	$('.col1-2 p').first().addClass('intro');
	
	/*/ Toggle 'active' class for menu items on mouse in/out
	$('#mainNav>ul>li').mouseover(function(){
		$(this).toggleClass('active');
	});
	$('#mainNav>ul>li').mouseout(function(){
		$(this).toggleClass('active');
	});*/
	
	// Add 'last' class to last submenu item
	$('#mainNav ul ul li').last().addClass('last');
	
	// Show the headers
	$('#pageHeader #items').hide('fast').show('fast');
	
	// setup ul.tabs from Jquery Tools to work as tabs for each div directly under div.panes
	function JQTslideTabs(){
		$("#home .slideTabs").tabs("#items > .item", {
		
			// enable "cross-fading" effect
			effect: 'fade',
			fadeOutSpeed: 'slow',
			interval: 7000,
		
			// start from the beginning after the last tab
			rotate: true
		
		// use the slideshow plugin. It accepts its own configuration
		}).slideshow({autoplay:true, interval:7000});
	}
	
	if($('#home .slideTabs').length){
		JQTslideTabs();
	}
	
	/* load google map */
	function getDefaultMap(){
		$("#map").gmap3(
			{	action: 'init',
				options:{
					center:[53.415904, 6.692042], //{lat:48.8620722, lng:2.352047, data:'Carrosserie Luchtenberg Uithuizen'}
					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.415904, 6.692042],
				//address: "Edama 4, Uithuizen", 
				infowindow:{
					options:{
						content:"Carrosserie Luchtenberg<br/>Edama 4, Uithuizen"
					}
				},
				map:{
					center: true
				}
			}
		);
	}
	
	function getNewRoute(){
		$('#map').gmap3({
			action:'getRoute',
			options:{
				origin:$('#fromLoc').val(),
				destination:'Edama 4, Uithuizen',
				travelMode: google.maps.DirectionsTravelMode.DRIVING
		},
		callback: function(results){
			if (!results) {return;}
			$(this).gmap3(
			{ action:'init', 
				options:{
					center:[53.415904, 6.692042],
					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();
	});
	
	$('#fromLoc').keyup(function(e) {
		//alert(e.keyCode);
		if(e.keyCode === 13) {
			//alert('Enter key was pressed.');
			getNewRoute();
		}
	});
	
	// select one or more elements to be overlay triggers
	if ($('.trigger').length) {
		var toShowInFancyBox = $('.trigger');
		toShowInFancyBox.fancybox();
	}
		
	
});
