var ie6= document.getElementById&&document.all&&(navigator.appVersion.indexOf("MSIE 6.")!=-1);
var thePos=Dimx=mx= 90, time, picURL, thbURL, picID='', picJumper=false;
var glWerting= new Array(),glNote= new Array();

function dmx(){
	if(picID==""){
		clearTimeout(time);
		return false;
	}
	time= setTimeout('dmx()', 0);
	mx	= Math.round(Dimx+=((thePos)-Dimx)*4/20);
	document.getElementById(picID).style.maxWidth= mx+'px';
	if(mx==thePos) clearTimeout( time );
	if(mx==thePos && thePos==90){ document.getElementById(picID).src= thbURL; leeren(); clearTimeout(time); }
}

function gross(obj, thmb, url){
	if(picID=="" && mx==90){
		picURL= url;
		thbURL= thmb;
		picID = obj.id;
		if(ie6){
			showInfo('<img src="'+picURL+'">');
		}
		else{
			thePos = 400;
			obj.src= picURL;
			dmx();
		}
	}
}

function klein(obj){
	if(ie6){
		clearInfo();
		leeren();
	}
	else{
		thePos= 90;
		dmx();
	}
}

function leeren(){
	picURL='';
	thbURL='';
	picID ='';
}

  function sendEcard(){
	with(document.send_ecard){
		style.display='block';
		nachricht.focus();
	}
  }
  function chooseCard(itemnr,card){
	document.getElementById('bild_card').src= card;
	document.send_ecard.card.value= itemnr;
  }
  function checkEcard(form){
	return (form.nachricht.value!="")
  }
  


  function loc(){
	if(!is_gast){
		var jsPfad= window.location.hash;
			jsPfad= jsPfad.substr(1);
			jsPfad= jsPfad.split(':');
		
		if(jsPfad[0]=='profilbild'){
			for(nr in pb){
				if(jsPfad[1]==pb[nr].id){
					profilDisp('bilder');
					profilbild.zeigen(nr);
					return; break;
				}
			}
			alert('Profilbild Nr.: '+jsPfad[1]+' nicht gefunden!');
		}
		else if(jsPfad=='meineSeite'&&_id('pro_meine')){
			profilDisp('meine');
		}else if(jsPfad=='ecards'){
			profilDisp('ecards');
		}else if(jsPfad=='kontakt'){
			profilDisp('kontakt');
		}else if(jsPfad=='profilbilder'){
			profilDisp('bilder');
		}else if(jsPfad=='aktiv'){
			profilDisp('aktiv');
		}else if(jsPfad=='tags'){
			profilDisp('tags');
		}else if(jsPfad=='freunde'){
			profilDisp('freunde');
			profilLink_vorher= 'freunde';
		}else if(jsPfad=='edit'){
			addEvent(window, 'load', editProfilFreeV2);
		}else{
			profilDisp('main');
		}
	}else{
		profilDisp('main');
	}
	_id('profilLink_'+profilLink_vorher).className='open';
	return false;
  }
  
  var songtick, songtickpos=2;
  function songticker(d){
  	if(document.getElementById('songticker')&&psm!=""){
	  document.getElementById('songticker').parentNode.style.lineHeight= '1.4';
	  document.getElementById('songticker').parentNode.style.marginTop= (songtickpos*-1)+'px';
	  if(d>0) songtick= setInterval(songticker_up,100);
	  if(d<0) songtick= setInterval(songticker_down,100);
	}
  }
  function songticker_up(){
  	if(songtickpos<31){
		songtickpos++;
		document.getElementById('songticker').parentNode.style.marginTop= parseInt(songtickpos*-1)+'px';
	}else{
		clearInterval( songtick );
		setTimeout('songticker(-1)', 5000);
	}
  }
  function songticker_down(){
  	if(songtickpos>2){
		songtickpos--;
		document.getElementById('songticker').parentNode.style.marginTop= parseInt(songtickpos*-1)+'px';
	}else{
		clearInterval( songtick );
		setTimeout('songticker(1)', 5000);
	}
  }
  
  function switchTagView(lnk){
	if(lnk.parentNode.className.indexOf('open')>-1){
		lnk.parentNode.className= lnk.parentNode.className.replace('open', '');
	}else{
		lnk.parentNode.className+= ' open';
	}
  }
  function tagMenu(typ,tag){
	  var str= '<b><a href="ort/stadtzentrum/einwohner/tag/'+typ+'/'+tag+'" class="icon" style="background-image:url(icon[tags|find])">Wer hat den Tag auch?</a></b><hr><a href="javascript:// In mein Profil übernehmen" onClick="addToMyTags('+typ+',\''+tag+'\')" class="icon" style="background-image:url(icon[tag|add])">In mein Profil übernehmen</a>';
	  contextmenu(str);
	  return false;
  }
  
  
  
 // Profilbilder
	var profilbild= new Object();
		profilbild.vorgang= 'vonÜbersicht';
		profilbild.offen= 0;
	
 // Übersicht
	profilbild.uebersicht= function(){
		var ausgabe= '<table style="border-collapse:separate;border-spacing:9px;margin:auto"><tr>';
		for(var i=1; i<=pb.length; i++){
			ausgabe	+= '<td class="pPicThmb" onClick="profilbild.zeigen('+(i-1)+')"><img src="'+pb[i-1].thumbnail.src
			ausgabe += '" title="'+pb[i-1].titel+'"></td>';
			if(i%6==0&&i!=pb.length) ausgabe+= '</tr><tr>';
			if(i==pb.length) ausgabe+= '</tr>';
		}
		_id('profilbild_container').style.height= 'auto';
		_id('profilbild_container').innerHTML= ausgabe+'</table>';
		profilbild.vorgang= 'vonÜbersicht';
		
		_id('picDetails').style.display='none';
		_id('picKommentare').style.display='none';
	};
	
 // Anzeigen
	profilbild.zeigen= function(nr){
		var p= pb[nr];
		if(!p.bild){
			p.bild= new Image();
			p.bild.src= 'gfx/user/'+p.id+'.jpg';
			p.bild.onload= function(){
				profilbild.geladen(nr);
				document.body.className= '';
			}
			document.body.className= 'ajaxwait';
		}else{
			profilbild.geladen(nr);
		}
		profilbild.offen= nr;
	};
	
 // Geladen zum Anzeigen
	profilbild.geladen= function(nr){
		if(profilbild.vorgang=='vonÜbersicht'){
			_id('profilbild_container').innerHTML+='<table id="picViewer_slider"><tr>'+
			'<td id="picViewer_links" class="picViewer_slider_td"></td>'+
			'<td id="picViewer_mitte" class="picViewer_slider_td"><img src="'+pb[nr].bild.src+'" id="picViewer_mitte_img">'+
			'<table id="picViewerTabelle" onContextmenu="return false"><tr>'+
			'<td id="showPrevPicture"><a onClick="profilbild.zurueck();this.blur()" href="javascript://" title="Vorheriges Bild"></a></td>'+
			'<td><a id="showOverview" onClick="profilbild.hoch();this.blur()" href="javascript://" title="Bilder Übersicht"></a></td>'+
			'<td id="showNextPicture"><a onClick="profilbild.weiter();this.blur()" href="javascript://" title="Nächstes Bild"></a></td>'+
		    '</tr></table></td>'+
			'<td id="picViewer_rechts" class="picViewer_slider_td"></td>'
			+'</tr></table>';
			_id('profilbild_container').style.overflow= 'hidden';
			_id('profilbild_container').style.height= _id('profilbild_container').firstChild.clientHeight+'px';
			animate(
				_id('profilbild_container').firstChild,
				'marginTop',
				0,-_id('profilbild_container').firstChild.offsetHeight,'px',
				50,20,
				function(){
					with(_id('picViewerTabelle').style){
						height= _id('picViewer_mitte_img').clientHeight+'px';
						width= _id('picViewer_mitte_img').clientWidth+'px';
						marginTop= -_id('picViewer_mitte_img').clientHeight+'px';
					}
					_id('profilbild_container').style.height= _id('picViewer_slider').clientHeight+'px';
					profilbild.details(nr);
				}
			);
		}
		else if(profilbild.vorgang=='weiter'){
			_id('picViewer_rechts').innerHTML= '<img src="'+pb[nr].bild.src+'" id="picViewer_rechts_img">';
			animate(
				_id('profilbild_container'),
				'height',
				_id('profilbild_container').clientHeight,
				_id('picViewer_rechts_img').clientHeight+25,'px',
				20,10,
				function(){
					animate(_id('picViewer_slider'), 'marginLeft', -500,-1000,'px',50,20,function(){
						_id('picViewer_mitte_img').src= pb[nr].bild.src;
						_id('picViewer_slider').style["marginLeft"]= '-500px';
						with(_id('picViewerTabelle').style){
							height= _id('picViewer_mitte_img').clientHeight+'px';
							width= _id('picViewer_mitte_img').clientWidth+'px';
							marginTop= -_id('picViewer_mitte_img').clientHeight+'px';
						}
						profilbild.details(nr);
					});
				}
			);
		}
		else if(profilbild.vorgang=='zurueck'){
			_id('picViewer_links').innerHTML= '<img src="'+pb[nr].bild.src+'" id="picViewer_links_img">';
			animate(
				_id('profilbild_container'),
				'height',
				_id('profilbild_container').clientHeight,
				_id('picViewer_links_img').clientHeight+25,'px',
				20,10,
				function(){
					animate(_id('picViewer_slider'), 'marginLeft', -500,0,'px',50,20,function(){
						_id('picViewer_mitte_img').src= pb[nr].bild.src;
						_id('picViewer_slider').style["marginLeft"]= '-500px';
						with(_id('picViewerTabelle').style){
							height= _id('picViewer_mitte_img').clientHeight+'px';
							width= _id('picViewer_mitte_img').clientWidth+'px';
							marginTop= -_id('picViewer_mitte_img').clientHeight+'px';
						}
						profilbild.details(nr);
					});
				}
			);
		}
	};
	
 // Nächstes Bild
	profilbild.weiter= function(){
		var nr= profilbild.offen;
		if(nr>=pb.length-1){
			nr= 0;
		}else{
			nr++;
		}
		profilbild.vorgang= 'weiter';
		profilbild.zeigen(nr);
	}
	
 // Vorheriges Bild
	profilbild.zurueck= function(){
		var nr= profilbild.offen;
		if(nr==0){
			nr= pb.length-1;
		}else{
			nr--;
		}
		profilbild.vorgang= 'zurueck';
		profilbild.zeigen(nr);
	}
	
 // Hoch zur Übersicht
	profilbild.hoch= function(){
		animate(
			_id('profilbild_container').firstChild,
			'marginTop',
			-_id('profilbild_container').firstChild.offsetHeight,0,'px',
			50,20,
			function(){
				_id('profilbild_container').removeChild( _id('profilbild_container').lastChild );
			}
		);
		animate(
			_id('profilbild_container'),
			'height',
			_id('profilbild_container').clientHeight,_id('profilbild_container').firstChild.clientHeight,'px',
			50,20
		);
		profilbild.vorgang= 'vonÜbersicht';
		
		_id('picDetails').style.display='none';
		_id('picKommentare').style.display='none';
	}
	
 // Details laden
	profilbild.details= function(nr){
		_id('picDetails').style.display='block';
		_id('picNote').innerHTML= pb[nr].bewertung;
		if(pb[nr].titel!=""){
			_id('picTitel').innerHTML= pb[nr].titel;
		}else{
			_id('picTitel').innerHTML= '<span style="color:#CCCCCC">(Kein Titel)</span>';
		}
		if(pb[nr].bewertung_aktiv){
			_id('picBewerten').style.display= TBshow;
		}else{
			_id('picBewerten').style.display= 'none';
		}
		if(pb[nr].kommentare_aktiv){
			_id('picKommentare').style.display='block';
			if(typeof pb[nr].kommentare == 'number'){
				_id('picKommentare').innerHTML= '<br><a href="javascript:// Kommentare abrufen?" onClick="profilbild.kommentare()"'+ 
				'style="margin:auto"><b>'+pb[nr].kommentare+'</b> Kommentare verfügbar - Jetzt Anzeigen?</a><br>&nbsp;';
			}
			else if(typeof pb[nr].kommentare == 'string'){
				_id('picKommentare').innerHTML= profilbild.neuer_kommentar + pb[nr].kommentare;
			}
		}
	}
	
 // Kommentare abrufen
	profilbild.kommentare= function(){
		_id('picKommentare').innerHTML= '<br><img src="gfx/16/load.gif"><br>Wird geladen ...<br>&nbsp;';
		ajax(baseURL+"cmd/profilbild_kommentare.php?pic="+pb[profilbild.offen].id, function(re){
			_id('picKommentare').innerHTML= profilbild.neuer_kommentar + re;
			pb[profilbild.offen].kommentare= re;
		});
	}
	profilbild.neuer_kommentar= '<form onSubmit="return profilbild.sende_kommentar(this)" class="neuer_kommentar"><table width="100%"><tr><td rowspan="2" class="kom-name" style="width:50px" valign="top"><img src="http://on-city.com/cmd/userpic.php?id='+id+'&size=a" border=0></td><td class="kom-name" style="padding-left:4px">Neuen Kommentar schreiben:<button tabindex="13" type="submit" name="button">Abschicken</button></td></tr><tr><td class="kom-text"><textarea tabindex="12" name="kommentar" onkeyup="resizeTextbox(this)" onfocus="resizeTextbox(this)"></textarea></td></tr></table></form>';
	
 // Bewertung abgeben
	profilbild.wertung= function(note){
		var bildNr= profilbild.offen;
		ajax(baseURL+"cmd/wertung.php?pic="+pb[profilbild.offen].id+"&note="+note, function(re){
			if(re!=""){
				if(bildNr==profilbild.offen){
					_id('picBewerten').style.display= 'none';
					_id('noteLaden').style.display= 'none';
					_id('picNote').innerHTML= re;
				}
				pb[bildNr].bewertung= re;
				pb[bildNr].bewertung_aktiv= false;
			}else{
				alert("Fehler! Bewertung nicht gespeichert!");
			}
		});
	}
	
 // Kommentar senden
	profilbild.sende_kommentar= function(form){
		if(form.kommentar.value!=""){
			form.button.disabled= true;
			ajax(baseURL+'cmd/pickom.php?bild='+pb[profilbild.offen].id+'&text='+escape(form.kommentar.value), function(re){
				if(re!="SQL-Fehler")
				_id('picKommentare').innerHTML= pb[profilbild.offen].kommentare= '<table width="100%"><tr><td rowspan="2" class="kom-name" style="width:50px" valign="top"><a href="profil/'+nickname+'"><img src="http://on-city.com/cmd/userpic.php?id='+id+'&size=a" border=0></a></td><td class="kom-name" style="font-size:10px;padding-left:4px"><a href="profil/'+nickname+'">'+nickname+'</a></td><td class="kom-name" style="text-align:right;font-size:10px;padding-right:4px">gerade eben</td></tr><tr><td class="kom-text" colspan="2">'+re+'</td></tr></table>' + pb[profilbild.offen].kommentare;
				else alert("Fehler! Kommentar nicht gespeichert!");
			});
		}
		return false;
	}
