
// ----- contextpanel ----------------------------
    /**
     * @extends SyqComponent
     */
    function SyqComponent_contextpanel()
    {
        this.click = new SyqEvent;
        this.elem = null;
        this.nTimerToHide = null;

        this.init = function()
        {
            var self = this;
            this.q('#p>*').each(function(index,elem) {
                $(elem).click(function() { self.click(elem) });
            });
        };

        this.show = function()
        {
            this.q('#p').css('top', Math.round($(this.elem).offset().top)+'px');
            this.q('#p').css('left', Math.round($(this.elem).offset().left+$(this.elem).width()-this.q('#p').width())+'px');
            this.q('#p').show();
        };

        this.attach = function(elem)
        {
            var self = this;
            $(elem).mouseover(function(){
                self.elem = elem;
                self.show();
                self.p_mouseover();
            });
            $(elem).mouseout(function(){
                self.p_mouseout();
            });
        };

        this.p_mouseover = function()
        {
            if (this.nTimerToHide!=null)
            {
                if (this.elem) $(this.elem).addClass('activeContext');
                clearTimeout(this.nTimerToHide);
                this.nTimerToHide = null;
            }
        };

        this.p_mouseout = function()
        {
            if (this.nTimerToHide==null)
            {
                if (this.elem) $(this.elem).removeClass('activeContext');
                var self = this;
                this.nTimerToHide = setTimeout(function() { self.q('#p').hide(); }, 1000);
            }
        };
    };
    SyqComponent_contextpanel.prototype = new SyqComponent;

// ----- getprogpanel ----------------------------
    /**
     * @extends SyqComponent
     */
    function SyqComponent_getprogpanel()
    {
        this.error = function(code)
        {
            if (code==1) alert("Введённый код неверен. Проверь правильность ввода!");
            else
            if (code==2) alert("К сожалению, прошло слишком много времени между загрузкой фотографии и оплатой, в результате чего фотография была посчитана ненужной и удалена с сервера. Создайте аватар сначала, после чего введите код снова.");
            else
            if (code==3) alert("Срок действия вашего кода доступа истёк.");
        };
    };
    SyqComponent_getprogpanel.prototype = new SyqComponent;

// ----- colorpicker ----------------------------
    /**
     * @extends SyqComponent
     */
    function SyqComponent_colorpicker()
    {
        this.color = '';

        this.change = new SyqEvent;

        this.init = function()
        {
            this.color = this.q('#color').val();
            var self = this;
            this.q('#cp').ColorPicker({
                color: self.color
                ,livePreview: false
                ,onChange: function (e1,e2,e3) { self.colorSelected(e1,e2,e3); }
            });
            this.q('#cp').css('background-color',this.color);
        };

        this.colorSelected = function(hsb,rgb,e)
        {
            this.color = '#'+rgb;
            this.q('#cp').css('background-color',this.color);
            this.change.call(this.color);
        };

        this.val = function(color)
        {
            if (color==null) return this.color;
            this.color = color;
            this.q('#cp').ColorPicker('color', this.color);
            this.q('#cp').css('background-color', this.color);
        };
    };
    SyqComponent_colorpicker.prototype = new SyqComponent;

// ----- vipAccessBanner ----------------------------
    /**
     * @extends SyqComponent
     */
    function SyqComponent_vipAccessBanner()
    {
        this.vipAccessClose_click = function()
        {
            $.cookie('hideVipAccess', '1', { path:'/' });
            this.q('.vipAccess').remove();
        };
    };
    SyqComponent_vipAccessBanner.prototype = new SyqComponent;

// ----- checkbox ----------------------------
    /**
     * @extends SyqComponent
     */
    function SyqComponent_checkbox()
    {
        this.click = new SyqEvent;

        this.init = function()
        {
            this.checked(this.checked());
        };

        this.val = this.checked = function(v)
        {
            if (v===undefined) return this.q('#v').val()!='0' ? true : false;

            this.q('#v').val(v ? '1':'0');
            if (v) this.q('#cb').addClass('checked');
            else   this.q('#cb').removeClass('checked');
        };

        this.cb_click = function(e)
        {
            var v = !this.checked();
            this.checked(v);
            return this.click.call(e, v);
        };
    };
    SyqComponent_checkbox.prototype = new SyqComponent;

// ----- sizeselector ----------------------------
    /**
     * @extends SyqComponent
     */
    function SyqComponent_sizeselector()
    {
        this.value = 0;
        this.change = new SyqEvent;

        this.init = function()
        {
            this.value = parseInt(this.q('#text').val());

            var self = this;
            this.q("#slider").slider({
                orientation:"horizontal",
                min: parseInt(self.q('#min').val()),
                max: parseInt(self.q('#max').val()),
                value: self.value,
                slide: function(event, ui)
                {
                    self.value = ui.value;
                    self.q('#text').val(self.value);
                    self.change.call(self.value);
                }
            });
        };

        this.text_keyup = this.text_change = function()
        {
            this.value = parseInt(this.q('#text').val());
            this.q("#slider").slider("value",this.value);
            this.change.call(this.value);
        };

        this.val = function(v)
        {
            if (v==null) return this.value;
            this.value = v;
            this.q('#text').val(v);
            this.q("#slider").slider('value', v);
        };
    };
    SyqComponent_sizeselector.prototype = new SyqComponent;

