// Eugen S. - (C) 2008
// ntmb.org

// Objekt Definierung
if (document.getElementById) { // Firefox
	typauswahl=document.getElementById("tooltip");
} 
else if (document.all) { // andere
	typauswahl=document.all.tooltip;
}

function on(id,bg,vote,pfad){
	if(bg==1){ col='99090A'; }
	else if(bg==2){ col='31A039'; }
	else if(bg==3){ col='CC9900'; }
	else if(bg==4){ col='772200'; }
	else if(bg==5){ col='0082FF'; }
	else if(bg==6){ col='1845AD'; }
	else if(bg==7){ col='660066'; }
	else if(bg==8){ col='669966'; }
	else if(bg==9){ col='707070'; }
	else if(bg==10){ col='FF0000'; }
	else if(bg==11){ col='FF3300'; }
	else if(bg==12){ col='CC3300'; } // abenteuer
	else if(bg==13){ col='000099'; }
	else if(bg==14){ col='FC7A2C'; }

	if(pfad==0){
		url='na';
	}
	else {
		url=pfad+'/'+id;
	}

	typauswahl.innerHTML='<img src="'+link+'d/'+url+'.jpg" width="140" height="105" border="0" style="border:#'+col+' 1px solid;background:#e7e7e7;padding:1px"><br><img src="'+link+'picture/vk/'+vote+'.gif" width="52" height="10" alt="Abstimmung" border="0">';
	typauswahl.style.display = "block";
}

function off(){
	typauswahl.style.display = "none";
}

// Ausrichtung
// Quelle: http://www.wendenburg.de/jstipps/mousepos.php
// Quelle: http://de.selfhtml.org/javascript/objekte/event.htm#client_x_y
var docEl = (typeof document.compatMode!="undefined" && document.compatMode!="BackCompat")? "documentElement" : "body";

	document.onmousemove=ausrichten; // Ausrichtung starten

// register event
// capture it for nc 4x (ok it's a dino)
if(document.layers) document.captureEvents(Event.MOUSEMOVE);

function ausrichten(e) {

// position where mousemove fired
var xpos    = document.all ? window.event.x + document.body.scrollLeft : e.pageX;
var ypos    = document.all ? window.event.y + document.body.scrollTop : e.pageY;

// Bild versetzen
xpos+=16;
ypos+=16;

// Displayposition
typauswahl.style.left=xpos+"px";
typauswahl.style.top=ypos+"px";
	
	// for the dino pass event
	if (document.layers) routeEvent(e);
}

// Ajax-Objekt
function ajaxLoad(dataLink,urlParameter,callBack){
	// Quelle: http://developer.mozilla.org/de/docs/AJAX:Getting_Started

	http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} 
	else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	if (!http_request) {
		callBack.setCallBack("");
		return false;
	}

	
	http_request.onreadystatechange = function() {
	
	
		if (http_request.readyState == 4) {
			if (http_request.status == 200) { // Ok
			callBack.setCallBack(http_request.responseText);
			} 
			else {
			callBack.setCallBack("");
			}
		}
		
	};
	http_request.open('POST',dataLink, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(urlParameter);

}


