/*
 * jQuery layer
 * Copyright (c) 2009 Dmitry (php-coder.ru) <diminapochta@gmail.com>
 */
(function($){
	$.layer = function(get, query, title){
		$('#layer').remove();
		$.post(get, query, function(data){
			$("#layer").remove();
			html = '<div id="layer"><iframe width="100%" height="100%" frameborder="0"></iframe><table class="box"><tr><td class="one"></td><td class="two"></td><td class="free"></td></tr><tr><td class="four"></td><td align="center">'+data+'</td><td class="five"></td></tr><tr><td class="six"></td><td class="seven"></td><td class="eight"></td></tr></table></div>';
	        $(html).appendTo("body");


            $("#layer").css({"width":$("body").css("width"), "height":$("body").css("height")});

            if($("#carousel").length){
	            $("#carousel").jCarouselLite({
					btnNext:"#gallery-next",
					btnPrev:"#gallery-prev",
					visible:5,
	        		speed:600,
	        		circular:false
				});
				$("#carousel img").click(function(){
				    $("#fullPhoto").attr("src", $(this).attr("full"));
				    return false;
				});
            }

            $("#layer .box").css({"left":Math.ceil(($("body").width()/2)-($("#layer .box").width()/2) + document.body.scrollLeft), "top":Math.ceil(($("body").height()/2)-($("#layer .box").height()/2) + document.body.scrollTop)});

			$("#layer .box").draggable({
				cursor:"move",
		        revert:false,
		        addClasses:false,
		        handle:$("#title_box"),
		        iframeFix:true,
		        scroll:false,
		        containment:"document"
		    });
			return false;
		});
		return false;
	}

})(jQuery);
