var js_current_image = 1;

function datosServidor() {
};
datosServidor.prototype.iniciar = function() {
	try {
		// Mozilla / Safari
		this._xh = new XMLHttpRequest();
	} catch (e) {
		// Explorer
		var _ieModelos = new Array(
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;
		for (var i=0;i < _ieModelos.length && !success; i++) {
			try {
				this._xh = new ActiveXObject(_ieModelos[i]);
				success = true;
			} catch (e) {}}
		if ( !success ) {
			return false;
		}
		return true;
	}
}

datosServidor.prototype.ocupado = function() {
	estadoActual = this._xh.readyState;
	return (estadoActual && (estadoActual < 4));
}

datosServidor.prototype.procesa = function() {
	if (this._xh.readyState == 4 && this._xh.status == 200) {
		this.procesado = true;
	}
}

datosServidor.prototype.enviar = function(urlget,datos) {
	if (!this._xh) {this.iniciar();}
	if (!this.ocupado()) {
		this._xh.open("GET",urlget,false);
		this._xh.send(datos);
		if (this._xh.readyState == 4 && this._xh.status == 200) {
			return this._xh.responseText;
		}		
	}
	return false;
}

function _gr(reqseccion,divcont) {
	remotos = new datosServidor;
	nt = remotos.enviar(reqseccion,"");
	document.getElementById(divcont).innerHTML = nt;
}

var urlBase = "update.php?";

function rateImg(rating,imgId)  {
  eval("alreadyRated = picture"+imgId+"_rated;");
  if (alreadyRated == 0) {
		eval("picture"+imgId+"_rated = 1;");
		remotos = new datosServidor;
		nt = remotos.enviar('http://christophsfotoblog.de/blog/update.php?rating='+rating+'&image='+imgId);
    alert("Vielen Dank, deine Stimme wurde gezählt!");
		eval("votes_small_before = document.getElementById('votes_small"+ imgId +"').innerHTML;");
		votes_small_before = parseInt(votes_small_before) + 1;
		eval("document.getElementById('votes_small"+ imgId +"').innerHTML = votes_small_before;");
		eval("document.getElementById('votes_"+ imgId.substr(0,4) +"').innerHTML = votes_small_before;");

		eval("rating_small_before = document.getElementById('rating_small"+ imgId +"').innerHTML;");
    if (rating_small_before == '-') {
      newRating = rating+'.0';
    } else {
      rating_small_before = parseFloat(rating_small_before);
      newRating = roundNumber(((rating_small_before*(votes_small_before-1))+rating)/votes_small_before,1);
    }
		eval("document.getElementById('rating_small"+ imgId +"').innerHTML = newRating;");
		eval("document.getElementById('rating_"+ imgId.substr(0,4) +"').innerHTML = newRating;");
  } else {
    alert('Du hast dieses Bild bereits bewertet.');
  }
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

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];}
}