//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){


	// 	$("#bl2").animate({opacity: "0.01"}, 1)
	// 	$("#bl2").animate({opacity: "0.01"}, 999)
	// 	$("#bl2").animate({opacity: "1"}, 3000)


	$("#knopkatxt1").animate({opacity: "0.01"}, 1)
	$("#knopkatxt2").animate({opacity: "0.01"}, 1)
	$("#knopkatxt3").animate({opacity: "0.01"}, 1)
	$("#knopkatxt4").animate({opacity: "0.01"}, 1)
	$("#knopkatxt5").animate({opacity: "0.01"}, 1)
	$("#knopkatxt6").animate({opacity: "0.01"}, 1)
	$("#knopkatxt7").animate({opacity: "0.01"}, 1)
	$("#knopkatxt8").animate({opacity: "0.01"}, 1)
	$("#knopkatxt9").animate({opacity: "0.01"}, 1)
	$("#knopkatxt10").animate({opacity: "0.01"}, 1)

	$("#knopkatxt1").animate({opacity: "0.01"}, 999)
	$("#knopkatxt2").animate({opacity: "0.01"}, 999)
	$("#knopkatxt3").animate({opacity: "0.01"}, 999)
	$("#knopkatxt4").animate({opacity: "0.01"}, 999)
	$("#knopkatxt5").animate({opacity: "0.01"}, 999)
	$("#knopkatxt6").animate({opacity: "0.01"}, 999)
	$("#knopkatxt7").animate({opacity: "0.01"}, 999)
	$("#knopkatxt8").animate({opacity: "0.01"}, 999)
	$("#knopkatxt9").animate({opacity: "0.01"}, 999)
	$("#knopkatxt10").animate({opacity: "0.01"}, 999)



	$("#knopkatxt1").animate({opacity: "1"}, 1000)
	$("#knopkatxt2").animate({opacity: "1"}, 1000)
	$("#knopkatxt3").animate({opacity: "1"}, 1000)
	$("#knopkatxt4").animate({opacity: "1"}, 1000)
	$("#knopkatxt5").animate({opacity: "1"}, 1000)
	$("#knopkatxt6").animate({opacity: "1"}, 1000)
	$("#knopkatxt7").animate({opacity: "1"}, 1000)
	$("#knopkatxt8").animate({opacity: "1"}, 1000)
	$("#knopkatxt9").animate({opacity: "1"}, 1000)
	$("#knopkatxt10").animate({opacity: "1"}, 1000)


	 	$("#bl4").animate({opacity: "0.01"}, 1)
	 	$("#bl4").animate({opacity: "0.01"}, 999)
	 	$("#bl4").animate({opacity: "1"}, 1000)
//	 	$("#bl3").animate({opacity: "1"}, 1000)



	//	popupStatus = 1;
	}
}


function loadPopup2(){
	//loads popup only if it is disabled
	if(popupStatus==0){





	 	$("#bl4").animate({opacity: "0.01"}, 1)
	 	$("#bl4").animate({opacity: "0.01"}, 999)
	 	$("#bl4").animate({opacity: "1"}, 1000)
//	 	$("#bl3").animate({opacity: "1"}, 1000)



	//	popupStatus = 1;
	}
}





//disabling popup with jQuery magic!
function disablePopup(){

 // alert(1);



	//disables popup only if it is enabled
	if(popupStatus==1){


   //     $("#ppp").animate({opacity: "1"}, 1000)
//	    $("#ppp").fadeOut("slow");

   //     $("#bx").animate({opacity: "1", left: "0", top: "0", height: "1", width: "1"}, 0)
	 //   $("#bx").fadeOut("slow");
    //    $("#backgroundPopup").fadeOut("slow");
	//	$("#popupContact").fadeOut("fast");

	//	 alert("Ваша страница зарегистрированна. Для добавления и изменения информации зайдите на свою страницу в раздел редактировать анкету.");
   //          $("#divcenter").animate({opacity: "1"}, 1000)       //text на сртанице

   //     $("#divcenter").animate({opacity: "0.02"}, 2000)    //text на сртанице
	//	$("#divcenter").animate({opacity: "1"}, 1000)       //text на сртанице

   //  document.getElementById("reg").style.display = 'none';
  //   document.getElementById("ssilkaanketa").style.display = 'none';

		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){

   var windowWidth = document.body.clientWidth;
   var windowHeight = document.body.clientHeight;

// var windowWidth = "1300";

var windowHeight = "800";
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();

	var pppHeight = $("#ppp").height();
	var pppWidth = $("#ppp").width();

   	var bxtop = windowHeight/2-200/2;
	var bxleft = windowWidth/2-200/2;



	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2+200,
		"left": windowWidth/2-popupWidth/2
	});

		$("#divcenter").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2+200,
		"left": windowWidth/2-popupWidth/2
	});

	$("#sp").css({
		"position": "absolute",
	    "left": windowWidth/2-225
	});
		$("#sl").css({
		"position": "absolute",
	    "left": windowWidth/2+120
	});








	$("#ppp").css({
		"position": "absolute",
		"top": windowHeight/2-pppHeight/2+200,
		"left": windowWidth/2-pppWidth/2
	});

	$("#bx").animate({opacity: "0.7", left: bxleft, top: bxtop, height: "200", width: "200"}, 1500)
    $("#bx").animate({opacity: "0.2", left: "-=50", top: "-=50", height: "300", width: "300"}, 800)

	//only need force for IE6

	$("#backgroundPopup").css({
		"height": windowHeight
	});

}

///////////////////////////////////////////////////////////////
//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
   //  ssilka(1);



   var windowWidth = document.body.clientWidth;
   	var popupWidth = $("#bl1").width();
  var tt=windowWidth/2-popupWidth/2;

   	$("#bl1").css({
		"position": "absolute",
		"left": windowWidth/2-500
	});

	   	$("#men1").css({
		"position": "absolute",
		"left": windowWidth/2-506
	});
	 	$("#pr").css({
		"position": "absolute",
		"left": windowWidth/2-500
	});
	 	$("#cont").css({
		"position": "absolute",
		"left": windowWidth/2-505
	});

		$("#ir").css({
		"position": "absolute",
		"left": windowWidth/2-502
	});

		$("#hotlog").css({
		"position": "absolute",
		"left": windowWidth/2-502
	});


  // alert(tt);





/*
$(".menu1").click(function(){

  $(".menu1").css({"color": "#fff"});

  //alert(66);
       popupnomer = 0;
		//centering with css
	//	centerPopup();
		//load popup
		loadPopup();
});
*/


$('.m1 a').bind('click', function(){
 popupnomer = 0;

		loadPopup2();

	$('.m1 a').removeAttr('style');
	$(this).css('color', '#fff');
});

$('a.spmenu2').live('click', function(){
	$('a.spmenu2').removeAttr('style');
	$(this).css('color', '#e5c003');
});

	$("#bl2").click(function(){

//alert(66);
       popupnomer = 0;
		//centering with css
	//	centerPopup();
		//load popup
		loadPopup2();
	});






	//CLOSING POPUP
	//Click the x event!
    /////////////   закрытие модального окна при переходе по ссылке



	/////////////////

	//Click out event!

	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
