var loadingImg = '/images/loading.gif';
var zoomlink = null;

var curSolution = null;
var curRealisation  = null;

var nbSolution = 4;
var nbRealisation = 5;

function initZoomBox() {
	var loading = new Image();
	loading.src = loadingImg;

	var prevSolution = $('prevzoomSolution');
	if (prevSolution) {
		prevSolution.onclick = function () { getZoom(-1,'Solution'); return false; }
		var nextSolution = $('nextzoomSolution');
		nextSolution.onclick = function () { getZoom(+1,'Solution'); return false; }
	}

	var prevRealisation = $('prevzoomRealisation');
	if (prevRealisation) {
		prevRealisation.onclick = function () { getZoom(-1,'Realisation'); return false; }
		var nextRealisation = $('nextzoomRealisation');
		nextRealisation.onclick = function () { getZoom(+1,'Realisation'); return false; }
	}

	/*
	zoomlink = $('zoomlink');
	cur = $('zoomcur').value;
	*/

}

function getZoom(exp, type) {
	 eval("if (cur"+type+"==null) cur"+type+" = $('ftypes').cur"+type+".value");

	eval("cur"+type+" = (cur"+type+")*1 + (exp)*1;");
	eval("if(cur"+type+"<=0) cur"+type+" = nb"+type+"; else if(cur"+type+">nb"+type+") cur"+type+"=1;");
	var zoomimg = $('zoomimg'+type);
	zoomimg.src = loadingImg;
	
	this.xhttpd = new Ajax();
	this.xhttpd.onsuccess = function(r) {
		var xml = r.responseXML.documentElement;
		eval('$(\'zoomcaption'+type+'\').innerHTML = xml.getElementsByTagName("title")[0].childNodes[0].nodeValue;');			
		eval('zoomimg.src = "/images/'+type.toLowerCase()+'s/"+(cur'+type+'-1)+".jpg"');

		var url = (type=='Realisation')?'/references/realisations.php?id=':'/services/allsolutions.php?id=';
		eval("$('link"+type+"Img').href='"+url+"'+(cur"+type+"-1);");
		eval("$('zoomcaption"+type+"').href='"+url+"'+(cur"+type+"-1);");



	};	
	this.xhttpd.URLString = 'type='+type+'&cur='+eval("cur"+type);
	this.xhttpd.request('/js/ajax/zoom.php', {method: 'POST'});
}


/*
function CallBackRequest() {
	if ( ajaxobj.readyState == 4 ) {
		var items = ajaxobj.responseText.split('#');
		loader = new Image();
		loader.onload = function() {
			var zoomimg = $('zoomimg');
			zoomimg.src = loader.src;
			var zoomcpt = $('zoomcaption');
			zoomcpt.innerHTML = items[1];
			zoomlink.href = './realisations/rea'+cur+'.html';
		}
		loader.src = items[0];
	}
}
*/

addLoadEvent(initZoomBox);