$(document).ready(function() {
	// set form field of search to empty depending on focus:
	$("#form_navibox").focus(function() {
		if($(this).val() == "Suchen"){
			oldVal = $(this).val();
			$(this).val('');
		}
	});
	$("#form_navibox").blur(function() {
		if($(this).val() == '')
			$(this).val(oldVal);
	});
	
	// set functionality of font size switcher:
	var contentarea = $("#main");
	var num_ee = contentarea.css('font-size');
	var num_e = parseFloat(num_ee, 10);
	var currentSize = contentarea.css('font-size');	

	$(".switcher a").click(function() {
		var num = parseFloat(currentSize, 10);
		var unit = currentSize.slice(-2);
		$(".switcher a").css('background-position', '0 0');		
		if (this.id == 'linkLarge'){
			num_new = num * 1.2;
			$("#linkLarge").css('background-position', '0 -15px');
		} else if (this.id == 'linkSmall') {
			num_new = num / 1.2;
			$("#linkSmall").css('background-position', '0 -15px');
		} else if (this.id == 'linkDefault') {
			num_new = num_e;
			$("#linkDefault").css('background-position', '0 -15px');
		}
		$("#main").css('font-size', num_new + unit);
		$("#right .content").css('font-size', num_new + unit);
   		return false;
	});
	
	// set gallery functions:
	$('ul.gallery').galleria({
		history   : true, // 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
			
			// fade in the image & caption
			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.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
			)
		}
	});

});