// AJAX Content Box
// Beta
function AjaxHitObject(limit,contentType,className,showKat){

	this.setCallBack=function(callBack){
		if(callBack!=""){ // ok
			this.ajaxcontentDiv.innerHTML='';
			eval(callBack);
			this.ajaxcontentDiv.innerHTML+='<br style="clear:both">';
			this.ajaxIsLoad=0;
		}
	}

	this.ajaxContentLimit=limit;
	this.ajaxContentType=contentType;
	this.ajaxContentshowKat=showKat;
	this.ajaxContentHitKat=1;
	this.boxListWidth=this.ajaxContentLimit*152;
	this.boxListLeftPadding=Math.round((mainSize-this.boxListWidth-64)/2)+32;

	this.setReload=function(hitKat,reload){
		this.ajaxContentPageNow=0;
		this.ajaxIsLoad=0;
		this.ajaxContentHitKat=hitKat;

		if(reload==1){
			document.write('</div></div><div align="center" class="ajaxContentBoxTop">Meiste Zugriffe: <a href="javascript:'+className+'.setKat(1);">Heute</a> - <a href="javascript:'+className+'.setKat(2);">Gestern</a> - <a href="javascript:'+className+'.setKat(3);">Woche</a> - <a href="javascript:'+className+'.setKat(4);">Monat</a> - <a href="javascript:'+className+'.setKat(5);">Gesamt</a><br>'+
					'<div class="haupt" style="background:transparent"><a href="javascript:'+className+'.setPreviousPage();" tilte="Zurück" class="left"><img src="picture/space.gif" width="32" height="120" zurück="Zurück" alt="Zurück" border="0"></a>'+
					'<a href="javascript:'+className+'.setNextPage();" tilte="Weiter" class="right"><img src="picture/space.gif" width="32" height="120" title="Weiter" alt="Weiter" border="0"></a>'+
					'<div id="ajaxContent" style="widh:'+this.boxListWidth+'px;padding-left:'+this.boxListLeftPadding+'px" align="center"></div>'+
				'<br style="clear:both">'+
			'</div></div><div class="haupt"><div class="main">');
			this.ajaxcontentDiv=document.getElementById('ajaxContent');
		}
		
		this.getAjaxEntry(this.ajaxContentPageNow);
	}

	// Zeit-Kategorie setzen
	this.setKat=function(newKat){
		this.ajaxContentHitKat=newKat;
		this.setReload(newKat,0);
	}



	// Umblaettern
	this.setNextPage=function(){	
		if(this.ajaxContentPageNow<4 && this.ajaxIsLoad==0){
			this.ajaxContentPageNow++;
			this.getAjaxEntry(this.ajaxContentPageNow);			
		}
	}
	this.setPreviousPage=function(){	
		if(this.ajaxContentPageNow>0 && this.ajaxIsLoad==0){
			this.ajaxContentPageNow--;
			this.getAjaxEntry(this.ajaxContentPageNow);
		}
	}


	// Ajax 
	this.getAjaxEntry=function(page) {		
		this.ajaxIsLoad=1;
		ajaxLoad('picture/topcontent/ajax.php',"page="+page+"&limit="+this.ajaxContentLimit+"&timekat="+this.ajaxContentHitKat+"&type="+this.ajaxContentType,this);

	}


	this.setContent=function(id,title,linkKat,titleUrlFormat,durchschnitt,pic,target,katTitle,katPicName){

		contentString='<div>';
	
		// Favoriten
		contentString+=getFavBoxBank(id);

		if(this.ajaxContentshowKat==true || target==0){
			katUrl=linkKat+'-fun-links-0';
			if(target!=0){
				if(linkKat=='video')
					katUrl='alle-videos-0';
				else if(linkKat=='spiele')
					katUrl='onlinespiele';
			}
		
			contentString+='<a href="'+katUrl+'.html"><img src="picture/space.gif" border="0" alt="Fun-Links" height="16" width="16" class="bildInfo" style="background-image:url(picture/m/'+katPicName+'.gif)"></a>';
		}
		if(this.ajaxContentshowKat==true && target==0)
			contentString+='<img src="picture/space.gif" border="0" alt="Fun-Link" title="Fun-Link" height="16" width="16" class="bildInfoPartner" style="background-image:url(picture/m/link.gif)">';
	
		contentString+='<a href="'+linkKat+'-'+id+'-'+titleUrlFormat+'.html" title="'+title+'"';
		if(target==0)
			contentString+=' target="_blank"';
		contentString+='><img src="picture/space.gif" width="140" height="105" border="0" alt="'+title+'" class="bild" style="background-image:url(d/'+pic+'/'+id+'.jpg)"></a><br>';
		contentString+='<img src="picture/vk/'+durchschnitt+'.gif" width="52" height="10" border="0"></div>';
		
		this.ajaxcontentDiv.innerHTML+=contentString;
		
		// Favoriten
		setFavBoxStatus(id,iFavContentID);
		iFavContentID++;
	}

	// Starten
	this.setReload(contentType,1);

}

