var Shop = new Class({
    version: '5.3.4',

    Implements: [ Events ],

    urls : {
        skin : '',
        base : ''
    },

    px1 : 'public/images/1px.gif',

    selectorFunctions : { },

    perBrowserFix : { },

    classes : { },

    runtime : {
        OptionsDefault : null,
        OptionsConfiguration : null,
        OptionCurrentStock : null,
        OptionImgWidth : null,
        OptionImgHeight : null
    },

    options : {
        debug : false,
        profile: false
    },

    status : {
        domready : false,
        load : false
    },

    debug : function() {
        if(true == this.options.debug)
            console.debug.pass(arguments)();
    },

    error : function() {
        if(!!console.warn) {
            console.warn.apply(console, arguments);
        } else if(!!console.error) {
            console.error.apply(console, arguments);
        } else {
            console.log.apply(console, arguments);
        }
    },

    profile : function() {
        if(true == this.options.debug && true == this.options.profile)
            console.profile();
    },

    profileEnd : function() {
        if(true == this.options.debug && true == this.options.profile)
            console.profileEnd();
    },

    time : function(el) {
        if(true == this.options.debug)
            console.time(el);
    },

    timeEnd : function(el) {
        if(true == this.options.debug)
            console.timeEnd(el);
    },

    get : function(el) {
        if('string' != typeOf(el)) {
            this.error('Unable to get(): ', el, this);
            return null;
        }

        var ret = null;
        if(el.indexOf('.') > 0) {
            var x = el.split('.');

            var tmp = this[ x[0] ];
            for(var y = 1; y < x.length; ++y) {
                if($chk(tmp)) {
                    tmp = tmp[ x[y] ];
                } else {
                    tmp = null;
                    break;
                }
            }

            if(null == tmp) {
                var tmp = Shop[ x[0] ];
                for(var y = 1; y < x.length; ++y) {
                    if($chk(tmp)) {
                        tmp = tmp[ x[y] ];
                    } else {
                        tmp = null;
                        break;
                    }
                }
            }

            ret = tmp;
        } else {
            if($chk(this[el])) {
                ret = this[el];
            } else if($chk(Shop[el])) {
                ret = Shop[el];
            } else {
                this.error('Unable to get(): ', el, this);
            }
        }

        if('function' == typeOf(ret))
            return ret.bind(this);
        else
            return ret;
    },

    subclass : function(_class) {
        if($chk(Shop[_class]) && $chk(Shop[_class].condition) && 'function' == typeOf(Shop[_class].condition)) {
            if(false == !!Shop[_class].condition.bind(this)())
                return;
            var options = Shop[_class].options || {};
            this.classes[_class] = new Shop[_class](options, this);
            this.classes[_class].Shop = this;
            return this.classes[_class];
        }
    },

    url : function(url, skin) {
        if(url.length > 0 && ( '/' == url.substr(0, 1) || 'http://' == url.substr(0, 7) || 'https://' == url.substr(0, 8)))
            return url;
        if(true == !!skin)
            return (this.urls.skin + '/' + url).replace(/\/\//g, '/');
        else
            return (this.urls.base + '/' + url).replace(/\/\//g, '/');
    },

    popup : function(url, event, params, obj) {
        params = params || '';
        if(!Browser.ie || !obj || !obj.click) {
            new DOMEvent(event).stop();
            window.open(url, '', params);
        } else {
            if(true == obj._prevent) {
                return;
            }

            new DOMEvent(event).stop();
            var wn = 'S_' + Math.random().toString().replace('.', '');
            var w = window.open('', wn, params);
            if(!!w) {
                obj.target = wn;
                obj._prevent = true;
                ( function() { this.click(); this._prevent = false; } ).delay(500, obj);
            } else {
                window.location.href = url;
            }
        }
    },

    initialize : function() {
        this.time('Shop.initialize');
        this.profile();

        this.status.domready = true;
        window.addEvent('load', (function() { this.status.load = true; }).bind(this) );

        if(false == this.get('urlParser')()) {
            this.error('Unable to parse urls');
            return;
        }

        if('function' == typeOf(this.get('preinit')))
            this.get('preinit')();

        this.get('runSelectorFunctions')();
        this.get('runPerBrowserFix')();

        this.subclass('skinPreviewBox');
        this.subclass('fadingText');
        this.subclass('productVoter');
        this.subclass('imageSlider');
        this.subclass('imageZoom');
        this.subclass('basketHandler');
        this.subclass('stockHandler');
        this.subclass('pageSlider');
        this.subclass('breadcrumbsFitter');
        this.subclass('filterPrice');
        this.subclass('filterFolder');
        this.subclass('filterSelects');
        this.subclass('ajaxBasket');

        this.get('galleryInit')();

        if('function' == typeOf(this.get('postinit')))
            this.get('postinit')();

        this.profileEnd();
        this.timeEnd('Shop.initialize');
    }

});


Shop.lang = { };
Shop.values = { };
Shop.useroptions = { };
Shop.preinit = Function.from();
Shop.postinit = Function.from();


Shop.urlParser = function() {
    $$('link[rel=home]').each(function(el) {
        if('string' == typeOf(el.get('href')))
            this.urls.base = (el.get('href') + '/').replace(/\/\//g, '/');
    }, this);

    $$('link[rel=start]').each(function(el) {
        if('string' == typeOf(el.get('href')))
            this.urls.base = (el.get('href') + '/').replace(/\/\//g, '/');
    }, this);

    $$('link[rel=skin]').each(function(el) {
        if('string' == typeOf(el.get('href')))
            this.urls.skin = (el.get('href') + '/').replace(/\/\//g, '/');
    }, this);

    return !!(this.urls.skin.length && this.urls.base.length);
};



Shop.runPerBrowserFix = function() {
    Browser.ie67 = !!Browser.ie6 || !!Browser.ie7;
    for(var b in Browser) {
        if(b.match(/^[a-z]/) && Browser[b] && $chk(this.get('perBrowserFix.' + b)) && 'function' == typeOf(this.get('perBrowserFix.' + b)))
            this.get('perBrowserFix.' + b).bind(this)();
    }
};



Shop.runSelectorFunctions = function() {
    for(var x in this.get('selectorFunctions')) {
        var sel = this.get('selectorFunctions.' + x);

        if('function' == typeOf(sel.domready)) {
            if(true == this.status.domready) {
                $$(sel.selector).each(sel.domready, this);
            } else {
                window.addEvent('domready', (function(sel) {
                    $$(sel.selector).each(sel.domready, this);
                }).pass([sel], this) );
            }
        }

        if('function' == typeOf(sel.load)) {
            if(true == this.status.load) {
                $$(sel.selector).each(sel.load, this);
            } else {
                window.addEvent('load', (function(sel) {
                    $$(sel.selector).each(sel.load, this);
                }).pass([sel], this) );
            }
        }
    }

    this.addEvent('Shop.element.add', function() {
        this.get('addeventSelectorFunctions')();
    });
};

Shop.addeventSelectorFunctions = function() {
    for(var x in this.get('selectorFunctions')) {
        var sel = this.get('selectorFunctions.' + x);
        if('function' == typeOf(sel.addelement)) {
            $$(sel.selector).each(sel.addelement, this);
        } else if('domready' == sel.addelement) {
            $$(sel.selector).each(sel.domready, this);
        }
    }
};



Shop.skinPreviewBox = new Class({
    Implements: [ Events, Options ],

    options : {
        a_class : 'spanhover',
        div_class : 'skinpreview',
        img_src : 'public/images/1px.gif'
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;
        var div = new Element('div', {
            'class' : this.options.div_class,
            events : {
                mouseenter : function(e) { $(this).fade(0.8); },
                mouseleave : function(e) { $(this).fade(0.3); }
            }
        }).inject(document.body).setStyle('opacity', 0.3);

        var a = new Element('a', {
            'class' : this.options.a_class,
            events : {
                click : function(e) {
                    new DOMEvent(e).stop();
                    Cookie.dispose('skinpreview', { 'path' : '/' + this.Shop.urls.base.replace(/(^\/|\/$)/g, '') });
                    window.location.href = window.location.href;
                }
            }
        }).inject(div);

        a.Shop = this.Shop;

        new Element('img', {
            src : this.Shop.url(this.options.img_src)
        }).inject(a);

        new Element('span', {
            text : this.Shop.get('lang.skinpreview.close')
        }).inject(a);
    }
});






Shop.fadingText = new Class({
    Implements: [ Events, Options ],

    options : {
        selector : 'input.fadingtext'
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        $$(this.options.selector).each(function(el) {
            if(0 == el.value.length) return;

            if( !$chk(el.form._fadingtext) )
                $(el.form)._fadingtext = [ ];

            $(el.form)._fadingtext.push(el);

            el._value = el.value;
            el.addEvent('focus', function(e) {
                if(this.value == this._value)
                    this.value = '';
            })

            el.addEvent('blur', function(e) {
                if('' == this.value)
                    this.value = this._value;
            });

            $(el.form).addEvent('submit', function(e) {
                new DOMEvent(e).stop();
                this._fadingtext.each(function(el) {
                    el.fireEvent('focus', null);
                });
                this.submit();
            });
        });
    }
});





Shop.productVoter = new Class({
    Implements: [ Events, Options ],

    options : {
        class0 : 'star0',
        class05 : 'star0-5',
        class1 : 'star1',
        selector : 'span.votestars',
        starsselector : 'span.votestars img',
        tipsclass : 'tool-tip',
        url : 'product/vote/prod/{prodid}/vote/{score}',
        votecountselector : 'span.votecount'
    },

    span : false,
    stars : [ ],
    votecount : false,

    mouseenter : function(score) {
        var n = 1;
        this.stars.each(function(el) {
            el.removeClass(this.options.class0).removeClass(this.options.class05)
                .removeClass(this.options.class1).addClass(n++ <= score ? this.options.class1 : this.options.class0);
        }, this);
    },

    mouseleave : function() {
        this.stars.each(function(el) {
            el.set('class', el._initial_class);
        });
    },

    vote : function(score) {
        var id = this.span.get('id').replace(/[^0-9]/g, '').toInt();
        if(id > 0 && score > 0) {
            var url = this.options.url.substitute({
                prodid : id,
                score : score
            });

            var req = new Request({
                url : this.Shop.url(url),
                secure : true,
                async : false,
                noCache : true,
                method : 'get',
                onFailure : function(xhr) {
                    alert(this.Shop.get('lang.common.product_vote_alert'));
                },
                onComplete : function(txt) {
                    if('1' == txt) {
                        this._class.span.removeEvents('mouseleave');
                        this._class.stars.setStyle('cursor', 'default').removeEvents('mouseenter').removeEvents('click');
                        this._class.votecount.set('text', this._class.votecount.get('text').toInt() + 1);
                        this._class.mouseenter(this._score);
                    } else {
                        alert(this.Shop.get('lang.common.product_vote_alert'));
                    }
                }
            });
            req._class = this;
            req._score = score;
            req.send();
        }
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        var span = this.span = $$(this.options.selector)[0];
        span._class = this;

        var stars = $$(this.options.starsselector);
        for(var x = 0; x < stars.length; ++x) {
            this.stars.push(stars[x]);
            stars[x]._class = this;
            stars[x]._initial_class = stars[x].get('class');
        }

        this.stars = $$(this.stars);

        var vc = span.getParent().getElements(this.options.votecountselector);
        if(1 == vc.length) {
            this.votecount = vc[0];
            vc[0]._class = this;
        }

        if(this.Shop.get('lang.voting.vote_n') && this.Shop.get('lang.voting.vote_n').length > 0)
            new Tips(stars, {
                className : this.options.tipsclass
            });

        value = 1;
        stars.each(function(el) {
            el._value = value++;
            el.set('alt', '');
            el.addEvent('mouseenter', function(e) {
                this._class.mouseenter(this._value);
            });
            el.addEvent('click', function(e) {
                this._class.vote(this._value);
            });
            el.setStyle('cursor', 'pointer');
            el.store('tip:className');
            el.store('tip:title', '');
            el.store('tip:text', this.Shop.get('lang.voting.vote_n').substitute({ 'score' : el._value }) );
        }, this);

        span.addEvent('mouseleave', function(e) {
            this._class.mouseleave();
        });
    }
});






Shop.imageSlider = new Class({
    Implements: [ Events, Options ],

    options : {
        container : null,
        sdiv : null,
        ul : null,
        left_arrow : null,
        left_arrow_img : null,
        right_arrow : null,
        right_arrow_img : null,
        imgwidth : 0,
        imgcount : 0,
        imglimit : 0,
        pos : 0,
        left_delta : -2,
        right_delta : 2,
        loaded_left_arrow : false,
        loaded_right_arrow : false,
        images_loaded : 0,
        galleryclass : 'innersmallgallery',
        asset_limit : 4
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;
        if(!$chk(this.options.container)) return;

        var div = this.options.container;
        this.options.sdiv = div.getChildren('.' + this.options.galleryclass).pop();
        this.options.ul = div.getElements('.' + this.options.galleryclass + ' ul').pop();
        if(!$chk(this.options.sdiv) || !$chk(this.options.ul) || this.options.ul.getChildren().length < 2) return;

        this.options.imgcount = this.options.ul.getChildren().length;
        var counter = 0;
        this.options.ul.getElements('img').each(function(img) {
            var i1 = img.get('alt');
            if(counter < this.options.asset_limit) {
                if('string' == typeOf(i1) && i1.length) {
                    ( function(x) { new Asset.image(x); } ).delay(500, this, i1);
                    var i2 = img.getParent().get('href');
                    if('string' == typeOf(i2) && i2.length) {
                        ( function(x) { new Asset.image(x); } ).delay(500, this, i2);
                    }
                }
                counter++;
            }
            if(Browser.ie || img.getSize().x > 0) {
                this.image_loaded.bind(this)();
            } else {
                img.addEvent('load', this.image_loaded.bind(this) );
            }
        }, this);
    },

    image_loaded : function() {
        this.options.images_loaded++;
        if(this.options.imgcount == this.options.images_loaded)
            this.start_init();
    },

    start_init : function() {
        var div = this.options.container;
        var sdiv = this.options.sdiv;
        var ul = this.options.ul;

        ul.setStyle('display', 'none');
        var td = ul.getParent();
        while('td' != td.get('tag') && $chk(td))
            td = td.getParent();
        if($chk(td)) {
            td.setStyle('width', td.getSize().x);
        }
        ul.setStyle('display', '');

        div.setStyles({
            width : div.getSize().x,
            height : div.getSize().y,
            position : 'relative'
        }).setStyle('opacity', 0);

        sdiv.setStyles({
            overflow : 'hidden',
            width : 100 * ul.getChildren().length
        });

        var w = 0;
        ul.getChildren().each(function(li) {
            w += li.getComputedSize().totalWidth;
        });
        if(w <= 10) return;
        sdiv.setStyle('width', w);
        this.options.imgwidth = Math.round(w / this.options.imgcount);

        this.options.left_arrow = new Element('img', {
            src : this.Shop.url(this.options.left_arrow_img),
            styles : {
                left : 0,
                position : 'absolute',
                'border-width' : 0,
                cursor : 'pointer'
            },
            events : {
                load : function(e) {
                    this._class.options.loaded_left_arrow = true;
                    this.setStyle('top', Math.round( (this.getParent().getSize().y - this.getSize().y) / 2 ) );
                    this._class.continue_init();
                },
                click : function(e) {
                    new DOMEvent(e).stop();
                    this._class.slide( this._class.options.left_delta );
                }
            }
        }).inject( div );
        this.options.left_arrow._class = this;

        this.options.right_arrow = new Element('img', {
            src : this.Shop.url(this.options.right_arrow_img),
            styles : {
                right : 0,
                position : 'absolute',
                'border-width' : 0,
                cursor : 'pointer'
            },
            events : {
                load : function(e) {
                    this._class.options.loaded_right_arrow = true;
                    this.setStyle('top', Math.round( (this.getParent().getSize().y - this.getSize().y) / 2 ) );
                    this._class.continue_init();
                },
                click : function(e) {
                    new DOMEvent(e).stop();
                    this._class.slide( this._class.options.right_delta );
                }
            }
        }).inject( div );
        this.options.right_arrow._class = this;

        if(Browser.ie && $(this.options.left_arrow).getSize().x > 0) {
            this.options.left_arrow.fireEvent('load');
        }

        if(Browser.ie && $(this.options.right_arrow).getSize().x > 0) {
            this.options.right_arrow.fireEvent('load');
        }
    },

    continue_init : function() {
        if(false == this.options.loaded_right_arrow || false == this.options.loaded_left_arrow) return;

        var imglimit = this.options.container.getSize().x - this.options.left_arrow.getSize().x * 1.25 - this.options.right_arrow.getSize().x * 1.25;
        imglimit = Math.floor( imglimit / this.options.imgwidth );
        this.options.sdiv.setStyle('margin-left', Math.round( this.options.left_arrow.getSize().x * 1.25 ));
        this.options.imglimit = imglimit;

        if(this.options.imglimit >= this.options.imgcount) {
            if(Browser.ie) {
                this.options.left_arrow.setStyle('display', 'none');
                this.options.right_arrow.setStyle('display', 'none');
            } else {
                this.options.left_arrow.dispose();
                this.options.right_arrow.dispose();
            }
        }

        this.slide();
        this.options.container.setStyle('opacity', 1);
    },

    slide : function(delta) {
        if(!$chk(delta)) delta = 0;
        this.options.pos += delta;
        if(this.options.pos < 0)
            this.options.pos = 0;
        else if(this.options.pos > (this.options.imgcount - this.options.imglimit) )
            this.options.pos = this.options.imgcount - this.options.imglimit;

        var list = this.options.ul.getChildren();
        var start = this.options.pos;
        var stop = this.options.pos + this.options.imglimit - 1;
        for(var x = 0; x < list.length; ++x) {
            if(x >= start && x <= stop)
                list[x].removeClass('none');
            else
                list[x].addClass('none');
        }
    }

});




Shop.imageZoom = new Class({
    Implements: [ Events, Options ],

    options : {
        img: false,
        inner: false,
        container_class : 'imagezoom',
        transbox_class : 'imagezoom_transbox',
        shade_class : 'imagezoom_shade'
    },

    img : null,
    div : null,
    divimg : null,
    src : null,

    mmfx : false,
    infx : false,
    inner : true,
    inside : false,
    startpos : null,

    locked : false,

    shade1 : null,
    shade2 : null,

    initialize : function(options, shop_class) {
        if (Browser.Features.Touch) {
            return;
        }

        this.setOptions(options);
        this.Shop = shop_class;

        var img = $(this.options.img);
        img._class = this;
        img._zoomimage = this;
        this.img = img;
        this.inner = !!this.options.inner;

        img.removeEvents('mouseenter').removeEvents('mouseleave').removeEvents('mousemove');
        img.addEvent('mouseenter', function(e) {
            if(true == this._loaded && false == this._locked) {
                this._class.inside = true;
                if(true == this._class.infx) {
                    this._class.show_div.delay(150, this._class);
                } else {
                    this._class.show_div();
                }
            } else {
                ( function() { this.fireEvent('mouseenter', e); } ).delay(100, this);
            }
        }).addEvent('mouseleave', function(e) {
            this._class.inside = false;
        }).addEvent('mousemove' , function(e) {
            if(true == this._class.inside)
                this._class.startpos = e.page;
        }).addEvent('load', function(e) {
            this._loaded = true;
        });
        var s = img.getSize();
        img._loaded = !!(s.x + s.y > 20)

        if(false == Shop.imageZoom.donefirsttime) {
            img._locked = true;
            Shop.imageZoom.donefirsttime = true;
            ( function() { this._locked = false; } ).delay(1000, img);
        } else {
            img._locked = false;
        }

        if(img.get('class').match(/gallery_[0-9]+/)) {
            var id = img.get('class').replace(/.*gallery_([0-9]+).*/, 'prodimg$1');
            if(id.match(/^prodimg[0-9]+$/) && $(id))
                this.src = $(id).get('href');
        } else {
            this.src = img.getParent().get('href');
        }

        if($chk(this.src))
            new Asset.image( this.src );
    },

    destroy : function() {
        try {
            window.removeEvent('resize', this.resize_event);
            delete this.img._class;
            delete this.img._zoomimage;
            if($chk(this.div)) this.div.dispose();
            if($chk(this.shade1)) this.shade1.dispose();
            delete this;
        } catch(e) { }
    },

    show_div : function() {
        if(false == this.inside || true == this.locked) return;

        if(!$chk(this.div)) {
            this.div = new Element('div', {
                'class' : this.options.container_class
            }).inject(document.body);
            var c = this.img.getComputedSize();
            var p = this.img.getPosition();

            this.resize_event = (function(e) {
                var p = this.img.getPosition();
                if(false == this.inner) {
                    this.shade1.setStyles({
                        left : p.x + ( Browser.firefox ? c['border-left-width'] : 0 ),
                        top : p.y
                    });
                    this.shade1._pos = this.img.getPosition();

                    var x = Shop.imageZoom.sidebox_size(this.img, this.div, this.divimg);
                    p = {
                        x : x.left,
                        y : x.top
                    };
                }

                this.div.setStyles({
                    left : p.x,
                    top : p.y
                });
            }).bind(this);
            window.addEvent('resize', this.resize_event);

            if(true == this.inner) {

                this.div.setStyles({
                    left : p.x + (Browser.firefox ? 1 : 0),
                    top : p.y,
                    width : c.width + c['padding-left'] + c['padding-right'],
                    height : c.height + c['padding-top'] + c['padding-bottom']
                });

                this.div._size = this.div.getSize();
                this.div._pos = this.div.getPosition();
            } else {
                this.div.setStyles( Shop.imageZoom.sidebox_size(this.img, this.div, this.divimg) );
                this.shade1 = new Element('div', {
                    'class' : this.options.shade_class
                })
                    .inject( document.body );

                this.shade1.setStyles({
                    left : p.x + (Browser.firefox ? 1 : 0),
                    top : p.y,
                    width : c.width,
                    height : c.height
                });
                this.shade1._size = this.img.getSize();
                this.shade1._pos = this.img.getPosition();
                this.shade1._class = this;
                this.shade1.set('tween', { duration: 300 }).fade('hide');

                this.shade2 = new Element('div', {
                    'class' : this.options.transbox_class,
                    styles : {
                        'background-image' : 'url("' + this.img.get('src') + '")',
                        width : 0,
                        height : 0
                    }
                })
                    .inject( this.shade1 );
            }

            this[this.inner ? 'div' : 'shade1']
                .removeEvents('mouseleave')
                .removeEvents('mousemove')
                .removeEvents('click')
                .addEvent('click', function(e) {
                    this._class.hide_div();
                    var a = this._class.img.getParent();
                    this._class.locked = true;

                    if('div' == a.get('tag') && a.hasClass('mainimg')) {
                        a = a.getElement('img');
                        if(a) {
                            a = $('prodimg' + a.get('class').replace(/^.*gallery_([0-9]+)[^0-9]?.*$/, '$1'));
                        }
                    }

                    if(a && 'a' == a.get('tag') && $chk(a._milkbox)) {
                        var id = 0;
                        try {
                            var list = a._milkbox.galleries[0].items;
                            for(var x = 0; x < list.length; ++x) {
                                if(list[x].element == a) {
                                    id = x;
                                    break;
                                }
                            }
                        } catch(e) { }
                        a._milkbox.open('milkbox:gall', id);
                    } else {
                        this._class.img.fireEvent('click', e);
                    }
                    ( function() { this._class.locked = false; } ).delay(500, this);
                })
                .addEvent('mouseleave', function(e) {
                    this._class.hide_div();
                })
                .addEvent('mousemove', function(e) {
                    var additionalWidth =   parseFloat(this.getStyle('border-left-width')) +
                                            parseFloat(this.getStyle('border-right-width')),
                        additionalHeight =  parseFloat(this.getStyle('border-top-width')) +
                                            parseFloat(this.getStyle('border-bottom-width'));

                    additionalWidth = parseInt(additionalWidth);
                    additionalHeight = parseInt(additionalHeight);

                    var size = {
                        x : this._size.x - additionalWidth,
                        y : this._size.y - additionalHeight
                    };

                    var xfactor = Shop.imageZoom.transform( ( e.page.x - this._pos.x ) / size.x, this._class.inner );
                    var yfactor = Shop.imageZoom.transform( ( e.page.y - this._pos.y ) / size.y, this._class.inner );
                    var s = this._class.divimg.getSize();

                    var x = -Math.round(xfactor * (s.x - size.x));
                    var y = -Math.round(yfactor * (s.y - size.y));

                    if(false == this._class.mmfx)
                        this._class.divimg.setStyles({ left : x, top : y });
                    else
                        this._class.divimg.morph({ left : x, top : y });

                    if($chk(this._class.shade2)) {
                        if(0 == this._class.shade2.getSize().x) {
                            this._class.shade2.setStyles({
                                width : Math.round( ( this._class.div.getSize().x / this._class.divimg.getSize().x ) * size.x ) ,
                                height : Math.round( ( this._class.div.getSize().y / this._class.divimg.getSize().y ) * size.y )
                            });
                            this._class.shade2._size = this._class.shade2.getSize();
                        }

                        x = Math.round(xfactor * (size.x - this._class.shade2._size.x));
                        y = Math.round(yfactor * (size.y - this._class.shade2._size.y));

                        this._class.shade2.setStyles({
                            left : x,
                            top : y,
                            'background-position' : (-x) + 'px ' + (-y) + 'px'
                        });
                    }
                });

            this.div._class = this;
            this.div.set('tween', { duration: 300 }).fade('hide');

            this.divimg = new Element('img', {
                src : this.src,
                styles : {
                    position : 'relative',
                    left : 0,
                    top : 0
                }
            }).inject(this.div).set('morph', {
                duration : 100
                //transition : 'linear:in:out'
            });

            if($chk(this.startpos) && $chk(this.startpos.x)) {
                this[this.inner ? 'div' : 'shade1'].fireEvent('mousemove', { 'page' : this.startpos });
            }
        }

        if(true == this.infx) {
            this.div.fade('in');
            if($chk(this.shade1))
                this.shade1.fade(0.75);
        } else {
            this.div.fade('show').setStyle('visibility', 'visible');
            if($chk(this.shade1)) {
                this.shade1.fade('show').setStyle('visibility', 'visible');
                this.shade1.setStyle('opacity', 0.75);
            }
        }
    },

    hide_div : function() {
        this.inside = false;
        var fadetype = ( this.infx ? 'out' : 'hide' );
        this.div.fade(fadetype).setStyle('visibility', 'hidden');
        if($chk(this.shade1))
            this.shade1.fade(fadetype).setStyle('visibility', 'hidden');
    }

});

Shop.imageZoom.donefirsttime = false;

Shop.imageZoom.transform = function(x, inner) {
    if(false == inner) return x;
    if(x < 0.5) {
        x = 3 * x * x - 1/4; // [ (2x)^2 / (4/3) ] - (1/3)
    } else {
        x = Math.sqrt(x - 0.5) * 1.5 + 0.5;
    }

    if(x >= 1) return 1;
    if(x <= 0) return 0;
    return x;
}

Shop.imageZoom.sidebox_size = function(oimg, sidediv, divimg) {
    var c = oimg.getComputedSize();
    var p = oimg.getPosition();
    return {
        left : p.x + c.width + 10,
        top : p.y,
        width : c.width,
        height : c.height
    };
}





Shop.basketHandler = new Class({
    Implements: [ Events, Options ],

    options : {
        shipping_id : 0,
        payment_id : 0,
        shipping_row : null,
        force_rows : false,
        step : 0,
        ordersumfield : null,
        currency : {
            dec_point : ',',
            thousands_sep : ' ',
            prefix : '',
            postfix : ''
        },
        containers : {
            step1 : false,
            step2 : false
        },
        selectors : {
            deliveryrow : '',
            paymentrow : '',
            deliverychangelink : '',
            paymentchangelink : '',
            paymentheadlabel : '',
            paymentrlabel : '',
            paymentradios : '',
            deliveryradios : '',
            deliveryheadlabel : '',
            deliveryheadvalue : '',
            deliverytrlabel : '',
            deliverytrvalue : '',
            trradio : '',
            countrytr : '',
            trcountryselect : '',
            trdifferentaddress : '',
            differentaddress : '',
            personaladdress : '',
            companyaddress : '',
            formcompanyname : '',
            formtaxid : '',
            formcompanyname2 : '',
            formtaxid2 : '',
            countryselect : '',
            addresstyperadios : '',
            addressselectsubmit : '',
            addressselect : ''
        },
        currency_map : '',
        getaddressurl : ''
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        if($chk(Shop.values.CurrencyMap)) {
            this.options.currency_map = Shop.values.CurrencyMap;
            this.parse_currency();
        }

        if($chk(Shop.values.ShippingValue)) {
            this.options.shippingValue = Shop.values.ShippingValue;
        }

        if($chk(Shop.values.SumNoShipping)) {
            this.options.sumNoShipping = Shop.values.SumNoShipping;
        }

        if($chk(Shop.values.Shipping2Payment)) {
            this.options.shipping2Payment = Shop.values.Shipping2Payment;
        }

        if($chk(Shop.values.Country2Shipping)) {
            this.options.country2Shipping = Shop.values.Country2Shipping;
        }

        if($chk(Shop.values.PaymentAdditional)) {
            this.options.paymentAdditional = Shop.values.PaymentAdditional;
        }

        if(this.options.step > 0 && 'function' == typeOf(this['step_' + this.options.step]))
            this['step_' + this.options.step]();
    },

    parse_currency : function() {
        var cmap = this.options.currency_map;
        this.options.currency.prefix = cmap.replace(/^(.*)1.*/, '$1');
        this.options.currency.postfix = cmap.replace(/.*6(.*)$/, '$1');
        this.options.currency.dec_point = cmap.replace(/.*4(.*)5.*/, '$1');
        this.options.currency.thousands_sep = cmap.replace(/.*1(.*)2.*/, '$1');
    },

    format_currency : function(x) {
        return this.options.currency.prefix
                + x.numberFormat(2, this.options.currency.dec_point, this.options.currency.thousands_sep)
                + this.options.currency.postfix;
    },

    calculate : function() {
        var td = this.options.ordersumfield;
        if($chk(td) && $chk(this.options.shippingValue) && $chk(this.options.sumNoShipping) && this.options.shipping_id > 0) {
            var sv = this.options.shippingValue['s' + this.options.shipping_id]
                        + this.shipping_additional(this.options.shipping_id, this.options.payment_id);
            var s = this.options.sumNoShipping + sv;

            td.set('text', this.format_currency(s));

            if($chk(this.options.shipping_row)) {
                this.options.shipping_row.getElements(this.options.selectors.deliverytrvalue).set('text', this.format_currency(sv));
                this.options.containers.step1.getElements(this.options.selectors.deliveryheadvalue).set('text', this.format_currency(sv));
            }
        }
    },

    shipping_additional : function(sid, pid) {
        if(this.options.paymentAdditional && this.options.paymentAdditional['s' + sid] && this.options.paymentAdditional['s' + sid]['p' + pid]) {
            return this.options.paymentAdditional['s' + sid]['p' + pid];
        }
        return 0;
    },

    step_1_show_delivery : function() {
        this.step_1_hide_payment();
        this.options.containers.step1.getElements(this.options.selectors.deliveryrow).filter(function(el) {
            return !el.getElement(this.options.selectors.trradio).disabled;
        }, this).removeClass('none');
        //this.options.containers.step1.getElement('tr.deliveryhead em.fold a').addClass('none');
    },

    step_1_show_payment : function() {
        this.step_1_hide_delivery();
        this.options.containers.step1.getElements(this.options.selectors.paymentrow).filter(function(el) {
            return !el.getElement(this.options.selectors.trradio).disabled;
        }, this).removeClass('none');
        //this.containers.step1.getElement('tr.paymenthead em.fold a').addClass('none');
    },

    step_1_hide_delivery : function() {
        if(false == this.options.force_rows) return;
        this.options.containers.step1.getElements(this.options.selectors.deliveryrow).addClass('none');
        this.options.containers.step1.getElements(this.options.selectors.deliverychangelink).removeClass('none');
    },

    step_1_hide_payment : function() {
        if(false == this.options.force_rows) return;
        this.options.containers.step1.getElements(this.options.selectors.paymentrow).addClass('none');
        this.options.containers.step1.getElements(this.options.selectors.paymentchangelink).removeClass('none');
    },

    step_1 : function() {
        if(!$chk(this.options.containers.step1)) return;

        var i = this.options.containers.step1.getParent().getElements('tbody input[type=text]')[0];
        if($chk(i)) i.focus();

        var f = this.options.containers.step1.getElement(this.options.selectors.deliverychangelink);
        if($chk(f)) {
            f.removeClass('none');
            if(f.getSize().x > 0) {
                this.force_rows = true;

                this.options.containers.step1.getElements(this.options.selectors.deliverychangelink).addEvent('click', function(e) {
                    if(e) new DOMEvent(e).stop();
                    this.blur();
                    if(true == this._class.options._folden_delivery) {
                        this._class.step_1_hide_payment();
                        this._class.options._folden_payment = true;
                        this._class.step_1_show_delivery();
                    } else
                        this._class.step_1_hide_delivery();
                    this._class.options._folden_delivery = ! this._class.options._folden_delivery;
                }).each(function(el) { el._class = this }, this);

                this.options.containers.step1.getElements(this.options.selectors.paymentchangelink).addEvent('click', function(e) {
                    if(e) new DOMEvent(e).stop();
                    this.blur();
                    if(true == this._class.options._folden_payment) {
                        this._class.step_1_show_payment();
                        this._class.step_1_hide_delivery();
                        this._class.options._folden_delivery = true;
                    } else
                        this._class.step_1_hide_payment();
                    this._class.options._folden_payment = ! this._class.options._folden_payment;
                }).each(function(el) { el._class = this }, this);

                this.step_1_hide_delivery();
                this.step_1_hide_payment();
                this.options._folden_payment = true;
                this.options._folden_delivery = true;
            }
        }

        this.options.containers.step1.getElements(this.options.selectors.paymentradios).each(function(el) {
            el.addEvent('change', function(e) {
                this._class.options.payment_id = $(this).get('value').toInt();
                this._class.options.containers.step1.getElements(this._class.options.selectors.paymentrow).removeClass('selected');
                tr = $(this).getParent();
                while('tr' != tr.get('tag'))
                    tr = tr.getParent();
                tr.addClass('selected');

                this._class.options.containers.step1.getElement(this._class.options.selectors.paymentheadlabel).set('html',
                    tr.getElements(this._class.options.selectors.paymentrlabel).get('html')
                );

                this._class.calculate();
                this._class.step_1_hide_payment();
                this._class.options._folden_payment = true;
                this._class.Shop.fireEvent('Shop.element.add');
            });
            el._class = this;
            if(Browser.ie) el.addEvent('click', function(e) { this.fireEvent('change', e); });
            if(true == el.checked)
                el.fireEvent('change', null);
        }, this);

        this.options.containers.step1.getElements(this.options.selectors.deliveryradios).each(function(el) {
            el.addEvent('change', function(e) {
                this._class.options.shipping_id = $(this).get('value').toInt();

                var tr = $(this).getParent();
                while('tr' != tr.get('tag'))
                    tr = tr.getParent();
                tr.getParent().getChildren(this._class.options.selectors.deliveryrow).removeClass('selected');
                tr.addClass('selected');
                this._class.options.shipping_row = tr;

                this._class.options.containers.step1.getElement(this._class.options.selectors.deliveryheadlabel).set('html',
                    tr.getElements(this._class.options.selectors.deliverytrlabel).get('html')
                );

                this._class.options.containers.step1.getElement(this._class.options.selectors.deliveryheadvalue).set('text',
                    tr.getElements(this._class.options.selectors.deliverytrvalue).get('text')
                );

                var trs = this._class.options.containers.step1.getElements(this._class.options.selectors.paymentrow);
                var inputs = [];
                var first = false;
                trs.each(function(tr) {
                    var input = tr.getElements(this._class.options.selectors.trradio).pop();
                    if(! $chk(input)) return;

                    var a = this._class.options.shipping2Payment['s' + $(this).get('value')];
                    if($chk(a) && a.contains( input.get('value').toInt() )) {
                        inputs.push(input);
                        input.disabled = input.readonly = false;
                        tr.removeClass('none');

                        if(false == first) {
                            tr.addClass('first');
                            first = true;
                        } else
                            tr.removeClass('first');
                    } else {
                        input.disabled = input.readonly = true;
                        input.checked = false;
                        tr.addClass('none').removeClass('first');
                    }
                }, this);

                if(inputs.length > 0) {
                    var checked = false;
                    for(var x = 0; x < inputs.length; ++x)
                        if(true == inputs[x].checked)
                            checked = true;
                    if(false == checked) {
                        inputs[0].checked = true;
                        inputs[0].fireEvent('change', null);
                    }
                }

                this._class.calculate();
                this._class.step_1_hide_delivery();
                this._class.options._folden_delivery = true;
            });
            el._class = this;
            if(Browser.ie) el.addEvent('click', function(e) { this.fireEvent('change', e); });
            if(true == el.checked)
                el.fireEvent('change', null);
        }, this);

        if($chk(this.options.country2Shipping)) {
            var tr = this.options.containers.step1.getElement(this.options.selectors.countrytr);
            if($chk(tr)) {
                var sel = tr.getElement(this.options.selectors.trcountryselect);
                if(sel.options.length > 0) {
                    if(sel.options.length > 1) {
                        tr.removeClass('none');
                    }
                    sel.addEvent('change', function(e) {
                        var cs = this._class.options.country2Shipping[this.get('value')];
                        var first = null;
                        var unchecked = false;
                        this._tr.getParent().getElements(this._class.options.selectors.deliveryradios).each(function(i) {
                            i.disabled = !this.contains(i.get('value').toInt());
                            if(true == i.disabled) {
                                if(true == i.checked) {
                                    i.checked = false;
                                    unchecked = true;
                                }
                            } else if(null == first) {
                                first = i;
                            }
                        }, cs);
                        if(true == unchecked) {
                            first.checked = true;
                            first.fireEvent('change');
                        }
                        this.blur();
                        this._tr.getParent().getElements(this._class.options.selectors.deliveryrow).removeClass('first').addClass('none');
                        this._class.step_1_show_delivery();
                        var ftr = this._tr.getParent().getElements(this._class.options.selectors.deliveryrow).filter(function(el) {
                            return !el.getElement(this._class.options.selectors.trradio).disabled;
                        }, this)[0];
                        if($chk(ftr))
                            ftr.addClass('first');
                    });
                    sel._class = this;
                    sel._tr = tr;
                    sel.fireEvent('change');
                }
            }
        }


        this.step_1_hide_delivery();
        this.step_1_hide_payment();
    },

    step_2 : function() {
        if(!$chk(this.options.containers.step2)) return;

        var i = this.options.containers.step2.getElements('input[type=text]')[0];
        if($chk(i)) i.focus();

        var f = (function myself(_form, _sub) {
            myself._form = _form;
            myself._sub = _sub;
            var trs = myself._form.getElements(this.options.selectors.trdifferentaddress);
            var i = myself._form.getElement(this.options.selectors.differentaddress);
            if($chk(i)) {
                if(i.checked)
                    trs.removeClass('none');
                else
                    trs.addClass('none');
            }

            var r = $(myself._form).getElement(this.options.selectors.companyaddress);
            var countrySelect = this.options.containers.step2.getElements(this.options.selectors.countryselect)[0];
            var c = 'PL' == countrySelect.get('value').toUpperCase().replace(/[^A-Z]/g, '');
            if($chk(r)) {
                myself._sub(myself._form.getElement(this.options.selectors.formcompanyname), r.checked);
                myself._sub(myself._form.getElement(this.options.selectors.formtaxid), r.checked);

                myself._sub(myself._form.getElement(this.options.selectors.formpesel), c && r.checked == false);

                myself._sub(myself._form.getElement(this.options.selectors.formcompanyname2), i.checked); //another address
                //myself._sub(myself._form.getElement('input[name=coname2]'), r.checked && i.checked); // another address & company
                myself._sub(myself._form.getElement(this.options.selectors.formtaxid2), i.checked); //another address
                //myself._sub(myself._form.getElement('input[name=nip2]'), r.checked && i.checked); // another address & company
            }
        }).pass([
            this.options.containers.step2.getElements('form').pop(),
            function(el, show) {
                if($chk(el)) {
                    var tr = $(el).getElement('! tr');
                    if(tr) {
                        if(true == show) {
                            tr.removeClass('none');
                            tr.getElements('input, select').set('disabled', false);
                        } else {
                            tr.addClass('none');
                            tr.getElements('input, select').set('disabled', true);
                        }
                    }
                }
            }
        ], this);
        f();

        this.options.containers.step2.getElements(this.options.selectors.countryselect).each(function(el) {
            el.addEvent('change', function(e) {
                var v = this.get('value');
                var chkbx = this._class.options.containers.step2.getElement(this._class.options.selectors.differentaddress);
                if(!$chk(chkbx))
                    return;

                if( false == this._class.options.country2Shipping.contains(v) ) {
                    chkbx._can_change = false;
                    if(false == chkbx.checked) {
                        chkbx.checked = true;
                        chkbx.fireEvent('change');
                    }
                } else {
                    chkbx._can_change = true;
                }
            });
            el._class = this;
            el.fireEvent('change');
        }, this);

        this.options.containers.step2.getElements(this.options.selectors.addresstyperadios).each(function(el) {
            el._change = f;
            el.addEvent('change', function(e) {
                this._change();
            })
            if(Browser.ie) el.addEvent('click', function(e) { this.fireEvent('change', e); });
        });

        this.options.containers.step2.getElements(this.options.selectors.differentaddress).each(function(el) {
            el._change = f;
            el.addEvent('change', function(e) {
                if(false == this._can_change && false == this.checked) {
                    (function() {
                        alert( this._class.Shop.get('lang.basket.shipping_different_country') );
                        this.checked = true;
                        this.blur();
                        this._change();
                    }).delay(100, this);
                } else {
                    this._change();
                }
            })
            el._class = this;
            if(Browser.ie) el.addEvent('click', function(e) { this.fireEvent('change', e); });
            el._change();
        }, this);
        this.options.containers.step2.getElements(this.options.selectors.addressselectsubmit).addClass('none');

        this.options.containers.step2.getElements(this.options.selectors.addressselect).each(function(el) {
            el.addEvent('change', function(e) {
                var val = this.get('value').toInt();
                if(val > 0) {
                    var req = new Request.JSON({
                        url : this._class.Shop.url(this._class.options.getaddressurl.substitute({ id : val})),
                        secure : true,
                        async : false,
                        noCache : true,
                        method : 'get',
                        onFailure : function(xhr) {
                            if(200 != this.status)
                                alert(this._class.Shop.get('lang.basket.address_request_error'));
                        },
                        onComplete : function(json) {
                            if($chk(json) && $chk(json.name)) {
                                var n = this._select.get('name').match(/2$/) ? '2' : '';
                                for(var k in json) {
                                    var selector = this._class.options.selectors.addressinput.substitute({
                                        name : k + n
                                    });
                                    this._class.options.containers.step2.getElements(selector).set('value', json[k]);
                                }
                                this._class.options.containers.step2.getElements(this._class.options.selectors.countryselect).fireEvent('change');

                                if('' == n) {
                                    if('' == json.nip && '' == json.coname) {
                                        $$(this._class.options.selectors.personaladdress).set('checked', true).fireEvent('change', null);
                                    } else {
                                        $$(this._class.options.selectors.companyaddress).set('checked', true).fireEvent('change', null);
                                    }
                                }

                                if('2' == n) {
                                    var select = this._class.options.containers.step2.getElement(
                                                    this._class.options.selectors.addressinput.substitute({
                                                        name : 'country2'
                                                    })
                                                  );
                                    if(select.get('value') != json.country) {
                                        select.getElements('option').filter(function(o) { return '' == o.value; }).dispose();
                                        new Element('option', {
                                            value : '',
                                            text : ''
                                        }).inject(select);
                                        select.set('value', '');
                                    }
                                }
                            } else {
                                alert(this._class.Shop.get('lang.basket.address_request_error'));
                            }
                        }
                    });
                    req._select = this;
                    req._class = this._class;
                    req.send();
                } else {
                    var keys = [ 'name','surname','phone','coname','nip','street','zip','city','country' ];
                    var n = this.get('name').match(/2$/) ? '2' : '';
                    for(var x = 0; x < keys.length; ++x) {
                        var selector = this._class.options.selectors.addressinput.substitute({
                            name : keys[x] + n
                        });
                        this._class.options.containers.step2.getElements(selector).set('value', '');
                    }
                    if('2' == n) {
                        var select = this._class.options.containers.step2.getElement(
                                        this._class.options.selectors.addressinput.substitute({
                                            name : 'country2'
                                        })
                                      );
                        select.getElements('option[value=]').dispose();
                    }
                }
            });
            if(Browser.ie) el.addEvent('click', function(e) { this.fireEvent('change', e); });
            el._class = this;
        }, this);
    },

    step_3 : function() {

    }
});








Shop.stockHandler = new Class({
    Implements: [ Events, Options ],

    options : {
        optionsConfiguration : null,
        optionsDefault : null,
        optionCurrentStock : null,
        optionImgWidth : null,
        optionImgHeight : null,
        selectstockselector : 'div.stocks select',
        inputselector : '#box_productfull form.basket input[name^=stock_id]'
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        if($chk(Shop.values.OptionsConfiguration)) {
            this.options.optionsConfiguration = Shop.values.OptionsConfiguration;
        }

        if($chk(Shop.values.OptionsDefault)) {
            this.options.optionsDefault = Shop.values.OptionsDefault;
        }

        if($chk(Shop.values.OptionCurrentStock)) {
            this.options.optionCurrentStock = Shop.values.OptionCurrentStock;
        }

        if($chk(Shop.values.OptionImgWidth)) {
            this.options.optionImgWidth = Shop.values.OptionImgWidth;
        }

        if($chk(Shop.values.OptionImgHeight)) {
            this.options.optionImgHeight = Shop.values.OptionImgHeight;
        }

        if('string' == typeOf(this.options.optionsDefault) && this.options.optionsDefault.length > 0) {
            var d = eval(Base64.decode(this.options.optionsDefault));
            var o = $$(this.options.selectstockselector);
            for(var x = 0; x < o.length; ++x)
                o[x].value = d[x % d.length];
        }

        if('string' == typeOf(this.options.optionsConfiguration) && this.options.optionsConfiguration.length > 0) {

            var d = JSON.decode(Base64.decode(this.options.optionsConfiguration));

            if('string' == typeOf(Shop.values.OptionCurrentStock) && Shop.values.OptionCurrentStock.length > 0)
                Shop.values.OptionCurrentStock = Shop.values.OptionCurrentStock.toInt();

            if(0 == d.length) {
                $$(this.options.selectstockselector).getParent().setStyle('display', 'none');
                return;
            }

            var n = 0;
            var first = null, last = null;
            var list = $$(this.options.selectstockselector);

            var fv = [ ];
            for(var s in d)
                fv.push( d[s][0] );
            fv = fv.unique();
            for(var x = 0; x < list[0].options.length;)
                if(! fv.contains($(list[0].options[x]).get('value')) )
                    list[0].remove(x);
                else
                    ++x;

            if(list.length > 0) {
                list.each(function(el) {
                    el._n = n++;
                    el._conf = d;
                    el._options = Array.from(el.options);
                    el._list = list;

                    el.addEvent('change', function(e) {
                        var values = this._list.get('value');

                        for(var x = this._n + 1; x < this._list.length; ++x) {
                            $(this._list[x]).empty();
                            this._list[x]._values = [];
                        }

                        for(var s in this._conf) {
                            var ok = true;
                            for(var x = 0; x < this._n + 1; ++x) {
                                if(this._list[x].value != this._conf[s][x]) {
                                    ok = false;
                                    break;
                                }
                            }

                            if(true === ok) {
                                for(var x = this._n + 1; x < this._list.length; ++x) {
                                    this._list[x]._values.push(this._conf[s][x]);
                                }
                            } else {

                            }
                        }

                        for(var x = this._n + 1; x < this._list.length; ++x) {
                            this._list[x].addSorted();

                            var vars = [];
                            for(var y = 0; y < this._list[x].options.length; ++y) {
                                vars.push( $(this._list[x].options[y]) );
                            }

                            if( $$(vars).get('value').contains( values[x] ) ) {
                                this._list[x].set('value', values[x]);
                            } else {
                                if(this._list[x].options.length > 1) {
                                    var o = new Option(this._class.Shop.get('lang.common.product_stock_select'), '');
                                    try {
                                        this._list[x].add(o, this._list[x].options[0]);
                                    } catch(e) {
                                        this._list[x].add(o, 0);
                                    }
                                }
                                this._list[x].selectedIndex = 0;
                            }
                        }

                        values = this._list.get('value');
                        if(false == values.contains('')) {
                            values = values.join(',');
                            for(var s in el._conf)
                                if( this._conf[s].join(',') == values )
                                    Shop.stockDownloader.get( this._class.Shop, s.replace('stock_', '').toInt() );
                        } else {
                            $$(this._class.options.inputselector).set('value', '');
                        }

                        for(var x = this._n + 1; x < this._list.length; ++x) {
                            this._list[x].fireEvent('change', null);
                        }
                    });

                    el.addSorted = (function() {
                        for(var x = 0; x < this._options.length; ++x) {
                            if( this._values.contains(this._options[x].value) ) {
                                if(Browser.ie) {
                                    this.add(new Option(
                                        $(this._options[x]).get('html'),
                                        $(this._options[x]).get('value')
                                    ));
                                } else {
                                    this.add(this._options[x], null);
                                }
                            }
                        }
                        this._values = [];
                    }).bind(el);

                    el._class = this;
                }, this);
                list[ list.length - 1 ]._last = true;

                var d = eval(Base64.decode(this.options.optionsDefault));
                if('array' == typeOf(d) && 0 == d.length) {
                    var o = new Option(this.Shop.get('lang.common.product_stock_select'), '');
                    if(Browser.ie) {
                        list[0].add(o, 0);
                    } else {
                        $(o).inject(list[0], 'top');
                    }
                    list[0].selectedIndex = 0;
                }

                list[0].fireEvent('change', null);
            }
        }

    }
});










Shop.pageSlider = new Class({
    Implements: [ Events, Options ],

    options : {
        container_selector : '.pageslider',
        slideslist_selector : 'ul.slides',
        pageslist_selector : 'ul.pages',
        pages_inner : '<li><a href=""><span>{num}</span></a></li>',
        center_pages : true,
        oneimgperpage : true,
        fxslide_class : 'animation_1',
        fxfade_class : 'animation_2',
        fxauto_class : 'animaton_auto',
        emptylink_cursor : 'default',
        fxauto_delay : 5000,
        fxslide_options : {
            duration : 350,
            transition : 'quad:in:out'
        },
        fxfade_options : {
            duration : 700,
            onComplete : function(el) {
                el.dispose();
            }
        }
    },

    periodical_timer : null,

    containers : [],

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        this.containers = $$( this.options.container_selector );
        this.containers.getElements( this.options.pageslist_selector ).empty();
        for(var y = 0; y < this.containers.length; ++y) {
            var c = this.containers[y];
            c.setStyle('overflow', 'hidden');

            var imgs = c.getElements('img');
            c._images = {
                toload : imgs.length,
                loaded : 0
            };

            for(var x = 0; x < imgs.length; ++x) {
                var s = imgs[x].getSize();
                if(s.x > 10 && s.y > 10) {
                    c._images.loaded++;
                } else {
                    imgs[x].addEvent( 'load', (function(c) {
                        c._images.loaded++;
                        if(c._images.loaded == c._images.toload) {
                            this.style(c);
                        }
                    }).pass(c, this) );
                }
            }

            if(c._images.loaded == c._images.toload) {
                this.style(c);
            }
        }
    },

    style : function(container) {
        var ul = container.getElement( this.options.slideslist_selector );
        if(!Browser.opera) {
            ul.setStyle('display', 'none');
        }
        if(Browser.ie) {
            container.setStyle('width', '100%');
        }
        container.setStyles({
            width : container.getSize().x,
            overflow : 'hidden'
        });
        ul.setStyles({
            display: 'block',
            width: '1000in'
        });

        var h = 0;
        var slides = ul.getChildren();
        for(var x = 0; x < slides.length; ++x) {
            var s = slides[x].getSize();
            if(s.y > h) {
                h = s.y;
            }
        }
        if(h > ul.getSize().y)
            ul.setStyle('height', h);

        ul.getElements('a')
        .filter(function(a) { return !$chk(a.get('href')); })
        .setStyle('cursor', this.options.emptylink_cursor )
        .addEvent('click', function(e) {
            new DOMEvent(e).stop();
        });

        if(true == this.options.oneimgperpage) {
            if(!Browser.ie) {
                ul.getElements('li').setStyle( 'min-width', ul.getParent().getSize().x );
            } else {
                ul.getElements('li').setStyles({
                    width : ul.getParent().getSize().x,
                    overflow : 'hidden'
                });
            }
        }

        this.count_pages(container);
    },

    count_pages : function(container) {
        var w = container.getSize().x;
        var imgs = container.getElement( this.options.slideslist_selector ).getChildren();

        var pages = [ 0 ];
        var delta = 0;
        if(true == this.options.oneimgperpage) {
            for(var x = 1; x < imgs.length; ++x) {
                pages.push( imgs[x].getPosition( imgs[x].getParent() ).x );
            }
        } else {
            for(var x = 0; x < imgs.length; ++x) {
                var tmp = imgs[x].getPosition( imgs[x].getParent() ).x - delta;
                if(tmp > w) {
                    pages.push( tmp + delta );
                    delta += tmp;
                }
            }
        }

        container._pages = pages;
        this.make_pages(container, pages.length);
    },

    make_pages : function(container, num) {
        var ul = container.getElement( this.options.pageslist_selector );
        if(!$chk(ul)) return;
        if(1 == num) {
            ul.dispose();
            return;
        }

        var html = '';
        for(var x = 1; x <= num; ++x) {
            html += this.options.pages_inner.substitute({ num : x });
        }
        ul.set('html', html);

        ul.setStyle('float', 'left');
        var w = ul.getSize().x;
        var pw = ul.getParent().getSize().x;
        ul.setStyles({
            float : '',
            left : Math.round( (pw - w) / 2)
        });

        var lis = ul.getChildren();
        for(var x = 0; x < lis.length; ++x) {
            lis[x]._num = x;
            lis[x]._class = this;
            lis[x]._container = container;
        }

        lis.addEvent('click', function(e) {
            new DOMEvent(e).stop();
            this._class.goto( this._container, this._num );
            this._class.periodical( this._container );
        });

        container._current = 0;
        this.goto( container, 0 );
        this.periodical( container );
    },

    periodical : function(container) {
        if($chk(this.periodical_timer)) {
            clearInterval(this.periodical_timer);
        }

        if(container.hasClass( this.options.fxauto_class )) {
            this.periodical_timer = (function(container) {
                                        this.next(container);
                                    }).periodical( this.options.fxauto_delay , this, container);
        }
    },

    goto : function(container, page) {
        if(page != container._current) {
            var ul = container.getElement( this.options.slideslist_selector );
            var l = -1 * container._pages[ page ];

            if(container.hasClass( this.options.fxslide_class )) {
                new Fx.Tween(ul, this.options.fxslide_options).start('left', l);
            } else if(container.hasClass( this.options.fxfade_class ) && !Browser.ie) {
                var nul = ul.clone();
                var pos = ul.getPosition( ul.getParent() );
                nul.setStyles({
                    position : 'absolute',
                    left : pos.x,
                    top : pos.y

                }).inject(ul, 'after');
                ul.setStyle('left', l);
                nul.set('tween', this.options.fxfade_options).fade('out');
            } else {
                ul.setStyle('left', l);
            }
        }

        var pages = container.getElement( this.options.pageslist_selector ).getChildren();
        pages.removeClass('current');
        pages[page].addClass('current');

        container._current = page;
    },

    next : function(container) {
        var p =  container._current + 1;
        if(p == container._pages.length) p = 0;
        this.goto(container, p);
    }
});






Shop.stockDownloader = new Class({
    Implements: [ Events, Options ],

    sid : null,
    stock : null,

    options : {
        sid : null,
        getstockurl : null,
        selectors : { }
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        this.sid = this.options.sid;
        this.get();
    },

    get : function() {
        var request = new Request.JSON({
            url : this.Shop.url( this.options.getstockurl.substitute({
                    sid : this.sid,
                    imgwidth : Shop.values.OptionImgWidth,
                    imgheight : Shop.values.OptionImgHeight
                }) ),
            secure : true,
            async : true,
            noCache : true,
            method : 'get',
            onFailure : function(xhr) {
                alert(this._class.Shop.get('lang.common.product_stock_download_error'));
            },
            onComplete : function(json) {
                if('object' == typeOf(json) && $chk(json.sid) ) {
                    this._class.stock = json;
                    this._class.display();
                } else {
                    alert(this._class.Shop.get('lang.common.product_stock_download_error'));
                }
            }
        });

        request._class = this;
        request.send();
    },

    display : function() {
        var sh = this.Shop.classes.stockHandler;
        if($chk(this.stock) && $chk(this.stock.sid) && sh.options.optionCurrentStock != this.stock.sid) {
            sh.options.optionCurrentStock = this.stock.sid;

            $$(this.options.selectors.stockid).set('value', this.stock.sid);

            if(false != this.stock.photo) {
                var img = $$(this.options.selectors.productimg)[0],
                    stockPhotoName = this.stock.photo.substr(this.stock.photo.lastIndexOf('/') + 1);

                if($chk(img)) {
                    img.set('src', this.stock.photo);

                    if( $$(this.options.selectors.smallgallery).length > 0) {
                        $$(this.options.selectors.smallgallery).each(function(img) {
                            var alt = img.get('alt').substr(img.get('alt').lastIndexOf('/') + 1);

                            if(stockPhotoName.indexOf(alt) != -1) {
                                img.fireEvent('mouseenter');
                            }
                        }, this);
                    } else {
                        var oid = img.get('class').replace(/.*gallery_([0-9]+).*/, '$1');
                        if(img.hasClass('gallery_' + oid))
                            img.removeClass('gallery_' + oid).addClass('gallery_' + this.stock.photo_id);
                    }
                }
            }

            var atd = $$(this.options.selectors.ddavailability).pop();
            if($chk(atd)) {
                atd.set('text', ' ' + this.stock.availability);
                if(false != this.stock.availability_photo)
                    new Element('img', {
                        'src' : this.stock.availability_photo,
                        'alt' : this.stock.availability
                    }).inject(atd, 'top');
            }

            var dtd = $$(this.options.selectors.dddelivery).pop();
            var dtr = $$(this.options.selectors.dtdelivery).pop();
            if($chk(dtd)) {
                if(false == this.stock.delivery) {
                    dtd.addClass('none');
                    dtr.addClass('none');
                } else {
                    dtd.removeClass('none').set('text', ' ' + this.stock.delivery);
                    dtr.removeClass('none');
                }
            }

            var pdiv = $$(this.options.selectors.price).pop();
            if($chk(pdiv)) {
                if(false == this.stock.special_offer) {
                    pdiv.getElements('em').removeClass('color').set('text', this.stock.price);
                    pdiv.getElements('del').addClass('none').set('text', '');
                } else {
                    pdiv.getElements('em').addClass('color').set('text', this.stock.special_offer);
                    pdiv.getElements('del').removeClass('none').set('text', this.stock.price);
                }
            }

            var ndiv = $$(this.options.selectors.nettoprice).pop();
            if($chk(ndiv)) {
                if(false == this.stock.net_special_offer)
                    ndiv.getElements('em').set('text', this.stock.net_price);
                else
                    ndiv.getElements('em').set('text', this.stock.net_special_offer);
            }

            $$(this.options.selectors.addtofav).each(function(el) {
                el.set('href', el.get('href').replace(/\/\w+$/, '/') + this.stock.sid);
            }, this);

            if(true == this.stock.can_buy)
                $$(this.options.selectors.basketform).removeClass('none');
            else
                $$(this.options.selectors.basketform).addClass('none');

            $$(this.options.selectors.unit).set('text', this.stock.unit);
        }
    }
});

Shop.stockDownloader.downloaded = [ ];

Shop.stockDownloader.get = function(shop_instance, sid) {
    if($chk(this.downloaded[sid])) {
        this.downloaded[sid].display();
    } else if(Shop.values.optionCurrentStock != sid) {
        Shop.stockDownloader.options = Shop.stockDownloader.options || { };
        Shop.stockDownloader.options.sid = sid;
        this.downloaded[sid] = shop_instance.subclass('stockDownloader');
    }
}

Shop.breadcrumbsFitter = new Class({
    Implements: [ Events, Options ],

    options : {
        selector : '.breadcrumbs ul.path li',
        max_y_pos : 2,
        dots_tag : null,
        dots_class : null,
        dots_html : null
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;
        this.fit();
    },

    fit : function() {
        var breads = $$(this.options.selector);
        if($chk(breads) && breads.length > 2) {
            var ul = breads[0].getParent();
            if(ul.getPosition(ul.getParent()).y > this.options.max_y_pos) {
                new Element(this.options.dots_tag, {
                    'class' : this.options.dots_class,
                    html : this.options.dots_html
                }).inject(breads[0], 'after');
                while(ul.getPosition(ul.getParent()).y > this.options.max_y_pos) {
                    var chs = ul.getChildren();
                    if(chs.length > 3) {
                        ul.getChildren()[2].dispose();
                    } else {
                        break;
                    }
                }
            }
        }
    }
});

Shop.filterPrice = new Class({
    Implements: [ Events, Options ],

    options : {
        selectors : {
            inputprice1 : '#filterprice1',
            inputprice2 : '#filterprice2',
            buttonprice : '#filterprice'
        }
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        var if1 = $$(this.options.selectors.inputprice1).pop();
        var if2 = $$(this.options.selectors.inputprice2).pop();
        var ifb = $$(this.options.selectors.buttonprice).pop();
        if(!!if1 && !!if2 && !!ifb) {
            ifb._if1 = if1;
            ifb._if2 = if2;
            if1._ifb = ifb;
            if2._ifb = ifb;

            ifb.removeEvents('click').addEvent('click', function(e) {
                if(!!e) {
                    new DOMEvent(e).stop();
                }

                var f1 = ifb._if1.get('value').replace(/\s+/g, '').replace(',', '.');
                var f2 = ifb._if2.get('value').replace(/\s+/g, '').replace(',', '.');

                if(f1.length) {
                    if(f2.length) {
                        var url = Shop.values.PriceFilterFromTo;
                    } else {
                        var url = Shop.values.PriceFilterFrom;
                    }
                } else {
                    if(f2.length) {
                        var url = Shop.values.PriceFilterTo;
                    } else {
                        return false;
                    }
                }

                if('string' != typeOf(url) || 0 == url.length) {
                    return false;
                }

                window.location.href = url.substitute({
                    pricefrom : f1,
                    priceto : f2
                });
            });

            if1.addEvent('keypress', function(e) {
                if(13 == e.code) {
                    this._ifb.fireEvent('click');
                }
            });

            if2.addEvent('keypress', function(e) {
                if(13 == e.code) {
                    this._ifb.fireEvent('click');
                }
            });
        }
    }
})

Shop.filterSelects = new Class({
    Implements: [ Events, Options ],

    options : {
        selectors : {
            lists : '#box_filter .innerbox ul',
            listitems : 'li',
            listlabel : 'span',
            listcount : 'em',
            selectedclass : 'selected'
        },
        label_separator : ', ',
        hidelistwithone : false,
        limit : 10,
        showmorehtml : '<a href="" class=""><span>{text} &raquo;</span></a>',
        showlesshtml : '<a href="" class=""><span>&laquo; {text}</span></a>'
    },

    current : {
        slct : null,
        ovrl : null
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        var lists = $$(this.options.selectors.lists);
        for(var x = 0; x < lists.length; ++x) {
            var list = $(lists[x]).addClass('none');
            var elements = list.getElements(this.options.selectors.listitems);

            if(true == this.options.hidelistwithone && elements.getElements('a').length < 2) {
                if(0 == elements.filter(function(e) { return e.hasClass(this.options.selectors.selectedclass); }, this).length) {
                    list.getParent().addClass('none');
                    continue;
                }
            }

            list.getElements('.spanhover').removeClass('spanhover');

            var lbl = [];
            var cls = '';
            for(var y = 0; y < elements.length; ++y) {
                var el = elements[y];
                if(el.hasClass(this.options.selectors.selectedclass)) {
                    lbl.push(el.getElement(this.options.selectors.listlabel).get('text'));
                    cls = this.options.selectors.selectedclass;
                }

                var id = el.get('id');
                if(!!id) {
                    id = id.replace(/^filter_(.+)_\d+$/, 'filter_type_$1');
                    if(id.match(/type/)) {
                        el.addClass(id);
                    }
                }
            }
            if(0 == lbl.length) {
                lbl = this.Shop.get('lang.common.product_stock_select');
            } else {
                lbl = lbl.join(this.options.label_separator);
            }

            var select = new Element('div', {
                'class' : 'multiselect folden ' + cls,
                text : lbl
            }).inject(list, 'before');
            select.unselectable = true;

            var button = new Element('div', {
                'class' : 'button'
            }).inject(select);

            var ovrl = new Element('div', {
                'class' : 'none filter_overlay'
            }).inject(document.body);

            list.inject(ovrl).removeClass('none');

            list._moreless = new Shop.filterFolder({
                selectors : {
                    lists : list
                },
                showmorehtml : this.options.showmorehtml,
                showlesshtml : this.options.showlesshtml,
                limit : this.options.limit
            }, this.Shop);

            elements.addEvent('click', function(e) {
                new DOMEvent(e).stop();
                var a = $(this).getElement('a');
                if(!!a) {
                    window.location.href = a.get('href');
                }
            });

            select.addEvent('click', (function(e) {
                new DOMEvent(e).stop();
                if(true == this[0]._folden) {
                    this[2].showoverlay( this[0], this[1] );
                    this[0]._folden = false;
                } else {
                    this[2].hidecurrent();
                }
            }).bind([select, ovrl, this]) );
            select._folden = true;
        }

        $(document.body).addEvent( (Browser.Platform.ios ? 'mouseup' : 'click'), function(e) {
            $(window).fireEvent('resize', e);
        });

        $(window).addEvent('resize', this.hidecurrent.bind(this));
    },

    showoverlay : function(slct, ovrl) {
        this.hidecurrent();

        var c = Object.append(slct.getCoordinates(), slct.getComputedSize());
        ovrl.removeClass('none').setStyles({
            top: c.bottom - 1,
            left: c.left,
            'min-width': 1.1 * c.width + c['padding-left'] + c['padding-right']
        });
        slct.addClass('showed').removeClass('folden');

        this.current.slct = slct;
        this.current.ovrl = ovrl;
    },

    hidecurrent : function() {
        if(!!this.current.slct) {
            this.current.slct.removeClass('showed').addClass('folden');
            this.current.slct._folden = true;
            this.current.slct = null;
        }
        if(!!this.current.ovrl) {
            this.current.ovrl.addClass('none');
            this.current.ovrl = null;
        }
    }
});

Shop.filterFolder = new Class({
    Implements: [ Events, Options ],

    options : {
        selectors : {
            lists : '#box_filter .innerbox ul',
            listfoldclass : 'foldable',
            listitems : 'li',
            listcount : 'em'
        },
        showmoretag : 'li',
        showlesstag : 'li',
        showmorehtml : '<a href="" class="spanhover"><span>{text} &raquo;</span></a>',
        showlesshtml : '<a href="" class="spanhover"><span>&laquo; {text}</span></a>',
        showmoretext : false,
        showlesstext : false,
        limit : 5,
        skipclass : 'selected',
        emptyclass : 'empty',
        hidelistwithone : false
    },

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        if(false == this.options.showmoretext) {
            this.options.showmoretext = this.Shop.get('lang.filter.show_more')
        }

        if(false == this.options.showlesstext) {
            this.options.showlesstext = this.Shop.get('lang.filter.show_less')
        }

        var lists = $$(this.options.selectors.lists);
        for(var x = 0; x < lists.length; ++x) {
            var elements = lists[x].getElements(this.options.selectors.listitems);
            if( true == this.options.hidelistwithone && elements.getElements('a').length < 2 ) {
                if(0 == elements.filter(function(e) { return e.hasClass(this.options.selectors.selectedclass); }, this).length) {
                    lists[x].getParent().addClass('none');
                    continue;
                }
            }

            if(lists[x].hasClass(this.options.selectors.listfoldclass)) {
                var tohide = this.get2hide( lists[x] );
                if( tohide.length ) {
                    lists[x]._tohide = tohide;
                    this.hide( lists[x] );
                }
            }
        }
    },

    get2hide : function( list ) {
        var items = list.getElements(this.options.selectors.listitems);
        var limit = this.options.limit - list.getElements('.' + this.options.skipclass).length;
        var tohide = [];
        items.sort( this.sort.bind(this) );
        var skipped = 0;
        for(var x = 0; x < items.length; ++x) {
            if(!items[x].hasClass(this.options.skipclass)) {
                if(skipped == limit || items[x].hasClass(this.options.emptyclass)) {
                    tohide.push(items[x]);
                } else {
                    skipped++;
                }
            }
        }

        return tohide;
    },

    hide : function( list ) {
        $$(list._tohide).addClass('none');

        var m = new Element(this.options.showmoretag, {
            html : this.options.showmorehtml.substitute({ text : this.options.showmoretext }),
            'class' : 'showmore'
        })
        .addEvent('click', function(e) {
            new DOMEvent(e).stop();
            this._class.show( this._list );
            $(this).dispose();
        })
        .inject(list, 'bottom');
        m._list = list;
        m._class = this;
    },

    show : function( list ) {
        $$(list._tohide).removeClass('none');

        var m = new Element(this.options.showlesstag, {
            html : this.options.showlesshtml.substitute({ text : this.options.showlesstext }),
            'class' : 'showmore'
        })
        .addEvent('click', function(e) {
            new DOMEvent(e).stop();
            this._class.hide( this._list );
            $(this).dispose();
        })
        .inject(list, 'bottom');
        m._list = list;
        m._class = this;
    },

    sort : function(x, y) {
        var xv = x.getElement( this.options.selectors.listcount );
        if(!!xv) {
            xv = xv.get('text').replace(/[^0-9]/g, '').toInt();
        } else {
            xv = 0;
        }

        var yv = y.getElement( this.options.selectors.listcount );
        if(!!yv) {
            yv = yv.get('text').replace(/[^0-9]/g, '').toInt();
        } else {
            yv = 0;
        }

        return yv - xv;
    }
});

Shop.ajaxBasket = new Class({
    Implements: [ Events, Options ],

    options : {
        form_selector : '.basket form[method=post][action], form.basket[method=post][action]',
        fullprod_selector : '! #box_productfull',
        container_id : 'ajaxbasket',
        main_class : 'ajaxbasket mask_box',
        bb_class : 'bottombuttons',
        basket_quantities : [
            '.header ul.basket li.count b.count',
            '#box_basket .innerbox p.products em'
        ],
        basket_sums : [
            '.header ul.basket li.count b.sum',
            '#box_basket .innerbox p.sum em'
        ],
        insert_px1 : true,
        container : null,
        request_options : {
            useSpinner : false,
            emulation : false,
            evalScripts : false,
            url : null
        }
    },

    json : null,
    mask : null,
    event : null,
    div : null,

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        if(null === this.options.container) {
            this.options.container = new Element('div', {
                id : this.options.container_id
            }).addClass('none').inject(document.body);
        }

        $$(this.options.form_selector).each((function(form) {
            var fp = form.getElement(this.options.fullprod_selector);
            if(!fp) {
                this.wrapform(form);
            }
        }).bind(this));
    },

    wrapform : function(form) {
        form._request = new Form.Request(form, this.options.container, {
            requestOptions : this.options.request_options,
            onSuccess : this.sent.bind(this),
            onFailure : this.failure.bind(this)
        });

        if(Browser.Platform.ios) {
            form.removeEvents('click:relay(button, input[type=submit])')
                .getElements('button, input[type=submit]')
                .removeEvents('click')
                .addEvent('click', (function(e) {
                    e.stop();
                    this.send();
            }).bind(form._request));
        }
    },

    sent : function(container) {
        var json = JSON.decode(this.options.container.get('text'));
        this.options.container.empty();
        if('object' === typeOf(json)) {
            this.json = json;
            if(!this.json.added || 0 == this.json.added.length) {
                this.error();
            } else {
                this.display();
            }
        } else {
            this.failure();
        }
    },

    failure : function() {
        alert(this.Shop.get('lang.ajaxbasket.submit_error'));
    },

    error : function() {
        if(this.json.messages.error.length || this.json.messages.warning.length) {
            if(this.json.messages.error.length) {
                alert(this.json.messages.error[0]);
            } else {
                alert(this.json.messages.warning[0]);
            }
        } else {
            this.failure();
        }
    },

    display : function() {
        if(!this.mask) {
            this.mask = this.Shop.subclass('mask');
        }

        this.mask.show();
        var div = this.div = new Element('div', {
            'class' : this.options.main_class
        }).inject(document.body);

        new Element('h3', {
            text : this.Shop.get('lang.ajaxbasket.product_added')
        }).inject(div);

        var ul = new Element('ul').inject(div);
        for(var x = 0; x < this.json.added.length; ++x) {
            new Element('li', {
                text : this.Shop.get('lang.ajaxbasket.product_name').substitute({
                    name : this.json.added[x].name,
                    quantity : this.json.added[x].quantity,
                    unit : this.json.added[x].unit
                })
            }).inject(ul);
        }

        new Element('h4', {
            html : this.Shop.get('lang.ajaxbasket.basket_items').substitute({
                count : this.json.basket.count,
                sum : this.json.basket.sum
            })
        }).inject(div);

        var bb = new Element('div', {
            'class' : this.options.bb_class
        }).inject(div);

        var b1 = new Element('button', {
            type : 'button',
            'class' : 'button'
        }).inject(bb);

        if(this.options.insert_px1) {
            new Element('img', {
                'class' : 'px1',
                src : this.Shop.url( this.Shop.get('px1') )
            }).inject(b1);
        }

        new Element('span', {
            text : this.Shop.get('lang.ajaxbasket.continue_shopping')
        }).inject(b1);

        var b2 = new Element('button', {
            type : 'button',
            'class' : 'button important'
        }).inject(bb);

        if(this.options.insert_px1) {
            new Element('img', {
                'class' : 'px1',
                src : this.Shop.url( this.Shop.get('px1') )
            }).inject(b2);
        }

        new Element('span', {
            text : this.Shop.get('lang.ajaxbasket.goto_basket')
        }).inject(b2);

        var c = new Element('div', {
            'class' : 'close'
        }).inject(div);

        div.position();
        var ws = window.getScroll();
        if( ws.x > 0 || ws.y > 0 ) {
            var p = div.getPosition();
            p.x -= ws.x;
            p.y -= ws.y;
            div.setStyles({
                position : 'fixed',
                left : p.x,
                top : p.y
            });
        } else {
            div.setStyle('position', 'fixed');
        }

        for(var x = 0; x < this.options.basket_quantities.length; ++x) {
            $$(this.options.basket_quantities[x]).set('text', this.json.basket.count)
        };
        for(var x = 0; x < this.options.basket_sums.length; ++x) {
            $$(this.options.basket_sums[x]).set('text', this.json.basket.sum);
        }


        this.event = (function(e) {
            if(27 === e.code) {
                this.close();
            }
        }).bind(this);
        c.addEvent('click', this.close.bind(this));
        b1.addEvent('click', this.close.bind(this));
        b2.addEvent('click', (function() {
            window.location.pathname = this.json.basket.url;
        }).bind(this));
        document.body.addEvent('keyup', this.event);
    },

    close : function() {
        this.div.dispose();
        this.div = null;
        this.mask.destroy();
        this.mask = null;
        document.body.removeEvent('keyup', this.event);
    }
});

Shop.mask = new Class({
    Implements: [ Events, Options ],

    options : {
        'target' : null,
        'class' : 'mask'
    },

    visible : false,
    element : null,
    event : null,

    initialize : function(options, shop_class) {
        this.setOptions(options);
        this.Shop = shop_class;

        this.element = new Element('div', {
            'class' : this.options['class']
        }).inject(document.body);

        if(!Browser.Platform.ios) {
            [ 'mousedown', 'mouseup', 'mousemove', 'click', 'dblclick' ].each(function(el) {
                this.element.addEvent(el, this.stop.bind(this));
            }, this);
            this.element.ondragstart = Function.from(false);
        }

        this.event = this.resize.bind(this);
        window.addEvent('resize', this.event);

        this.hide();
    },

    toggle : function() {
        if(false == this.visible) {
            this.show();
        } else {
            this.hide();
        }
    },

    stop : function(e) {
        if(Browser.Platform.ios) {
            e.stopPropagation();
        } else {
            (new DOMEvent(e)).stopPropagation();
        }
    },

    show : function() {
        this.element.removeClass('none');
        this.visible = true;
        this.position().resize();
        return this;
    },

    hide : function() {
        this.element.addClass('none');
        this.visible = false;
        return this;
    },

    position : function() {
        return this;
    },

    resize : function() {
        var s = window.getSize();
        this.element.setStyles({
            width: s.x,
            height: s.y
        });
        return this;
    },

    destroy : function() {
        window.removeEvent('resize', this.event);
        this.element.dispose();
        this.visible = false;
        return this;
    }
});

Shop.galleryInit = function() {
    if(!!window.Milkbox && !!Milkbox._version && Milkbox._version.substring(0, 1).toInt() >= 3) {
        var opts = this.get('useroptions.milkbox');
        opts.imageOfText = this.get('lang.milkbox.x_of_y');
        $$('*[rel^=milkbox]').each(function(el) {
            el.set('data-milkbox', el.get('rel'));
            el.set('rel', null);
        });
        var m = new Milkbox(opts);
        $$('a[data-milkbox^=milkbox]').each(function(a) {
            a._milkbox = this;
        }, m);
    }
}

Shop.useroptions.milkbox = {
    autoSize: true,
    autoPlay: false,
    maxHeight: 0
}

Shop.useroptions.prevent = false;
Shop.mask.condition = Function.from(true);
Shop.fadingText.condition = Function.from(true);
Shop.stockDownloader.condition = Function.from(true);





//Language pre-back (fallback, but before ;)
Shop.lang = JSON.decode('{"common":{"product_vote_alert":"","product_stock_select":"","product_stock_download_error":""},"voting":{"vote_n":""},"basket":{"address_request_error":""}}');
//MD5 (Message-Digest Algorithm), http://www.webtoolkit.info/
var MD5=function(s){function L(b,a){return(b<<a)|(b>>>(32-a))}function K(k,b){var F,a,d,x,c;d=(k&2147483648);x=(b&2147483648);F=(k&1073741824);a=(b&1073741824);c=(k&1073741823)+(b&1073741823);if(F&a){return(c^2147483648^d^x)}if(F|a){if(c&1073741824){return(c^3221225472^d^x)}else{return(c^1073741824^d^x)}}else{return(c^d^x)}}function r(a,c,b){return(a&c)|((~a)&b)}function q(a,c,b){return(a&b)|(c&(~b))}function p(a,c,b){return(a^c^b)}function n(a,c,b){return(c^(a|(~b)))}function u(G,F,aa,Z,k,H,I){G=K(G,K(K(r(F,aa,Z),k),I));return K(L(G,H),F)}function f(G,F,aa,Z,k,H,I){G=K(G,K(K(q(F,aa,Z),k),I));return K(L(G,H),F)}function D(G,F,aa,Z,k,H,I){G=K(G,K(K(p(F,aa,Z),k),I));return K(L(G,H),F)}function t(G,F,aa,Z,k,H,I){G=K(G,K(K(n(F,aa,Z),k),I));return K(L(G,H),F)}function e(k){var G;var d=k.length;var c=d+8;var b=(c-(c%64))/64;var F=(b+1)*16;var H=Array(F-1);var a=0;var x=0;while(x<d){G=(x-(x%4))/4;a=(x%4)*8;H[G]=(H[G]|(k.charCodeAt(x)<<a));x++}G=(x-(x%4))/4;a=(x%4)*8;H[G]=H[G]|(128<<a);H[F-2]=d<<3;H[F-1]=d>>>29;return H}function B(c){var b="",d="",k,a;for(a=0;a<=3;a++){k=(c>>>(a*8))&255;d="0"+k.toString(16);b=b+d.substr(d.length-2,2)}return b}function J(b){b=b.replace(/\r\n/g,"\n");var a="";for(var k=0;k<b.length;k++){var d=b.charCodeAt(k);if(d<128){a+=String.fromCharCode(d)}else{if((d>127)&&(d<2048)){a+=String.fromCharCode((d>>6)|192);a+=String.fromCharCode((d&63)|128)}else{a+=String.fromCharCode((d>>12)|224);a+=String.fromCharCode(((d>>6)&63)|128);a+=String.fromCharCode((d&63)|128)}}}return a}var C=Array();var P,h,E,v,g,Y,X,W,V;var S=7,Q=12,N=17,M=22;var A=5,z=9,y=14,w=20;var o=4,m=11,l=16,j=23;var U=6,T=10,R=15,O=21;s=J(s);C=e(s);Y=1732584193;X=4023233417;W=2562383102;V=271733878;for(P=0;P<C.length;P+=16){h=Y;E=X;v=W;g=V;Y=u(Y,X,W,V,C[P+0],S,3614090360);V=u(V,Y,X,W,C[P+1],Q,3905402710);W=u(W,V,Y,X,C[P+2],N,606105819);X=u(X,W,V,Y,C[P+3],M,3250441966);Y=u(Y,X,W,V,C[P+4],S,4118548399);V=u(V,Y,X,W,C[P+5],Q,1200080426);W=u(W,V,Y,X,C[P+6],N,2821735955);X=u(X,W,V,Y,C[P+7],M,4249261313);Y=u(Y,X,W,V,C[P+8],S,1770035416);V=u(V,Y,X,W,C[P+9],Q,2336552879);W=u(W,V,Y,X,C[P+10],N,4294925233);X=u(X,W,V,Y,C[P+11],M,2304563134);Y=u(Y,X,W,V,C[P+12],S,1804603682);V=u(V,Y,X,W,C[P+13],Q,4254626195);W=u(W,V,Y,X,C[P+14],N,2792965006);X=u(X,W,V,Y,C[P+15],M,1236535329);Y=f(Y,X,W,V,C[P+1],A,4129170786);V=f(V,Y,X,W,C[P+6],z,3225465664);W=f(W,V,Y,X,C[P+11],y,643717713);X=f(X,W,V,Y,C[P+0],w,3921069994);Y=f(Y,X,W,V,C[P+5],A,3593408605);V=f(V,Y,X,W,C[P+10],z,38016083);W=f(W,V,Y,X,C[P+15],y,3634488961);X=f(X,W,V,Y,C[P+4],w,3889429448);Y=f(Y,X,W,V,C[P+9],A,568446438);V=f(V,Y,X,W,C[P+14],z,3275163606);W=f(W,V,Y,X,C[P+3],y,4107603335);X=f(X,W,V,Y,C[P+8],w,1163531501);Y=f(Y,X,W,V,C[P+13],A,2850285829);V=f(V,Y,X,W,C[P+2],z,4243563512);W=f(W,V,Y,X,C[P+7],y,1735328473);X=f(X,W,V,Y,C[P+12],w,2368359562);Y=D(Y,X,W,V,C[P+5],o,4294588738);V=D(V,Y,X,W,C[P+8],m,2272392833);W=D(W,V,Y,X,C[P+11],l,1839030562);X=D(X,W,V,Y,C[P+14],j,4259657740);Y=D(Y,X,W,V,C[P+1],o,2763975236);V=D(V,Y,X,W,C[P+4],m,1272893353);W=D(W,V,Y,X,C[P+7],l,4139469664);X=D(X,W,V,Y,C[P+10],j,3200236656);Y=D(Y,X,W,V,C[P+13],o,681279174);V=D(V,Y,X,W,C[P+0],m,3936430074);W=D(W,V,Y,X,C[P+3],l,3572445317);X=D(X,W,V,Y,C[P+6],j,76029189);Y=D(Y,X,W,V,C[P+9],o,3654602809);V=D(V,Y,X,W,C[P+12],m,3873151461);W=D(W,V,Y,X,C[P+15],l,530742520);X=D(X,W,V,Y,C[P+2],j,3299628645);Y=t(Y,X,W,V,C[P+0],U,4096336452);V=t(V,Y,X,W,C[P+7],T,1126891415);W=t(W,V,Y,X,C[P+14],R,2878612391);X=t(X,W,V,Y,C[P+5],O,4237533241);Y=t(Y,X,W,V,C[P+12],U,1700485571);V=t(V,Y,X,W,C[P+3],T,2399980690);W=t(W,V,Y,X,C[P+10],R,4293915773);X=t(X,W,V,Y,C[P+1],O,2240044497);Y=t(Y,X,W,V,C[P+8],U,1873313359);V=t(V,Y,X,W,C[P+15],T,4264355552);W=t(W,V,Y,X,C[P+6],R,2734768916);X=t(X,W,V,Y,C[P+13],O,1309151649);Y=t(Y,X,W,V,C[P+4],U,4149444226);V=t(V,Y,X,W,C[P+11],T,3174756917);W=t(W,V,Y,X,C[P+2],R,718787259);X=t(X,W,V,Y,C[P+9],O,3951481745);Y=K(Y,h);X=K(X,E);W=K(W,v);V=K(V,g)}var i=B(Y)+B(X)+B(W)+B(V);return i.toLowerCase()};
//console4Opera
try { if(!window.console) window.console = { }; if(!console.log) console.log = Function.from(); if(!console.debug) console.debug = Function.from(); if(!console.info) console.info = console.warn = console.error = console.profile = console.profileEnd = Function.from(); } catch(e) { }
//Base64
var Base64={charpool:'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',encode:function(e){var b="",a=0;var j,h,f,i,g,d,c;while(a<e.length){j=e.charCodeAt(a++);h=e.charCodeAt(a++);f=e.charCodeAt(a++);i=j>>2;g=((j&3)<<4)|(h>>4);d=((h&15)<<2)|(f>>6);c=f&63;if(isNaN(h)){d=c=64}else{if(isNaN(f)){c=64}}b+=this.charpool.charAt(i)+this.charpool.charAt(g)+this.charpool.charAt(d)+this.charpool.charAt(c)}return b},decode:function(e){var b="",a=0;var j,h,f,i,g,d,c;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(a<e.length){i=this.charpool.indexOf(e.charAt(a++));g=this.charpool.indexOf(e.charAt(a++));d=this.charpool.indexOf(e.charAt(a++));c=this.charpool.indexOf(e.charAt(a++));j=(i<<2)|(g>>4);h=((g&15)<<4)|(d>>2);f=((d&3)<<6)|c;b+=String.fromCharCode(j);if(d!=64){b+=String.fromCharCode(h)}if(c!=64){b+=String.fromCharCode(f)}}return b}};
//Currency format, http://snipplr.com/view/3516/mootools--numberformat/
Number.implement({ numberFormat : function(decimals, dec_point, thousands_sep) { decimals = Math.abs(decimals) + 1 ? decimals : 2; dec_point = dec_point || '.'; thousands_sep = thousands_sep || ','; var matches = /(-)?(\d+)(\.\d+)?/.exec((isNaN(this) ? 0 : this) + '');  var remainder = matches[2].length > 3 ? matches[2].length % 3 : 0; return (matches[1] ? matches[1] : '') + (remainder ? matches[2].substr(0, remainder) + thousands_sep : '') + matches[2].substr(remainder).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep) + (decimals ? dec_point + (+matches[3] || 0).toFixed(decimals).substr(2) : ''); } });
//Element
Element.implement({isHidden: function(){var c = this.getComputedSize();return (0 == c.totalWidth && 0 == c.totalHeight ? true : ( 'none' == this.getStyle('display') ? true : false ) );},'isVisible': function(){return !this.isHidden();}});
//$chk
var $chk = function(obj) { return !!(obj || obj === 0); };

