var projectImages;
var TCvisible = 'block';
var ICbackground = 'none';
var maxScrollingHeight = 0;
var F1;
var isGraphic = false;
var scrollVelo = 5;

function init()
{
	projectImages = $('ImageNavigation').getElements('A');
	if(projectImages.length)
	{
		if(location.href.indexOf('graphic') > -1)
			isGraphic =  true;
		for(var no=0; no<projectImages.length; no++)
		{
			if(no == 0 && !isGraphic)
				projectImages[no].addEvent("click", function() {
					showText();
				});
			else
			{
				if(isGraphic)
				{
					projectImages[no].id = (no+1);
				}
				else
				{
					projectImages[no].id = no;
				}
				projectImages[no].addEvent("click", function() {
					showPic(this.id);
				});
			}
		}
	}
	else
	{
		projectImages = $('ImageNavigation').getElements('IMG');
		for(var no=0; no<projectImages.length; no++)
		{
			projectImages[no].addEvents({"mouseover": function() {
				if(this.getProperty('alt') == 'Down')
					scrollDown();
				else
					scrollUp();
				},
				'mouseout': function() {
					stopScrolling();
				}});
		}
		maxScrollingHeight = ($('Text').getCoordinates().height - 300);
	}
}

function startImprint()
{
	$('imprint').addEvent('click', function(event) {
		event.stop();
		var top = Math.floor((window.getCoordinates().height-750)/2);
		if(top < 0)
			top = 0;
		var left = Math.floor((window.getCoordinates().width-400)/2);
		if(left < 0)
			left = 0;
		
		if(!$defined(F1))
		{
			F1 = window.open(this.getProperty('href'), "Fenster1", "width=400,height=750,left="+left+",top="+top);
			F1.focus();
		}
		else
		{
			if(F1.closed)
				F1 = window.open(this.getProperty('href'), "Fenster1", "width=400,height=750,left="+left+",top="+top);
			else
				F1.location.href = this.getProperty('href');
			F1.focus();
		}
	});
}

function showImageNavigation(x)
{
	for(var no=0; no<projectImages.length; no++)
	{
		if(no < x)
		{
			projectImages[no].innerHTML = (no+1) + " &lt; ";
			projectImages[no].removeClass('active');
		}
		else if(no == x)
		{
			projectImages[no].innerHTML = ' ' + (no+1) + ' ';
			projectImages[no].addClass('active');
		}
		else
		{
			projectImages[no].innerHTML = " &gt; " + (no+1);
			projectImages[no].removeClass('active');
		}
	}
}

function showGraphicImageNavigation(x)
{
	x = (x-1);
	for(var no=0; no<projectImages.length; no++)
	{
		if(no < x)
		{
			projectImages[no].innerHTML = (no+1) + " &lt; ";
			projectImages[no].removeClass('active');
		}
		else if(no == x)
		{
			projectImages[no].innerHTML = ' ' + (no+1) + ' ';
			projectImages[no].addClass('active');
		}
		else
		{
			projectImages[no].innerHTML = " &gt; " + (no+1);
			projectImages[no].removeClass('active');
		}
	}
}

function showPic(x)
{
	var img = $("Image");
	img.src = $('Image'+x).getProperty('src');
	img.width = $('Image'+x).getProperty('width');
	img.height = $('Image'+x).getProperty('height');
	var caption = $('Image'+x).getProperty('alt');
	if(caption.indexOf('Image') != -1)
		caption = $('Image1').getProperty('alt');
	if(caption.length && caption.indexOf('Image') == -1)
	{
		var pos = caption.indexOf('||');
		if(pos  != -1)
		{
			var uri = caption.substring(pos+2, caption.length);
			caption = caption.substring(0, pos-1);
			var ltpos = caption.lastIndexOf('|')+1;
			var link = ' <a href="'+ uri + '">' + caption.substring(ltpos, caption.length) + '</a>';
			caption = caption.substring(0, ltpos);
			caption = caption + link;
		}
		$('ImageCaption').innerHTML = caption;
	}
	TCvisible = 'none';
	$('TextContainer').setStyle('display', TCvisible);
	ICbackground = 'none';
	$('ImageCaption').setStyle('background', ICbackground);
	if(isGraphic)
		showGraphicImageNavigation(x);
	else
		showImageNavigation(x)
}

function showText()
{
	TCvisible = (TCvisible == 'block') ? 'none' : 'block';
	ICbackground = (ICbackground == 'none') ? 'url(/all/images/abdeckung.png)' : 'none';
	$('TextContainer').setStyle('display', TCvisible);
	$('ImageCaption').setStyle('background', ICbackground);
	var img = $("Image");
	img.src = $('Image1').getProperty('src');
	img.width = $('Image1').getProperty('width');
	img.height = $('Image1').getProperty('height');
	var caption = $('Image1').getProperty('alt');
	if(caption.length && caption.indexOf('Image') == -1)
	{
		var pos = caption.indexOf('||');
		if(pos  != -1)
		{
			caption = caption.substring(0, pos-1);
		}
		$('ImageCaption').innerHTML = caption;
	}
	showImageNavigation(0)
}

function scrollUp()
{
	 var top = $('Text').getStyle('margin-top').toInt()-scrollVelo;
	 if(Math.abs(top) < maxScrollingHeight)
	 {
		$('Text').setStyle('margin-top', top);
		S = setTimeout("scrollUp()", 20);
	}
	else
		stopScrolling();
}
function scrollDown()
{
	var top = $('Text').getStyle('margin-top').toInt()+scrollVelo;
	 if(top < 10)
	 {
		$('Text').setStyle('margin-top', top);
		S = setTimeout("scrollDown()", 20);
	}
	else
		stopScrolling();
}
function stopScrolling()
{
	clearTimeout(S);
}
