﻿$(document).ready(function(){
	sectionsResize();
	$('.slider').nivoSlider({
		directionNav:true, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:true, //1,2,3...
		manualAdvance:true
	});

	sectionsResize();
	$(window).resize(function() {
		sectionsResize();
	});

	$("a[href='#inicio']").hide();
	
	$(window).scroll(
    	function() {
			if  ($(this).scrollTop() == $(document).height() - $(this).height()){
				$("#footer").animate({bottom: "0px" }, {duration:250});
			}
			else {
				$("#footer").stop().animate({ bottom: "-58px" }, {duration:2000});
			}
			var menu = "inicio";
			animateMenu(menu);
		}
	);


	$('.nav a').click(function(e){		
		$.scrollTo( this.hash || 0, 1500);
		e.preventDefault();
	});

	// Map
	$("#static-map").hover(
		function () {
			$(this).remove();
			var elolivo = new google.maps.LatLng(jQuery('#map').attr('data-latitude'), jQuery('#map').attr('data-longitude'));
			var myOptions = {
			  zoom: 17,
			  center: elolivo,
			  mapTypeId: google.maps.MapTypeId.HYBRID
			};
			var map = new google.maps.Map(document.getElementById("map"), myOptions);
			var marker = new google.maps.Marker({
				position: elolivo, 
				map: map, 
				title:"Restaurante El Olivo Cafetería"
			});
		}
	);
	// Map
	
	//Footer
	$("#footer").stop().delay(5000).animate({ bottom: "-58px" }, 2000, function() {});
	
	$("#footer").mouseover(
		function() {
			if  ($(window).scrollTop() != $(document).height() - $(window).height()){
				$("#footer").stop().animate({bottom: "0px" }, {duration:250});
			}
		}
	);			
	$("#footer").mouseout(
		function() {
			if  ($(window).scrollTop() != $(document).height() - $(window).height()){
				$("#footer").stop().animate({ bottom: "-58px" }, {duration:2000});
			}
		}
	);
	
	$("a[rel='galeria']").colorbox({
		current: "{current} / {total}",
		height:"80%",
		opacity:0.7,
		transition:"fade",
		width:"60%"
	});
	
	$("a[rel='pratos']").colorbox({
		current: "{current} / {total}",
		height:"80%",
		opacity:0.7,
		transition:"fade",
		width:"60%"
	});
});



function animateMenu(menu) {
	var scrollposition = $(window).scrollTop();
	var top = $("div[id='"+ menu +"']").offset().top;
	var sectionheight = $("div[id='"+ menu +"']").next().outerHeight();

	if (((top-100) < scrollposition) && ((top+sectionheight-200) > scrollposition)) {
		$("a[href='#"+ menu +"']").fadeOut(500);
	} else {
		$("a[href='#"+ menu +"']").fadeIn(500);
	}		
}

function sectionsResize() {
	var wHeight = $(this).height();

	var sections = new Array("#inicio","#restaurante","#local","#pratos","#ubicacion");

	$.each(sections, function(index, value) {
		var itemHeight = $(value).height();
		var paddingTB = (wHeight - itemHeight) / 2;

		//$(value).css("padding-bottom", paddingTB);
		//$(value).css("padding-top", paddingTB);
		$(value).animate({"paddingBottom": paddingTB}, "slow");
		$(value).animate({"paddingTop": paddingTB}, "slow");

	});
}
