//resize (primoparametro = lo sfondo grigio che e' un div, secondo parametro il div della finestra da centrare);

//gallery_bg background grigio
//gallery_win finestra dettagli
//gallerydet div destinatario



function centra2(tdiv,gallery,dx,dy) {
//	dx = document.getElementById(tdiv).style.width;
//	dy = document.getElementById(tdiv).style.height;
	if (!dx) dx=700;
	if (!dy) dy=200;	

	if ($(gallery)) {
		root = $(gallery);
	} else {
		root = $("gallery_image_img");

	}
	dx=root.width;
	dy=root.height;
	

	var size = get_wsize();
	var scroll = xScrollTop();
	newx = ( (size.x-dx) /2);	
	newy = scroll+(size.y/2)-(dy/2);
	
	$(tdiv).style.top = newy+"px";
	$(tdiv).style.left = newx+"px";
}

function resize2(this_div,centra_div) {
	var size = xDocSize();
	if (document.getElementById(this_div)) {
		document.getElementById(this_div).style.width = size.w+"px";
		document.getElementById(this_div).style.height = size.h+"px";
		centra2(centra_div);
	}
}



gallery_callbig = {
	
	open: function(thisimg, maximg, pathaj, pathimg, modimg){
		resize2("gallery_bg","gallery_win");

		if (!pathaj) {
			pathaj= "_views/v_gallery.php";
		}	

		if (!pathimg) {
			pathimg = "_public/gallery/";
		}	
		if (!modimg) {
			modimg = "."+"jpg";
		}	



		if (thisimg) {
			new Ajax.Request(pathaj, {
				method: "post",
				parameters: { thisimg: thisimg, pathimg:pathimg, modimg:modimg, maximg:maximg},
				onSuccess: function (a) { 
					$("gallerydet").innerHTML = a.responseText
					$("gallerydet").style.visibility = "visible";
					resize2("gallery_bg","gallery_win");

				},
			});

		}

	},

	close: function() {
		$("gallery_bg").style.width = "100%";
		$("gallery_bg").style.height = "100%";
		$("gallerydet").style.visibility="hidden";
	}
}

function centra_dopo(){
	resize2("gallery_bg","gallery_win");
}

function prev_img(a,b) {
	c = a-1;
	gallery_callbig.open(c,b);
}

function next_img(a,b) {
	gallery_callbig.open(a+1,b);
}

function exit_img(a) {
	gallery_callbig.close();
}
