/*----------------------CUFON-------------------------------------*/

	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('#navi li a',{ fontFamily: 'Steelfish' , hover:true});
	Cufon.replace('a.top',{ fontFamily: 'Steelfish' , hover:true});


$(document).ready(function() {
	noSpam();
	smoothscroll();
	history();
	
	/*--- fancybox ------------------------------------*/
	$("a.zoom2").fancybox({
		'easingIn, easingOut': true, 
		'zoomSpeedIn'		:	500,
		'zoomSpeedOut'		:	500,
		'overlayOpacity'	:	0.2,
		'overlayColor'		:	'#666'
	});
			

	/*--- show alt on hover ------------------------------------*/
	$('.althover')
		.each(function() {
			$(this).parent().append('<div class="alt" style="display:none">' + this.alt + '</div>');
		})
		.mouseenter(function() {
			$(this).siblings('div').show();
		})
		.mouseleave(function() {
			$(this).siblings('div').hide();
		});
});

function history(){
	if($('#history').length == 0){return false;}
	var itemWidth = 335;
	
	
	var $history = $('#history'), height = 0, width = 0;
	$history.append('<ul id="history-years"></ul><div id="history-text-container"><div id="history-text"></div></div><div id="history-img-container"><div id="history-img"></div></div>');
	var $textContainer = $('#history-text-container'), $imgContainer = $('#history-img-container'), $text = $('#history-text'), $img = $('#history-img'), $years = $('#history-years');
	var $items = $history.find('.history-item');

	$items.each(function(){
		var $this = $(this);
		var tmpHeight = $this.height(), year = $this.find('span').text();
		height = tmpHeight > height ? tmpHeight : height;
		width = width + itemWidth;
		
		$this.find('img').attr('year', year).appendTo($img);
		$this.attr('year', year).appendTo($text);
		
		var year = $this.find('span').text();
		$years.append('<li>'+year+'</li>');
	});
	$years.find('li').first().addClass('active');
	$years.wrap('<div id="history-years-container"></div>');
	$years.css('width', $years.find('li').length*50);
	var $images = $img.find('img');
	
	$items.css({
		float: 'left',
		width: itemWidth
	}).find('span').hide();
	$history.css({
		height: height,
		marginTop: 40,
		width: 670,
		position: 'relative'
	});
	var containerMap = {
		width: 335,
		position: 'relative',
		height: height,
		overflow: 'hidden',
		float: 'left'
	};
	var elemMap = {
		width: width,
		position: 'relative',
		height: height
	};
	$textContainer.css(containerMap);
	$imgContainer.css(containerMap);
	$img.css(elemMap);
	$text.css(elemMap);
	$images.wrap('<div class="history-img-item"></div>');
	
	$history.append('<a id="prev" href="#prev">«</a><a id="next" href="#next">»</a>');
	$history.find('#next, #prev').click(function(){
		if($years.is(':animated')){return false;}
		var year = $years.find('.active').text(), nextYear, $next, newMargin, yearsMargin, dir = $(this).attr('id'), $active = $years.find('.active');
		if(dir == 'prev'){
			if($active.prev().length > 0){
				$next = $active.prev();
				nextYear = $next.text();
			}else{
				$next = $years.find('li').last();
				nextYear = $next.text();
			}
			newMargin = year > nextYear ? '+=' + itemWidth : itemWidth - width;
			newMarginImg = year > nextYear ? '+=' + itemWidth : - (itemWidth * ($images.length - 1));
			yearsMargin = year > nextYear ? '+=' + 50 : -(($years.find('li').length - 1) * 50);
		}else{
			if($active.next().length > 0){
				$next = $active.next();
				nextYear = $next.text();
			}else{
				$next = $years.find('li').first();
				nextYear = $next.text();
			}
			newMargin = year < nextYear ? '-=' + itemWidth : 0;
			newMarginImg = newMargin;
			yearsMargin = year < nextYear ? '-=' + 50 : 0;
		}
		$years.find('.active').removeClass('active');
		$next.addClass('active');
		$text.animate({marginLeft: newMargin}, 300);
		$years.animate({marginLeft: yearsMargin}, 300);
		if($img.find('img[year='+nextYear+']').length > 0){
			$img.animate({marginLeft: newMarginImg}, 300);
		}
	});

}

/*-----------------------------------------------------------
    to encrypt e-mail address
    ---------------------------------------------------------*/

function noSpam(){
	$('a.escape').each(function(){
		$(this).find('span').first().html('@');
		$(this).attr('href','mailto:'+$(this).text());
	});
}

// smoothscroll and gototop-button
//	Last changed:	Sebastian Pontow - s.pontow@euroweb.de
function smoothscroll(){$("a[href*=#]").click(function(){if(location.pathname.replace(/^\//,"")==this.pathname.replace(/^\//,"")&&location.hostname==this.hostname){var a=$(this.hash);a=a.length&&a||$("[name="+this.hash.slice(1)+"]");if(a.length){var b=a.offset().top;$("html,body").animate({scrollTop:b},1e3);return false}}})}$.fn.topLink=function(a){a=$.extend({fadeSpeed:200},a);var b;var c=false;var d=$(this);var e=$(window);var f=$(document.body).children(0).position().top;e.scroll(function(){window.clearTimeout(b);b=window.setTimeout(function(){if(e.scrollTop()<=f){c=false;d.fadeOut(a.fadeSpeed)}else if(c==false){c=true;d.stop(true,true).fadeIn(a.fadeSpeed).click(function(){d.fadeOut(a.fadeSpeed)})}},100)})};
