jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
$(document).ready(function(){
		$(document).pngFix(); 
		$('#levels').serialScroll({
			items:'li',
			prev:'#schema div.prev',
			next:'#schema div.next',
			axis:'x',
			offset:-96, //when scrolling to photo, stop 96 before reaching it (from the left)
			duration:1200,
			force:true,
			stop:true,
			lock:false,
			cycle:false,
			easing:'easeOutQuart',
			onBefore:function( e, elem, $pane, $items, pos ){
				var prevText = $items.eq(pos-1).attr('title') || '';
				var nextText = $items.eq(pos+1).attr('title') || '';
				$('#schema div.prev').html('<p>'+prevText+'</p>');
				$('#schema div.next').html('<p>'+nextText+'</p>');
				}
		});

		$("map").tooltip({	
			showURL: false
		 });
		if ($('img[usemap]').length > 0) {
			$('img[usemap]').maphilight();
		};
		if ($('#msg').length > 0) {
			$("#msg").hide();
		};
		var options = { 
			beforeSubmit:function()  //before sending submit, give user notification...
			  {
				$("#form").hide("fast");
				$("#msg").addClass("sending");
			  	$("#msg").html("Sending...");
			  	$("#msg").show("fast");
			  },
		        success:function(rtn) 
			   { 
			    if(rtn=="success")
			    {
			      $("#salu_form").resetForm();
			      $("#sendbutton").hide();
			      $("#msg").removeClass("sending");
			      $("#msg").addClass("success");
			      $("#msg").html("Thank you for your message. We will get back to you as quickly as we can.");
			     }else{
			        //there was an error, so grab the UL in the content ID, 
			        //inside the hidden DIV, and put it into the Message Notification
			      $("#msg").addClass("error");
			      $("#msg").html("Hmm - there was an error in handling your message. Please try again later.");
			     }
			   }
		    };
		if ($("#salu_form").length > 0) {
			$("#salu_form").validate({
			   submitHandler: function(form) {
			   	$(form).ajaxSubmit(options);
			   }
			});
		};
		$('.gallerythumbs').addClass('gallery'); // adds new class name to maintain degradability
		$('ul.gallerythumbs').galleria({
			history   : false, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#main_image', // the containing selector for our main image
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				image.css('display','none').fadeIn(1000);
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				// add a title for the clickable image
				image.attr('title','Next image >>');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				)
			}
		});
	});