function floatFormWindow(form_window_id, focus_field_id, onclose)
{
        this.form_window = null;
        this.overlay = null;
        this.form_window_id = form_window_id || "at_frm_bitrix";
        this.focus_field_id = focus_field_id || null;
        this.onclose = onclose || function(){};

        this.ShowForm = function()
        {
                if(!this.form_window)
                        this.form_window = $('#' + this.form_window_id);

                this.form_window.appendTo(document.body).css('display', 'block');

                if (this.GetOpacityProperty())
                        this.CreateOverlay();

                if(this.focus_field_id)
                        $('#' + this.focus_field_id).focus();

                var _this = this;
                $(document).bind('keypress', function(e) {
                        if(e.keyCode == '27')
                                _this.CloseForm();
                });
        };
        this.CloseForm = function()
        {
                if(typeof this.onclose == 'function')
                        var res = this.onclose();

                this.form_window.hide();
                if(this.overlay)
                        this.overlay.hide();

                $(document).unbind('keypress');
        };
        this.CreateOverlay = function()
        {
                if (!this.overlay)
                {
                        this.overlay = $('<div class="float-form-overlay"></div>').appendTo(document.body);
                        var _this = this;
                        this.overlay.click(function() {_this.CloseForm()});
                }
                var windowSize = this.GetWindowScrollSize();
                this.overlay.css("width", windowSize.scrollWidth + "px");
                this.overlay.css("height", windowSize.scrollHeight + "px");
                this.overlay.show();
        };
        this.GetOpacityProperty = function()
        {
                if (typeof document.body.style.opacity == 'string')
                        return 'opacity';
                else if (typeof document.body.style.MozOpacity == 'string')
                        return 'MozOpacity';
                else if (typeof document.body.style.KhtmlOpacity == 'string')
                        return 'KhtmlOpacity';
                else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5)
                        return 'filter';
                return false;
        };
        this.GetWindowScrollSize = function(pDoc)
        {
                var width, height;
                if (!pDoc)
                        pDoc = document;

                if ( (pDoc.compatMode && pDoc.compatMode == "CSS1Compat"))
                {
                        width = pDoc.documentElement.scrollWidth;
                        height = pDoc.documentElement.scrollHeight;
                }
                else
                {
                        if (pDoc.body.scrollHeight > pDoc.body.offsetHeight)
                                height = pDoc.body.scrollHeight;
                        else
                                height = pDoc.body.offsetHeight;

                        if (pDoc.body.scrollWidth > pDoc.body.offsetWidth ||
                                (pDoc.compatMode && pDoc.compatMode == "BackCompat") ||
                                (pDoc.documentElement && !pDoc.documentElement.clientWidth)
                        )
                                width = pDoc.body.scrollWidth;
                        else
                                width = pDoc.body.offsetWidth;
                }
                return {scrollWidth : width, scrollHeight : height};
        };
}

CMlibAjax = {
        UpdateQuota: function()
        {
                $("#quota").load("/bitrix/templates/main/include_areas/quota.php?AJAX_CALL=Y");
        }
}

CJSCapthca = function(img)
{
        this.image = BX(img);

        this.reload = function()
        {
                if(!this.image) return;
        	BX.ajax( {
        		'method': 'POST',
        		'dataType': 'html',
        		'url': '/captcha.php',
        		'onsuccess': BX.proxy(this.__insert, this)
        	});
        }
        this.__insert = function(sid)
        {
                this.image.src = '/bitrix/tools/captcha.php?captcha_sid=' + sid;
                this.__getSIDField().value = sid;
        }
        this.__getSIDField = function()
        {
                var form = BX.findParent(this.image, {"tag": "form"});
                if(!form) return false;

                var attr = {"name": "captcha_sid", "type": "hidden"};
                var field = BX.findChild(form, {"tag": "INPUT", "attr": attr}, true);
                if(!field)
                {
                        field = form.appendChild(BX.create("INPUT", {"attrs": attr}));
                }
                return field;
        }
}

BX(function() {

        var c = BX("img_captcha");
        
        if(c)
                BX.bind(c, "click", function() {
                        var c = new CJSCapthca(this);
                        c.reload();
                });
});

$(function() {

	$("a[href$=.jpg]:has(img),a[href$=.png]:has(img),a[href$=.gif]:has(img)", "#content").fancybox({

		'overlayShow'			: true,
		'zoomSpeedIn'			: 600,
		'overlayOpacity'		: 0.6,
		'zoomSpeedOut'			: 500,
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInBack'
	});
});
