var init3 = false;

function initPubController() {
	// do not init the controller twice
	if (init3) { return false; }
	init3 = true;
	
	$("#popupContact2").live("click", function(){ disablePopup2();});
	$("#backgroundPopup2").live("click", function(){disablePopup2();});

	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){disablePopup2();}
	});
	
	popupStatus = 0;
}


function openPopup(url) {
	if(popupStatus==0){
		var img = new Image();
		img.src = url;
		
		var width = img.width;
		var height = img.height;
		
		var ratio;
		if (width > 900) {
			ratio = 900 / width;
			width = 900;
			height = height * ratio;
		}
		if (height > 700) {
			ratio = 700 / height;
			height = 700;
			width = width * ratio;
		}

		$("#popupContact2").css({
			"width": width,
			"height": height
		});
		
		$("#popupContact2").centerScreen();
		
		$("#popupContact2-content").html("<img src=\"" + url + "\" width=\"" + width + "\" height=\"" + height+ "\" />");
		
		$("#backgroundPopup2").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup2").fadeIn("slow");
		$("#popupContact2").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup2(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup2").fadeOut("slow");
		$("#popupContact2").fadeOut("slow");
		popupStatus = 0;
	}
}

