$(document).ready(function(){
	
	//input labels	
	//$(":text").labelify();
	

	
	//home
	$('.interactive-image').hover(
		function(){
			$(this).find('div').fadeIn();
		},
		function(){
			$(this).find('div').fadeOut();
		}
	);
	
	//$('h1').fitText();
	
	//interactive
	if ($('body').hasClass('home')){
		$('body').interactive();
	}
	
	
	//scroller
	$('#scroll-nav').scroller();
	
	
	//slideshow
	/*$("#slideshow").easySlider({
		auto: false,
		continuous: true,
		numeric: true
	});*/
	if ($("#slideshow").length > 0){
		$("#slideshow").slides();
	}
	
	
	//footer
	$('#credits').hover(
		function(e){
			$('#credits-info').fadeIn('fast');	
		},
		function(e){
			$('#credits-info').fadeOut('fast');	
		}
	);
	
	
	//filtering
	if ($('.wines-grid').length > 0){

		$('.wines-grid').filtering();
	}
	
	
	//scroll to top
	$("#button-top").bind('click',function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
	
	
	//external links
	$("a").each( function(){
		if ($(this).attr("rel") == "_blank"){
			$(this).attr("target","_blank");
			$(this).addClass("external");
		}
	});
	
	
	//footer, snap to bottom if short page
	var 	h = $('#header').height(), 
		m = $('#main').height(), 
		f = $('#footer').height(),
		d = $(window).height();
		
	if (h + m + f < d){
		$('#main').height( d - h - f );
	}
	
	log(h+' '+m+' '+f+' '+d);

	// google map and directions
	if ($('#map-canvas').length > 0){
		initMap();
	}
		
	function initMap() {
		var 	map,
			marker,
			modus = new google.maps.LatLng(38.364541,-122.3383),
			myOptions = {
				zoom:13,
				mapTypeId: google.maps.MapTypeId.HYBRID,
				center: modus,
				streetViewControl: true
			},
			contentString = ' <h1 id="head1">Modus Operandi Cellars<span id="" class="normal"><br>5225 Solano Ave, Napa, CA 94558</span></h1> ',
			infowindow = new google.maps.InfoWindow({
				content: contentString
			}),
			directionDisplay;
			
		
		map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);  
		marker = new google.maps.Marker({
			position: modus,
			map: map,
			title:"Modus Operandi Cellars"
		});
		google.maps.event.addListener(marker, 'click', function(){
		  infowindow.open(map,marker);
		});
		 
		marker.setMap(map);  
		directionsDisplay = new google.maps.DirectionsRenderer();
		directionsDisplay.setMap(map);
		directionsDisplay.setPanel(document.getElementById("directions-panel"));
	}

	function calcRoute() {
		var start = document.getElementById("start").value,
			end = document.getElementById("end").value,
			directionsService = new google.maps.DirectionsService(),
			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);
		} else {
			alert("A directions request could not be successfully processed");
		}
		});
	}
	
	$('#get-directions').bind('click',function(){
		calcRoute();
	});


});

