var imgChatWindow = new Image();
imgChatWindow.src = "img/chwndbg.gif";

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("fast");
		$("#popupContact").fadeIn("fast");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//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+document.body.scrollTop-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	$("#chat_operator").click(
		function(){
			outputPopUp();
		}
	);
});
function outputPopUp(){
	$("<div/>").attr({"id":"popupContact"})
		.css({"display":"none", "position":"fixed", "_position":"absolute", "width":"312px", "height": "168px", "background-image":"url(img/chwndbg.gif)", "z-index":"1010", "padding":"16px"})
		.appendTo("body");

	$("<a/>").attr({"id":"popupContactClose"})
		.css({"display":"block", "font-size":"14px", "line-height":"14px", "right":"6px", "top":"4px", "position":"absolute", "color":"#024124", "font-weight":"700", "cursor":"pointer", "text-decoration":"none"})
		.html("x")
		.click(function(){
			disablePopup();
		})
		.appendTo("#popupContact");

	$("<div/>").attr({"id":"popupContactContent"})
		.css({"display":"block", "font-size":"13px", "line-height":"18px", "padding":"16px 0 0 0"})
		.appendTo("#popupContact");

	var chtoprttxt;
	switch(langString){
		case "en":
			chtoprttxt = "Central Office: Sarabski str., district 657, <br />ZQAN Holding<br /><br />Work time: from 09:00 till 18:00<br /><br />Break time: from 13:00 till 14:00<br /><br />Rest day: Saturday and Sunday";
		break;
		case "az":
			chtoprttxt = "Mərkəzi Ofis: Sarabski küç., məh. 657, <br/>6-cı mərtəbə, ZQAN Holdinq<br /><br />Saat: 09:00-dan 18:00–a qədər<br /><br />Nahar fasiləsi: 13:00 dan – 14:00 dək<br /><br />İstirahət günləri: Şənbə və Bazar";
		break;
		case "ru":
			chtoprttxt = "Центральный Офис: ул. Сарабского, <br />квартал 657, 6-ой этаж, ZQAN Holding<br /><br />Рабочии график: с 09:00 до 18:00<br /><br />Обеденный перерыв: с 13 :00 до 14:00<br /><br />Выходные дни: Суббота и Воскресенье";
		break;
		
	};
		$("<div/>").css({"float":"left", "color":"#0069AD", "position":"absolute", "left":"20px", "padding":"10px 16px 0 0"}).html("<p style='font-size: 13px; line-height: 16px; color: #024124; font-weight: bold'>" + chtoprttxt + "</p>").appendTo("#popupContactContent");

	$("<div/>").attr({"id":"backgroundPopup"})
	.css({"display":"none", "position":"fixed", "_position":"absolute", "width":"100%", "height": "100%", "top":"0", "left":"0", "background":"#000000", "border":"1px solid #cecece", "z-index":"1009"})
	.appendTo("body");

	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	$("#idCloseChat").click(function(){
		disablePopup();
	});
//	$("#popupContactClose").click(function(){
//		disablePopup();
//	});

	centerPopup();
	loadPopup();
}