// ----- subscribe ----------------------------
    /**
     * @extends SyqComponent
     */
    function SyqComponent_subscribe()
    {
        this.email_focusin = function()
        {
            if (this.q('#email').val()=='e-mail')
            {
                this.q('#email').css('color','').val('');
            }
        };
        this.email_focusout = function()
        {
            if (this.q('#email').val()=='')
            {
                this.q('#email').css('color','#D699D6').val('e-mail');
            }
        };

        this.btSubscribe_click = function()
        {
            var re = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
            if (!re.test(this.q('#email').val()))
            {
                this.subscribeFail(1);
                return false;
            }
        };

        this.subscribeOK = function()
        {
            alert("Вы успешно подписались на нашу рассылку. Иногда письма могут попадать в папку 'спам'!");
        };

        this.subscribeFail = function(error)
        {
            if (error==1) alert("Проверьте правильность ввода e-mail.");
            else
            if (error==2) alert("Пользователь с данным адресом уже подписан на рассылку.");
        };
    };
    SyqComponent_subscribe.prototype = new SyqComponent;

// ----- fontReplace ----------------------------
    /**
     * @extends SyqComponent
     */
    function SyqComponent_fontReplace()
    {
        this.init = function()
        {
            this.text(this.q('#text').html());
        };

        this.text = function(t)
        {
            if (t==null) return this.text;
            this.q('#text').html(t);
            var self = this;
            this.q('#text').fontReplace({
                path		: '/components/fontReplace/',
                textIndent	: -9000,
                fontFile	: self.q('#font').val(),
                fontSize	: self.q('#size').val(),
                fontColor	: self.q('#color').val(),
                background	: self.q('#background').val(),
                width		: self.q('#width').val(),
                height		: self.q('#height').val()
            });
        };
    };
    SyqComponent_fontReplace.prototype = new SyqComponent;

// ----- customText ----------------------------
    /**
     * @extends SyqComponent
     */
    function SyqComponent_customText()
    {
        this.x = 0;
        this.y = 0;
        this.w = 0;
        this.h = 0;

        this.angle = 0;

        this.init = function()
        {
            if ($.browser.msie)
            {
                this.q('#i')[0].ondrag = function () {return false;};
            }
        };
        
        this.bind = function(text, fontFamily, fontSize, color, konturColor, shadowColor, rotateAngle, transparency)
        {
			this.angle = rotateAngle;
            var url = '/components/fontReplace/' +
				 'fontReplace.support.php?font=' + encodeURIComponent(fontFamily) +
				 '&text=' + encodeURIComponent(text) +
				 '&fontcolor=' + color.replace(/#/g,'') +
				 '&backgroundcolor=' + '' +
				 '&size=' + fontSize +
				 '&konturColor=' + (konturColor ? konturColor.replace(/#/g,'') : '') +
				 '&shadowColor=' + (shadowColor ? shadowColor.replace(/#/g,'') : '') +
				 '&rotateAngle=' + rotateAngle;
            this.q('#i').attr('src',url);
        };

        this.i_load = function()
        {
            this.w = this.q('#i').width();
            this.h = this.q('#i').height();

            this.q('#i').css('display', 'block');
        };

        this.baseX = null;
        this.baseY = null;
        this.baseImgOfs = null;

        this.i_mousedown = function(e)
        {
            //alert('md');
            if (e.preventDefault) e.preventDefault();

            this.baseX = e.clientX;
            this.baseY = e.clientY;
            this.baseImgOfs = this.q("#i").offset();
        };
        
        this.c_mousemove = function(e)
        {
            if(e.preventDefault) e.preventDefault();

            if (this.baseX==null) return;

            var self = this;
            this.q('#i').offset({
                left: self.baseImgOfs.left + e.clientX-self.baseX,
                top: self.baseImgOfs.top + e.clientY-self.baseY
            });
        };

        this.c_mouseup = function(e)
        {
            if(e.preventDefault) e.preventDefault();

            if (this.baseX!=null)
            {
                this.baseX = null;
                var ofsI = this.q('#i').offset();
                var ofsC = this.q('#c').offset();
                this.x = ofsI.left - ofsC.left;
                this.y = ofsI.top - ofsC.top;
            }
        };

        this.setTextPos = function(x,y)
        {
            var self = this;
            this.q('#i').offset({ left: x, top: y });
            
        };

    };
    SyqComponent_customText.prototype = new SyqComponent;
