window.imgXxlPopUpUrlBase = '';
window.imgXxlPopUpUrl = '';
window.onload = function ()
{
	/**
	 *  Öffnet externe Links in neuem Fenster, obwohl das absolut scheiße ist!
	 */
	aLinks = document.getElementsByTagName( 'A' );
	for ( i = aLinks.length; i--;  )
	{
		if ( aLinks[i].href.substr( 0, 10 ) == 'javascript' ) { continue; }
		if ( aLinks[i].hostname != window.location.hostname ) { aLinks[i].target = '_blank'; }
	}

	var carlink, carlist = document.getElementById( 'carlist' );
	
	if ( carlist )
	{
		aTbody = carlist.getElementsByTagName( 'TBODY' );
		for ( t = 0; t < aTbody.length; t++ )
		{
			carlist = aTbody[t];
			if ( carlist && carlist.childNodes )
			{
				for ( var i = carlist.childNodes.length; i--; )
				{
					if ( !carlist.childNodes[i].style ) { continue; }
					carlink = carlist.childNodes[i].getElementsByTagName( 'A' );
					if ( carlink[1] && carlink[1].href )
					{
						carlist.childNodes[i].className += ' pointer';
						carlist.childNodes[i].link = carlink[0].href;
						carlist.childNodes[i].target = carlink[0].target;
						carlist.childNodes[i].onclick = function ()
						{
							if ( this.link ) 
							{ 
								if ( !this.target ) 
								{ 
									window.location = this.link; 
								}
								else
								{
									window.open( this.link, '_blank' );
									return false;
								}						
							}
						};
					}
				}		
			}
		}
	}
	// Detailansicht - Bilder
	
	var eImgages;
		
	if ( eImages = document.getElementById( 'images' ) )
	{
		var tmp = eImages.getElementsByTagName( 'UL' )[0];
		window.eImage = eImages.getElementsByTagName( 'IMG' )[0]; // Big image
		var aLinks = tmp.getElementsByTagName( 'A' ); // Thumbnail links
		
		window.iCid = window.location.search.substr( 5 );
		
		// Path to big image
		window.sImgSrcPath = eImage.src.substr( 0, eImage.src.lastIndexOf( '/' ) + 1 );
		
		// Check if "no photo"
		tmp = eImage.src.substr( eImage.src.lastIndexOf( '/' ) + 1, 1 );
		if ( tmp < '0' || tmp > '1' ) { return; }
		
		if ( aLinks.length < 1 ) { return; } // If not at least one Thumbnail
		// Loop through thumbs
		for ( var i = 0; i < aLinks.length; i++ )
		{
			aLinks[i].iImgNr = i;
			aLinks[i].onclick = rotateImage;
			aLinks[i].bigImage = new Image();
			aLinks[i].bigImage.src = sImgSrcPath + i + '.jpg';
		}
	}
	
	// JavaScript XXL-PopUp
	if ( ( eNode1 = document.getElementById( 'xxlpopup' ) ) && eNode1.href )
	{
		window.imgXxlPopUpUrlBase 
			= eNode1.href.replace( /(img=)\d+/, '$1{img}' );
		eNode1.href = 'javascript:popup(\'' + eNode1.href + '\')';
	}
}

function rotateImage ()
{
	eImage.src = this.bigImage.src;
	window.imgXxlPopUpUrl 
		= window.imgXxlPopUpUrlBase.replace( /\{img\}/, this.iImgNr );
	return false;
}

function popup ( sUrl, iWidth, iHeight, sName )
{
	if ( window.imgXxlPopUpUrl ) { sUrl = window.imgXxlPopUpUrl; }
	if ( !iWidth ) { iWidth = 805; }
	if ( !iHeight ) { iHeight = 550; }
	if ( !sName ) { sName = '_POPUP'; }

	winPopUp = window.open(
		sUrl,
		sName,
		"width=" + iWidth + 
		",height=" + iHeight + 
		",scrollbars=0,resizable=1,status=0,location=0,toolbar=0,directories=0,menubar=0" )
		winPopUp.focus();
}

function clearForm ( f ) 
{
	if ( !f.elements ) { return false; }
	for( var i = 0; i < f.elements.length; i++ ) {
		f.elements[i].checked = false;
		f.elements[i].selectedIndex = 0;
	}
	f['ah[Mode]'].value = '';
	return false;
}

