var HttpReq;
var BildContainer="";
var IMGCount=0;

function getQuery(Name) {
 var search = Name.toUpperCase() + "=";
 var query = document.location.search.toUpperCase();
   if (query.length > 0) {
      offset = query.indexOf(search);
      if (offset != -1) {
         offset += search.length;
         end = query.indexOf("&", offset);
         if (end == -1)
            end = query.length;
         return unescape(query.substring(offset, end));
      }
   }
 return('');
}

function loadBilder(url) {
	var url='/bilder.asp?f=js&q='+escape(url);
	if (window.XMLHttpRequest) {
		HttpReq = new XMLHttpRequest();
		HttpReq.onreadystatechange = processReqChange;
		HttpReq.open("GET", url, true);
		HttpReq.send(null);
	} else if (window.ActiveXObject) {
		HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		if (HttpReq) {
			HttpReq.onreadystatechange = processReqChange;
			HttpReq.open("GET", url, true);
			HttpReq.send();
		}
	}
}	

function processReqChange() {
	if (HttpReq.readyState == 4) {
		if (HttpReq.status == 200) {
		putBild(HttpReq.responseText);
		}
	}
}


function putBild(Wahl){
 tt='';
 BildContainer= Wahl.split('\n');
 if(BildContainer.length >1) ImgShow();
}

function big(ig){
  var tBild = new Image;
  tBild.src= (ig=="" ? "/img/pixel.gif":ig);
  document.images["bigpic"].src= tBild.src;
}

function ImageInfo(){
 var tt='',td='',n=0,m=0;
 var umb=false;

 if(IMGCount % 9==0){
  start= IMGCount
 }else{
  if(IMGCount-9 >0) start=start
  else start=0
 }

 for (i=start; i< BildContainer.length; i++) {
	ar = BildContainer[i].split("#");
	if(ar[0] !=''){
	 td+='<td><a href="#" onclick="setPic('+i+');big('+"'"+ar[1]+'.jpg'+"'"+');return false"><img class="pic'+(i==IMGCount? 'A':'N')+'" height=75 width=75 src="'+ar[1]+'_s.jpg" title="'+ar[2]+' '+ar[3]+'" alt="'+ar[2]+' '+ar[3]+'"></a>&nbsp;</td>';
	 n++;
	 if(n>2) umb=true,n=0,m++;
	 if(m>2) break;
	}
	if(umb){
	 tt+='<tr>'+td+'</tr>';
	 td='';
	 umb=false;
	}
 }
 tt+='<tr>'+td+'</tr>';
 tt+='<tr><td align=center colspan=3>powered by <a id=ank href="http://www.flickr.com" Target="flickr" Title="weiter Bilder finden Sie bei Flickr.com">flickr.com</a> &copy; F. Kriebus</td></tr>';
 divElement = document.getElementById("ImgBlock");
 if(divElement){
  style = divElement;
  divElement.innerHTML = '';
  divElement.style.visibility = 'hidden';
  divElement.innerHTML = '<table border=0>'+tt+'</table>';
  divElement.style.visibility = 'visible';
 }

}

function setPic(n){
 //alert('Bild: '+n)
 IMGCount=n;
}

function ImgShow(){
if(BildContainer.length >0) {
  if(IMGCount >BildContainer.length) IMGCount=0;
  ar= BildContainer[IMGCount].split("#")
  if(ar==''){
	IMGCount++;
	setTimeout("ImgShow()",1000);
  }else{
   var bSrc= ar[1]+'_m.jpg'
   var bild = new Image;
   bild.onload = function() {
	setTimeout("ImgShow()",5000);
   };
   bild.src =bSrc;
   document.images["TopImage"].src= bild.src;
   ImageInfo();
  }
  IMGCount++
 }
 
}