var lFavValues=new Array();
var iFavContentID=1;
var iFavLimit=200;

function loadFavValues()
{
	var value=unescape(CookieLesen('lacheckeFav'));
	errorChars=value.replace(/\,[\d]+/g, '');
	if(errorChars==''){
		lFavValues=value.split(',');
	}
	else{
		CookieSchreiben('lacheckeFav','');
	}
}

loadFavValues();

function setFavBoxStatus(id,contentID)
{
	var bIsExist=false;
	
	for(i=0;i<lFavValues.length;i++){
		if(lFavValues[i]==id)
		{
			bIsExist=true;
			break;
		}
	}
	
	writeFavBoxStatus(id,contentID,bIsExist);

}

function writeFavBoxStatus(id,contentID,bIsExist)
{
	oContentLink=document.getElementById("favID"+contentID);

	writeTitle='aus myFavorites entfernen';
	writePicType='delete';
	if(!bIsExist){
		writeTitle='in myFavorites hinzufügen';
		writePicType='add';
	}
	
	if(oContentLink.title=='') // href nur einmal setzen
	{
		oContentLink.href='javascript:favBoxChange('+id+','+contentID+')';
	}
	oContentLink.innerHTML='<img src="picture/m/'+writePicType+'.gif" border="0" alt="'+writeTitle+'" width="16" height="16" class="bildFav"></a>';
	oContentLink.title=writeTitle;
}

function writeFavBox(id){
	document.write(getFavBoxBank(id));
	setFavBoxStatus(id,iFavContentID);
	iFavContentID++;
}

function getFavBoxBank(id){
	return '<a id="favID'+iFavContentID+'"></a>';
}


function favBoxChange(id,contentID)
{
	favNewValue='';
	bIsExist=false;

	// herausfiltern
	newList=new Array();
	newListNr=0;
	for(i=0;i<lFavValues.length;i++){
		if(lFavValues[i]==id)
		{
			bIsExist=true;
			writeFavBoxStatus(id,contentID,false);
		}
		else
		{
			if(i>0)
			{
				favNewValue+=','+lFavValues[i];
			}
			newList[newListNr]=lFavValues[i];
			newListNr++;
		}
	}
	
	lFavValues=newList;
	
	// neuer Wert ans Ende
	if(!bIsExist){
		if(newList.length<=iFavLimit){
			favNewValue+=','+id;
			lFavValues[newListNr]=id;		
			writeFavBoxStatus(id,contentID,true);
		}
		else {
			alert('Dein Favoritenspeicher ist leider schon voll!');
		}
	}

	CookieSchreiben('lacheckeFav', favNewValue);
}

function CookieSchreiben(n,w)
{
	a = new Date((new Date()).getTime() +1000*60*60*24*365); // 1 Jahr
	document.cookie = n+'='+w+'; expires='+a.toGMTString()+';';
}

function CookieLesen(n)
{
	a = document.cookie;
	while(a != ''){
		cookiename = a.substring(0,a.search('='));
		cookiewert = a.substring(a.search('=')+1,a.search(';'));
		// wenn es der letzte Parameter ist
		if(cookiewert == cookiename+'='){
			cookiewert = a.substring(a.search('=')+1,a.length);
		}
		
		if(cookiename == n){
			return cookiewert;
		}

		// vorderen Teil abschneiden
		i = a.search(';')+2;
		if(i == 0){
			i = a.length
		}
		a = a.substring(i,a.length);
	}
	return '';
}