//onload ausfŸhren

function log() {
    return;
	if (console) {
		if (console.log) {
			console.log(arguments);
		}
	}
}

$(function() {
	//rechte spaltenhöhe anpassen
    var setHeight = function() {
    	var right = $('#rechteSpalte, #perforierung');
    	
    	var wh = $(window).height();
    	var bh = $('body').height();
    	
    	var h = Math.max(wh, bh);
    	
    	right.height(h);
    }
    
    setHeight();
	
	var pfeil = $('#naviPfeil');

	//pfeil am anfang positionieren
	var active = $('li.menu-level1-active');
	if (active.length) {
		var pos = active.position().top - 100;
		var height = active.height() / 2;
		pfeil.css('top', (pos+height)+'px');		
	}
	//animation
	$('#subNavi li').hover(function(){
		var node=$(this);
		var pos = node.position().top - 100;
		var height = node.height() / 2;
		pfeil.stop().animate({top : (pos+height)}, 500, 'swing');
	},function(){
		var node = $('li.menu-level1-active');
		var pos = node.position().top - 100;
		var height = node.height() / 2;
		pfeil.stop().animate({top : (pos+height)}, 500, 'swing');
	})
	//bildgallerie
	var left = $('#bildNaviLinks');
	var right = $('#bildNaviRechts');
	var strip = $('#bildStreifen');
	var mask = $('#bildMaske');
	var step = 560;
	var images = $('.csc-textpic');
	var imageAmount = images.length;
	var currentIndex = 0;
	var speed = 800;
	left.bind('click', function(){
		//var preIndex = currentIndex;
		currentIndex--;
		if (currentIndex < 0) currentIndex = imageAmount-1;
		
		//makenhöhe setzen
		var height = images.eq(currentIndex).height();
		var diff = height - mask.height();
		mask.stop().animate({height : height}, speed, 'swing', setHeight);

		//animacion!
		var toPos = currentIndex * -step;
		strip.stop().animate({left : toPos}, speed, 'swing');
	}).children('a').attr('href', 'javascript:void(0)');
	right.bind('click', function(){
		//var preIndex = currentIndex;
		currentIndex++;
		if (currentIndex >= imageAmount) currentIndex = 0;

		//makenhöhe setzen
		var height = images.eq(currentIndex).height();
		var diff = height - mask.height();
		mask.stop().animate({height : height}, speed, 'swing', setHeight);
		
		//animacion!
		var toPos = currentIndex * -step;
		strip.stop().animate({left : toPos}, speed, 'swing');
	}).children('a').attr('href', 'javascript:void(0)');
	//h2 neu platzieren
	$('#bildStreifen h2').each(function() {
		var node = $(this);
		var target = node.next().children('.csc-textpic-text');
		node.prependTo(target);
	})
	//maskenhoehe am anfang festsetzen

    if (images.length) {
	    mask.height(images.eq(0).height());
    }
});
