// Javascript
$(document).ready(function(){
	
	//Sponsorenteaser - Animation
	moveSponsorLogos();	
	function moveSponsorLogos(){
		var iHeight = $('#sponsors-teaser #logos img').height();
		var iCnt = iHeight/74 * 3300;
		$('#logos').css( "top" , "0px");
		$('#logos2').css( "top" , iHeight + "px");
		$('#logos').animate({ top:"-" + iHeight + "px" }, iCnt, "linear");
		$('#logos2').animate({ top:"0px" }, iCnt, "linear", function(){ moveSponsorLogos(); })
	}				   
	
	//Gallery Lightbox
	if( $('#gallery div#big a.lightbox').length > 0 ){
		$('#gallery div#big a.lightbox').lightBox({
			txtImage: 'Bild',
			txtOf: 'von',
			imageBtnNext: '/images/gal_next_news.gif',
			imageBtnPrev: '/images/gal_prev_news.gif',
			imageBtnClose: '/images/gal_close.gif',
			imageLoading: '/images/gal_loading.gif',
			imageBlank: '/images/gal_blank.gif'
		});
	}
	
})

//Gallery

var aThumbs = new Array();

function setGalleryThumbArray(sPath) {
	var iIndex = aThumbs.length;
	aThumbs[iIndex] = new Array();
	aThumbs[iIndex][0] = sPath;
}

function showGalPerPage(iPage, iMaxPicPerPage) {
	var iStart = iPage * iMaxPicPerPage;
	var iEnd = iStart + iMaxPicPerPage;
	var sListContent = '';
	var aGalPages = document.getElementsByName('galpage');
	var i = 0;
	for (i = 0; i < aGalPages.length; i++) {
		aGalPages[i].className = "";
		if (i == iPage) {
			aGalPages[i].className = 'gallerypageselected';
		}
	}
	var iImgCnt = 0;
	for (i = iStart; i < iEnd; i++) {
		if (aThumbs[i] != null) {
			iImgCnt++;
			sListContent += '<li><a onClick="switchImg(' + i + ')"><img src="' + aThumbs[i] + '" /></a></li>';
		} else {
			break;
		}
	}

	if (i > iStart && sListContent != '') {
		document.getElementById('thumbnails').innerHTML = sListContent;
	}
}

function switchImg(iImgIndex) {
	$('#gallery div#big div').removeClass('active');
	$('#gallery div#big div#image-' + iImgIndex ).addClass('active');
}


var aGallery = new Array();
var iPicCnt = 0;
function addImageToGal(iCnt, sImage, iWidth, iHeight, sTitle) {
	aGallery[iCnt] = new Array();
	aGallery[iCnt]['src'] = sImage;
	aGallery[iCnt]['width'] = iWidth;
	aGallery[iCnt]['height'] = iHeight;
	aGallery[iCnt]['title'] = sTitle;
}

