new Namespace("eu.mckinley.products.colors");
eu.mckinley.products.colors = Class.create({

    elem : false,
    ajaxurl : "/?controller=product&action=getcolorimage&language=",
    id : 0,

    initialize : function (elem) {


        this.ajaxurl = this.ajaxurl + websiteconfig["language"];
        this.id = websiteconfig["product"];

        $(elem).observe('change', this.change.bind(this));
        this.elem = elem;

    },

    change : function (i) {

        var val = $(this.elem).getValue();
        var value = encodeURI(val);
        new Ajax.Request(this.ajaxurl, {
            method: 'get',
            parameters: 'id=' + this.id + "&color=" + value,
            onComplete: function (resp) {
                var response = resp.responseText;

                var data = eval('(' + response + ')');

                if ((typeof (data.img1) == "string") && typeof (data.thumbnail1) == "string") {
                    var productflashvars = {
                        img1 : data.img1,
                        thumbnail1 : data.thumbnail1
                    };
                    var params = {
                        quality: 'high',
                        wmode: 'transparent',
                        scale: 'scale',
                        allowScriptAccess: 'sameDomain'
                    };

                    var playerVersion = swfobject.getFlashPlayerVersion();
                    if (playerVersion.major >= 9) {
                        swfobject.embedSWF("/static/swf/zoomer.swf", "productzoom", "380", "390", "8.0.0", "/static/swf/expressInstall.swf", productflashvars, params);
                    }
                    else {
                        $("productzoom").update("<img src='" + data.image + "' alt='' />");
                    }
                }
            }
        });

    }
});

