﻿Type.registerNamespace("Res.Commerce.Web.Composants.FicheProduit.V01");

Res.Commerce.Web.Composants.FicheProduit.V01.VisuelsProduit = function (element) {
    Res.Commerce.Web.Composants.FicheProduit.V01.VisuelsProduit.initializeBase(this, [element]);

    this._ClassZoomClickEvent = null;
    this._IdZoomClickEvent = null;
    this._HplVideo = null;
    this.LstSlideVideo = null;
    this._IdDivZoom = null;
    this._IdUlVignette = null;
    this._ZoomDataSource = null;
    this._rolloverDispoActif = null;
    this._idRolloverDispo = null;
};

Res.Commerce.Web.Composants.FicheProduit.V01.VisuelsProduit.prototype = {
    initialize: function () {
        Res.Commerce.Web.Composants.FicheProduit.V01.VisuelsProduit.callBaseMethod(this, "initialize");

        this.initialise_video();

        this._HplVideo = $(this.FormatId('#' + this._IdUlVignette + ' a'));
        this._HplVideo.live('click', Function.createDelegate(this, this.updateLinkVideo));

        if (this._IdDivZoom) {
            var divZoom = $(this.FormatId("#" + this._IdDivZoom));
            if (divZoom != null) {
                divZoom.click(Function.createDelegate(this, this.OnClickDivZoom));
            }
        }
    },
    dispose: function () {
        this._HplVideo.die('click');
        Res.Commerce.Web.Composants.FicheProduit.V01.VisuelsProduit.callBaseMethod(this, "dispose");
    },
    saveClientState: function () {
        return null;
    },
    ClickDivZoom: function (func) {
        $('#' + this._element.id).live("VisuelsZoomProduit", func);
    },
    OnClickDivZoom: function (ev) {
        if (ev != null) {
            ev.preventDefault();
            var event = jQuery.Event("VisuelsZoomProduit");
            event.IdElement = this._element.id;
            $('#' + this._element.id).trigger(event);
        }
    },
    SetImageColoris: function (urlimage) {
        if (urlimage != null) {
            var pathImage = urlimage.split('/');
            var image = $(this.FormatId(".memo_fp_vue_produit_supp")).find("img[src$=" + pathImage[pathImage.length - 1] + "]");
            var li = image.parent();
            if (typeof (li) != 'undefined') {
                this._savedImage = null;
                this.SelectImage(this.FormatId("#" + li.attr("id")));
            }
        }
    },
    initialise_video: function () {
        if (this.get_LstSlideVideo() == null) return;

        if (this.get_LstSlideVideo().length > 0) {
            var lst = this.get_LstSlideVideo();
            jQuery.each(lst, function () {
                var so = new SWFObject('/Video/player.swf', 'mpl', this.Width, this.Height, '9');
                so.addParam('allowfullscreen', 'true');
                so.addParam('allowscriptaccess', 'always');
                so.addParam('wmode', 'opaque');
                //Si la vidéo n'est pas au premier plan, on ne la chargera qu'au click
                if (this.Ordre == '1') {
                    so.addVariable('file', this.UrlMediaNavigation);
                }
                else {
                    so.addVariable('file', '');
                }
                so.addVariable('backcolor', this.Color);
                so.addVariable('autostart', 'true');
                so.addVariable('repeat', 'always');
                so.write(this.IdComposant);
            });
        }
    },

    updateLinkVideo: function (ev) {
        if ($(ev.currentTarget).attr('rel') == 'video') {

            var _IdSlide = $(ev.currentTarget).attr('href');
            var _lst = this.get_LstSlideVideo();

            //On supprime le lecteur précédent
            $(this.FormatId('#mpl')).remove();

            if (this.get_LstSlideVideo().length > 0) {
                jQuery.each(_lst, function () {
                    if ('#' + this.IdComposant == _IdSlide) {
                        var so = new SWFObject('/Video/player.swf', 'mpl', this.Width, this.Height, '9');
                        so.addParam('allowfullscreen', 'true');
                        so.addParam('allowscriptaccess', 'always');
                        so.addParam('wmode', 'opaque');
                        so.addVariable('file', this.UrlMediaNavigation);
                        so.addVariable('backcolor', this.Color);
                        so.addVariable('autostart', 'true');
                        so.addVariable('repeat', 'always');
                        so.write(this.IdComposant);
                    }
                });
            }
        }
    },

    get_IdDivZoom: function () {
        return this._IdDivZoom;
    },
    set_IdDivZoom: function (value) {
        this._IdDivZoom = value;
    },
    get_IdUlVignette: function () {
        return this._IdUlVignette;
    },
    set_IdUlVignette: function (value) {
        this._IdUlVignette = value;
    },
    get_LstSlideVideo: function () {
        return this.LstSlideVideo;
    },
    set_LstSlideVideo: function (value) {
        this.LstSlideVideo = value;
    },
    get_ZoomDataSource: function () {
        return this._ZoomDataSource;
    },
    set_ZoomDataSource: function (value) {
        this._ZoomDataSource = value;
    },
    get_RolloverDispoActif: function () {
        return this._rolloverDispoActif;
    },
    set_RolloverDispoActif: function (value) {
        this._rolloverDispoActif = value;
    },
    get_IdRolloverDispo: function () {
        return this._idRolloverDispo;
    },
    set_IdRolloverDispo: function (value) {
        this._idRolloverDispo = value;
    }

};
Res.Commerce.Web.Composants.FicheProduit.V01.VisuelsProduit.registerClass("Res.Commerce.Web.Composants.FicheProduit.V01.VisuelsProduit", Res.Commerce.Web.Composants.SlideShow);
if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();



