//Funzione Adattamento immagini
function image_resize(which, parent, perc, sourcew, sourceh) {
	var elem = document.getElementById(which);

	var oparent = document.getElementById(parent);

	if (elem == undefined || elem == null) return false;
	if (sourcew == null) {
		var orig_width = elem.width;
		var orig_height = elem.height;
	} else {
		var orig_width = sourcew;
		var orig_height = sourceh;
	}
	//vedo se l'immagine è orizzontale... o verticale
	if (orig_width >= orig_height) {
		max = oparent.offsetWidth*perc;
		elem.width = max; elem.height = orig_height*(max/orig_width);
	} else {
		max = oparent.offsetHeight*perc;
		elem.height = max; elem.width = orig_width*(max/orig_height);
	}
}


var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(src){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupDialog").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupDialog").fadeIn("slow");
		$("#popupDialog").fadeIn("slow");
		$("#popupimage").attr("src",src);
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupDialog").fadeOut("slow");
		$("#popupDialog").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(src){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupDialog").height();
	var popupWidth = $("#popupDialog").width();
	//centering
	$("#popupDialog").css({
		"position": "absolute",
		"top": 20,
		"left": windowWidth/2-popupWidth/2,
		"display": "block"
	});
	//only need force for IE6
	$("#backgroundPopupDialog").css({
		"height": windowHeight
	});
	loadPopup(src);
	//image_resize('popupimage', 'popupDialog', 1, width, height);
}
