$(document).ready(function() {
	$("html, body").scrollTop(0);

	Cufon.replace('#navigation ul li a', {fontFamily: 'Bodoni Poster Italic'});
	Cufon.replace('.address, .hint, .form-caption', {fontFamily: 'Bodoni Italic'});
	Cufon.replace('.phone, .label', {fontFamily: 'Gotham HTF Book'});
	Cufon.replace('.phone span', {fontFamily: 'Gotham HTF Book Italic'});
	Cufon.replace('.operation-head', {fontFamily: 'Bodoni Recut Black SSi Black Italic'});
	Cufon.replace('.operation', {fontFamily: 'Gotham HTF Book'});
	Cufon.replace('.operation span', {fontFamily: 'Gotham HTF Book Italic'});

	$('#navigation a, .arrow-link, .arrow-link2, .signup-ribbon').bind('click',function(event){
		var $anchor = $(this);
		var hash = $(this).attr('href');
		$('html, body').stop().animate({
		scrollTop: $($anchor.attr('href')).offset().top
		}, 1400, 'easeInOutExpo', function() {
			//window.location.hash = hash;
		});
		event.preventDefault();
	});

	$('.arrow-link').hover( function () {
		$(this).stop().animate({"opacity": 1});
	}, function () {
		$(this).stop().animate({"opacity": 0.25});
	});


	$('.twitter, .facebook').hover( function () {
		$(this).stop().animate({"opacity": 1});
	}, function () {
		$(this).stop().animate({"opacity": 0.50});
	});

	$('#location .signup-ribbon').hover( function () {
		$('#location .signup-ribbon span').stop().animate({"opacity": 0});
	}, function () {
		$('#location .signup-ribbon span').stop().animate({"opacity": 1});
	});

	$('#navigation ul li a').hover( function () {
		$(this).stop().animate({"opacity": 1});
	}, function () {
		if ($(this).hasClass('link-active')) return false;
		$(this).stop().animate({"opacity": 0.25});
	});

	$.waypoints.settings.scrollThrottle = 30; // millisec to check mouse scroll
	$('#navigation').waypoint(function(event, direction) {
		$(this).parent().toggleClass('sticky', direction === "down");
		event.stopPropagation();
	});

	$('#page > div').waypoint({ offset: '50%' });
	$('body').delegate('#page > div', 'waypoint.reached', function(event, direction) {
		var $active = $(this);
		var id =$active.attr('id');
		if (direction === "up") {
			$active = $active.prev();
		}
		if (!$active.length) $active.end();
		$('#navigation .link-active').stop().animate({"opacity": 0.25});
		$('#navigation .link-active').removeClass('link-active');
		$('#navigation a[href=#'+$active.attr('id')+']').addClass('link-active');
		$('#navigation a[href=#'+$active.attr('id')+']').stop().animate({"opacity": 1});
	});


	$(".maillist-form").validate({
		errorPlacement: function(error, element) {},
		invalidHandler: function(form, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				alert ('Please enter all required field.');
			}
		},
		submitHandler: function(form) {
			sendMail();
		}
	});

	// send email
	function sendMail () {
		$('.email-result').html('<img src="images/loading.gif" alt="Sending.." align="bottom"/>');
		var values = $('.maillist-form').serialize();
		$.post("send-email.php", values, function(data){
			var returnError = data;
			if (returnError == 'ok') {
				$('.email-result').html('Message sent. Thank you. We will contact you shortly with more information.');
			} else {
				$('.email-result').html('<span class="error-hint ">Error while sending email. Please try again.</span>');
			}
		});
	}

}); // ready
