// JavaScript Document
/*
jQuery.easing.bounceout = function(p, n, firstNum, delta, duration) {
	if ((n/=duration) < (1/2.75)) {
		return delta*(7.5625*n*n) + firstNum;
	} else if (n < (2/2.75)) {
		return delta*(7.5625*(n-=(1.5/2.75))*n + .75) + firstNum;
	} else if (n < (2.5/2.75)) {
		return delta*(7.5625*(n-=(2.25/2.75))*n + .9375) + firstNum;
	} else {
		return delta*(7.5625*(n-=(2.625/2.75))*n + .984375) + firstNum;
	}
};
 
jQuery.easing.bouncein = function(x, t, b, c, d) {
	return c - jQuery.easing['bounceout'](x, d-t, 0, c, d) + b;
};*/

var kj_easing = null;
//var kj_easing = "easeOutExpo";

function scrollToPrezzi() {
	// find the scroll element
	var scrollElement = 'html, body';
	$('html, body').scrollTop(1);
	if ($('html').scrollTop() == 1) scrollElement = 'html';
	else if ($('body').scrollTop() == 1) scrollElement = 'body';
	/*$('html, body').scrollTop(0);*/
	$(scrollElement).animate({ scrollTop: Math.round($("#prezzi").offset().top) - 160 }, 1500);

}


$(document).ready( function() {
	/*
		Magic positioning
	*/
	//alert(location.href);
	// add pipes to menu
	$("#menu li:not(:last)").after("<li>|</li>");	
	// find the scroll element
	var scrollElement = 'html, body';
	$('html, body').scrollTop(1);
	if ($('html').scrollTop() == 1) scrollElement = 'html';
	else if ($('body').scrollTop() == 1) scrollElement = 'body';
	$('html, body').scrollTop(0);						
	// setups the scrollable function for the anchored lnks
	$("a[href*=#]").click(function(event) {
		event.preventDefault();
		$(scrollElement).animate({ scrollTop: Math.round($(this.hash).offset().top) - 140 }, 500);
	});
	
	// floating menu 
	$("#menuFloating").css("top",  5000 + "px");
	$("#menuLogo").css("top", 5000 - 135 + "px");
	
	if ($.browser.msie) {
		$("#menuFloating").css("margin-left",  -500 + "px");
		$("#menuLogo").css("margin-left", -500 + "px");
	}
	
	$(window).scroll(function () {
		var top = $(document).scrollTop();
		var bottom = top + $(window).height();
		var where = -1;
		
		var agriturismo = $("#agriturismo").offset().top;
		var iniziative = $("#iniziative").offset().top;
		var prezzi = $("#prezzi").offset().top;
		var press = $("#press").offset().top;
		var links = $("#links").offset().top;
		var contatti = $("#contatti").offset().top;
	
		$("#menuFloating li").removeClass("hilite");
		if (agriturismo > top && agriturismo < bottom) {
			$("#menuFloatingAgriturismo").addClass("hilite");
			where = agriturismo;
		} else if (iniziative > top && iniziative < bottom) {
			$("#menuFloatingIniziative").addClass("hilite");
			where = iniziative;
		} else if (prezzi > top && prezzi < bottom) {
			$("#menuFloatingPrezzi").addClass("hilite");
			where = prezzi;
		} else if (press > top && press < bottom) {
			$("#menuFloatingPress").addClass("hilite");
			where = press;
		} else if (links > top && links < bottom) {
			$("#menuFloatingLinks").addClass("hilite");
			where = links;
		}
		 else if (contatti > top && contatti < bottom) {
			$("#menuFloatingContatti").addClass("hilite");
			where = contatti;
		}
		if (where > 0) {
			$("#menuFloating").stop().animate({top: where}, 150);
			$("#menuLogo").stop().animate({top: where - 135}, 150);
		}
    });
});