function showImage4Gal(iCnt) {
	if (iCnt < 0) {
		iCnt = (iPicCnt - 1);
	}
	if (iCnt == iPicCnt) {
		iCnt = 0;
	}

	document.getElementById('fog').style.display = 'block';
	document.getElementById('galleryview').style.display = 'block';
	//document.getElementById('galleryview').style.top = (document.body.clientHeight / 2 - (aGallery[iCnt]['height'] / 2)) + 'px';
	//document.getElementById('galleryview').style.left = (document.body.clientWidth / 2 - (aGallery[iCnt]['width'] / 2)) + 'px';
	var y;
	if (self.pageYOffset) // all except Explorer
	{
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	// Explorer 6 Strict
	{
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		y = document.body.scrollTop;
	}

	document.getElementById('galleryview').style.top = ((screen.availHeight / 2) - (aGallery[iCnt]['height'] / 2) - 100) + 'px';
	//document.getElementById('galleryview').style.top = '10px';
	document.getElementById('galleryview').style.left = (document.body.clientWidth / 2 - (aGallery[iCnt]['width'] / 2)) + 'px';
	document.getElementById('galleryview').style.width = aGallery[iCnt]['width'] + 'px';
	var iHeight = parseInt(aGallery[iCnt]['height']) + 20;
	document.getElementById('galleryview').style.height = iHeight + 'px';
	//document.getElementById('galleryview').innerHTML = '<p><a class="close" href="javascript:closeGal()">X</a></p>';
	document.getElementById('galleryview').innerHTML = '<p><img src="' + aGallery[iCnt]['src'] + '"></p>';
	document.getElementById('galleryview').innerHTML += '<p align="center">' + aGallery[iCnt]['title'] + '</p>';
	document.getElementById('galleryview').innerHTML += '<p style="margin-top: 5px;"><a style="float: left; padding-right: 20px;" href="javascript:showImage4Gal(0)"><img src="images/gal_first.gif" alt="erstes Bild"></a><a style="float: left; padding-right: 10px;" href="javascript:showImage4Gal(' + (iCnt-1) + ')"><img src="images/gal_prev.gif" alt="voriges Bild"></a><a style="float: left; padding-right: 20px;" href="javascript:showImage4Gal(' + (iCnt+1) + ')"><img src="images/gal_next.gif" alt="nächstes Bild"></a><a style="float: left; " href="javascript:showImage4Gal(' + (iPicCnt - 1) + ')"><img src="images/gal_last.gif" alt="letztes Bild"></a><a style="float: right" href="javascript:closeGal()"><img src="images/gal_close.gif" alt="schließen"></a></p>';

}

function closeGal() {
	document.getElementById('fog').style.display = 'none';
	document.getElementById('galleryview').style.display = 'none';
	document.getElementById('galleryview').innerHTML = '';
}

var bSearchBoxCleaned = false;

	function clearSearchBox(sSearchWord) {

		if(!bSearchBoxCleaned && document.getElementById('csq').value == sSearchWord) {
			document.getElementById('csq').value = '';
			bSearchBoxCleaned = true;
		}

	}
	
	function footerHeight() {
		
		var iNewHeight = guiGetDocumentHeight() - (guiGetElementHeight('header') + guiGetElementHeight('navi') + guiGetElementHeight('main'));
		guiSetElementHeight('footer', iNewHeight);
		
	}
	
	function guiGetDocumentHeight() {
		// Browserweiche
		if (self.innerHeight) {
			return self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
			return document.documentElement.clientHeight;
		}
		else if (document.body) {
			return document.body.clientHeight;
		}
	}

	function guiGetDocumentWidth() {
		// Browserweiche
		if (self.innerWidth) {
			return self.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
			return document.documentElement.clientWidth;
		}
		else if (document.body) {
			return document.body.clientWidth;
		}
	}

	function guiGetElementWidth(sID) {
		if(document.getElementById(sID)) {
			if(document.getElementById(sID).style.display != 'none') {
				return document.getElementById(sID).offsetWidth;
			} else {
				return 0;
			}
		}
	}

	function guiGetElementHeight(sID) {
		if(document.getElementById(sID)) {
			if(document.getElementById(sID).style.display != 'none') {
				return document.getElementById(sID).offsetHeight;
			} else {
				return 0;
			}
		}
	}

	function guiGetElementBottom(sID) {
		if(document.getElementById(sID)) {
			return parseInt(guiReplace(document.getElementById(sID).style.bottom, "px", ""));
		} else {
			return 0;
		}
	}

	function guiGetElementTop(sID) {
		if(document.getElementById(sID)) {
			return guiReplace(document.getElementById(sID).style.top, "px", "");
		} else {
			return 0;
		}
	}

	function guiSetElementWidth(sID, iWidth) {
		if(document.getElementById(sID) && iWidth >= 0) {
			document.getElementById(sID).style.width = guiGetPixels(iWidth) + 'px';
		}
	}

	function guiSetElementHeight(sID, iHeight) {
		if(document.getElementById(sID) && iHeight >= 0) {
			document.getElementById(sID).style.height = guiGetPixels(iHeight) + 'px';
		}
	}

	function guiSetElementTop(sID, iTop) {
		if(document.getElementById(sID)) {
			document.getElementById(sID).style.top = guiGetPixels(iTop) + 'px';
		}
	}

	function guiSetElementLeft(sID, iLeft) {
		if(document.getElementById(sID)) {
			document.getElementById(sID).style.left = guiGetPixels(iLeft) + 'px';
		}
	}

	function guiSetElementRight(sID, iRight) {
		if(document.getElementById(sID)) {
			document.getElementById(sID).style.right = guiGetPixels(iRight) + 'px';
		}
	}

	function guiSetElementBottom(sID, iBottom) {
		if(document.getElementById(sID)) {
			document.getElementById(sID).style.bottom = guiGetPixels(iBottom) + 'px';
		}
	}

	function guiSetElementDisplay(sID, sStatus) {
		if(document.getElementById(sID) && (sStatus == '') || (sStatus == 'inline') || (sStatus == 'block') || (sStatus == 'none'))  {
			document.getElementById(sID).style.display = sStatus;
		}
	}

	function guiSetElementClass(sID, sClass) {
		if(document.getElementById(sID))  {
			document.getElementById(sID).className = sClass;
		}
	}

	function guiGetPixels(sPixels) {
		return guiReplace(sPixels);
	}

	function guiReplace(sString, sSearch, sReplace) {
		sReturn = "" + sString;
		while (sReturn.indexOf(sSearch) >- 1) {
			pos= sReturn.indexOf(sSearch);
			sReturn = "" + (sReturn.substring(0, pos) + sReplace +
			sReturn.substring((pos + sSearch.length), sReturn.length));
		}

		return sReturn
	}

	function guiSetElementMarginLeft(sID, iLeft) {
		if(document.getElementById(sID)) {
			document.getElementById(sID).style.marginLeft = guiGetPixels(iLeft) + 'px';
		}
	}

	function guiGetElementMarginLeft(sID) {
		if(document.getElementById(sID)) {
			return guiReplace(document.getElementById(sID).style.marginLeft, "px", "");
		} else {
			return 0;
		}
	}


	function wait(iMSec)
	  {
	  var eDate = null;
	  var eMsec = 0;
	  var sDate = new Date();
	  var sMsec = sDate.getTime();

	  do {
		  eDate = new Date();
		  eMsec = eDate.getTime();

	  } while ((eMsec-sMsec)<iMSec);
	}


//Navigation
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
