jQuery(function($) {
	$('#gallery_thumbnails').galleria({
		insert:		"#image_holder",
		clickNext:	false,
		onImage:	function(image,caption,thumb) { // let's add some image effects for demonstration purposes
					// fade in the image and caption
					if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
						image.css('display','none').fadeIn(1000);
					}
					caption.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.5);
					// 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.5';
					// 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.5); } // don't fade out if the parent is active
					)
			}
	});
	$("#gallery_prev").click(function(){
		$.galleria.prev();
		return false;
	});
	$("#gallery_next").click(function(){
		$.galleria.next();
		return false;
	});
	
	var config1 = {    
		sensitivity: 15, // number = sensitivity threshold (must be 1 or higher)   
		over: galleryPrevShow,
		out: galleryPrevHide 
	};
	var config2 = {    
		sensitivity: 15, // number = sensitivity threshold (must be 1 or higher)   
		over: galleryNextShow,
		out: galleryNextHide 
	};

	$("#gallery_prev").hoverIntent(config1);
	$("#gallery_next").hoverIntent(config2);

	$(".overlabel").overlabel();

	var $nav = $("#nav").tabs({ fx: { opacity: 'toggle', duration: 'fast' } });
	$('h1 a, .backto').click(function() { // bind click event to link
	    $nav.tabs('select', 0); // switch to third tab
	    return false;
	});
	
	var options = {
		target:        '#error',   // target element(s) to be updated with server response 
		beforeSubmit:  showRequest,  // pre-submit callback 
		success:       showResponse  // post-submit callback 
    };
	$("#contactform").ajaxForm(options);

});

// Gallery Next/Prev
function galleryPrevShow(navObj) {
	$("#gallery_prev").fadeTo("fast", 1);
}
function galleryPrevHide(navObj) {
	$("#gallery_prev").fadeTo("fast", 0);
}
function galleryNextShow(navObj) {
	$("#gallery_next").fadeTo("fast", 1);
}
function galleryNextHide(navObj) {
	$("#gallery_next").fadeTo("fast", 0);
}

// AJAX Form
function showRequest(formData, jqForm, options) {
	$("#error").hide();
    $("#submit_btn").attr("disabled", "disabled");
    $("#submit_btn").attr("value", "Sending");
}
function showResponse(responseText, statusText)  { 
    $("#error").fadeIn("fast");
    $("#submit_btn").removeAttr("disabled");
    $("#submit_btn").attr("value", "Absenden");
}

// misc functions
function ct( $obj ) {
	$obj.target = '_blank';
}
