﻿function popup(){
	//SETTING UP OUR POPUP
	
	//loading popup with jQuery magic!
	this.loadPopup = function (){
			$("#backgroundPopup").css({
				"opacity": "0.7"
			});
			$("#backgroundPopup").fadeIn("fast");
			$("#popupContact").fadeIn("fast");
	};
	
	//disabling popup with jQuery magic!
	this.disablePopup = function (){
		//disables popup only if it is enabled
			$("#backgroundPopup").fadeOut("slow");
			$("#popupContact").fadeOut("slow");
	};
	//centering popup
	this.centerPopup = function (){
		//request data for centering
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $("#popupContact").height();
		var popupWidth = $("#popupContact").width();
		//centering
		$("#popupContact").css({
			"position": "absolute",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
		//only need force for IE6
		
		$("#backgroundPopup").css({
			"height": windowHeight
		});
		
	};
};

//CONTROLLING EVENTS IN jQuery
	jQuery(document).ready(function($){
	
	//LOADING POPUP
	//Click the button event!
	$("#newmessage").click(function(){
		var new_popup = new popup();
		//centering with css
		new_popup.centerPopup();
		//load popup
		new_popup.loadPopup();
		var username = $(this).attr("title");
     	$("input#to_id").val(username+',');
		$("input#to_id").attr('readonly','readonly');

	});
	
	$("#fullmessage").click(function(){
		var new_popup = new popup();
		//centering with css
		new_popup.centerPopup();
		//load popup
		new_popup.loadPopup();
	});		
	
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		var new_popup = new popup();
		new_popup.disablePopup();
	});

});