var timeout = 300;
var timerref = 0;
var menueeintrag = 0;
function menue_oeffnen() {
	menue_canceltimer();
	menue_schliessen();
	$(this).find('div').eq(0).animate({opacity:0.9},100);
	menueeintrag = $(this).find('div').eq(0).show();
	}
function menue_schliessen() {
	if(menueeintrag) {
		menueeintrag.hide();
		}
	}
function menue_timer() {
	timerref = window.setTimeout(menue_schliessen, timeout);
	}
function menue_canceltimer() {
	if(timerref) {
		window.clearTimeout(timerref);
		timerref = null;
		}
	}





$(document).ready(function() {

	$("a[rel=external]").attr("target", "_blank");

	screen_resize();

	$('.link').bind('mouseover', menue_oeffnen);
	$('.link').bind('mouseout', menue_timer);
	$(document).bind('onclick', menue_schliessen);

	var quant = $("#image > ul > li").length;
	$('.nbrs').text(quant);
	nbr = img_on+1;
	$('.nbr').text(nbr);
    if(quant==1) $('.control').css('visibility','hidden');
	
	var fussnote = $("#image > ul > li > img").eq(img_on).attr('title');
	$('#footer').text(fussnote);
	
	$('.thumbs').click(function() {
		$('#image, #footer, #thumbnails').toggle();
		$('.thumbs > span').toggle();
		});
	

});


$(window).resize(function() {
	screen_resize();
	$('#image').scrollTo( $('#image li:eq('+img_on+')'), 10 );
})		


function screen_resize() {
	
	var screenWidth =  $(window).width();
	var screenHeight =  $(window).height();

	$('.screenWidth').text(screenWidth);
	$('.screenHeight').text(screenHeight);
  
	var divWidth = screenWidth-100;
	var divHeight = divWidth/3*2;
	var marginLeft = 50;
	if((screenHeight-115)<divHeight) {
		divHeight = screenHeight-115;
		divWidth = divHeight/2*3;
		marginLeft = (screenWidth-divWidth)/2;
		}
	var thmbWidth = (divWidth-45)/4;
	var thmbHeight = thmbWidth/3*2;
	$('#main').width(divWidth);
	$('#main').css('margin-left', marginLeft);
	$('#image').height(divHeight);
	$('#image > ul > li').height(divHeight);
	$('#image > ul > li').width(divWidth);
	$('#thumbnails > ul > li').width(thmbWidth);
	$('#thumbnails > ul > li').height(thmbHeight);
	
	
	}
