box.store("lop").addConstructor("capsule",function(f,g){var d,l,m,a,i,b,h,j=/cap-page-(\S+)/,c=/-(?:off|on)\./i,e=/[a-zA-Z0-9._-]+$/,k;d=function(o){o.currentlyOK=false;o.available=true;o.msgElm.html(o.msgError);var n=o.success===0;if(n){o.available=false;o.msgElm.element.find("a").remove();}o.boxPublish("error",{action:"load",reset:o.resetting});o.resetting=false;if(n){o.boxPublish("initcomplete",{status:"error"});}o.msgElm.applyStyles(o.msgStyles);};a=function(n){return n==="-on."?"-off.":"-on.";};l=function(n){return function(q){var p=q.target,o=p.src;if(p.tagName==="IMG"&&c.test(o)){p.src=p.src.replace(c,a);f(p).mouseout(m(n));}};};m=function(n){return function(){f(this).unbind("mouseout");this.src=this.src.replace(c,a);};};i=function(n){return function(){f(this).addClass(n.contentRollClass);};};b=function(n){return function(){f(this).removeClass(n.contentRollClass);};};h=function(n){n.currentURL=n.pendingURL;n.pendingURL=null;n.updateContent(n.nextContentElm);if(n.nextHeight!==n.currentHeight){if(n.nextHeight>n.currentHeight){n.mask.element.height(n.nextHeight);}n.coreElm.animate({height:n.nextHeight},400,function(){n.currentHeight=n.nextHeight;n.nextHeight=null;n.mask.hide();});}else{n.nextHeight=null;n.mask.hide();}};k=function(n){this.id=n;};k.prototype={boxCreate:function(o){var n=this.id;this.index=o.index;this.rootElm=f(o.rootElm);this.coreElm=this.rootElm.find("div.cap-core");this.contentElm=this.rootElm.find("div.cap-text");this.baseURL=o.baseURL.replace("{$id}",n);this.rootFile=this.rootElm.data("cap-rootFile")||o.rootFile;this.rootForceFile=o.rootForceFile||null;this.tplURL=this.rootElm.find("input.capURL").val()||null;this.datasHTML=g.get("util").create("loadhtml."+n,o).bindToUi(this);this.datasIMG=g.get("util").create("loadimage."+n,o).bindToUi(this);this.loadImmediatly=o.loadImmediatly;this.baseHeight=o.baseHeight;this.msgLoading=o.msgLoading;this.msgError=o.msgError;this.l10n=o.l10n;this.success=0;this.enable();if(o.loadImmediatly){this.reveal();}},boxDestroy:function(){this.disable();var n=this.id;g.get("util").destroy("loadhtml."+n).destroy("loadimage."+n);},boxGetName:function(n){var o=this.boxName+"."+this.id;return n?o:o+(this.pageId?"."+this.pageId:"");},disable:function(){if(this.disabled!==true){var n=this.id,o=this.boxGetName(true);this.stopLoading();g.get("util:delegate-click").remove({id:o,root:this.rootElm});this.rootElm.unbind("mouseover");g.get("ui").destroy("mask."+n);g.unsubscribe("reveal>"+o,"requeststart>"+o,"requesterror>"+o,"htmlready>"+o,"preloadready>"+o,"preloaderror>"+o,"show>mask."+n,"hide>mask."+n);this.disabled=true;this.available=false;}},enable:function(){var q=this;if(q.disabled!==false){var o=q.id,p=q.boxGetName(true),n="#"+o+" div.cap-core:";q.msgElm=f('<div class="panel"></div>');q.msgStyles={top:n+"in-middle",left:n+"in-middle"};q.mask=g.get("ui").create("mask."+o,{html:'<div class="mask" style="overflow:hidden;"></div>',insertTarget:q.coreElm,insertStyles:{top:0,left:0,width:n+"padding-box",height:n+"padding-box",opacity:0},insertAnimStyles:{opacity:1},insertAnimDuration:600,removeAnimStyles:{opacity:0},removeAnimDuration:1000});g.get("util:delegate-click").add({id:p,deepness:4,root:q.rootElm,test:function(r){return r.tagName==="A";},handler:function(t,s){var u=f(s).getBoxDatas()||{},r=(s.target||u.target||"").replace("_","");q.boxPublish("clicklink",{element:s,boxDatas:u});if(r==="self"){t.preventDefault();q.startLoading(s.href,u.cache!=="false");}else{if(r==="blank"){t.preventDefault();g.getWin().open(s.href);q.boxPublish("outgoing",{element:s});}else{if(r==="error"){t.preventDefault();q.mask.hide();}}}}});q.rootElm.mouseover(l(q));g.subscribe({name:"reveal>"+p,context:q,handler:function(r){this.offsetTop=this.rootElm.offset().top;this.currentHeight=this.baseHeight;this.startLoading(this.getDefaultURL());}},{name:"requeststart>"+p,context:q,handler:function(r){this.currentlyOK=false;this.mask.element.append(this.msgElm.html(this.msgLoading));this.mask.show();this.msgElm.applyStyles(this.msgStyles);}},{name:"requesterror>"+p,context:q,handler:function(r){this.pendingURL=null;if(r.data.status!=="abort"){d(this);}}},{name:"htmlready>"+p,context:q,handler:function(t){this.mediaPlayerId=null;this.nextContentElm=t.data.element;var r=this.datasIMG.getURLs(this.nextContentElm),u=[],s=r.length;while(s--){if(c.test(r[s])){u[u.length]=r[s].replace(c,a);}}this.datasIMG.batch(r.concat(u));}},{name:"preloadready>"+p,context:q,handler:function(){this.currentlyOK=true;if(this.mask.dom.available){h(this);}}},{name:"preloaderror>"+p,context:q,handler:function(){d(this);}},{name:"show>ui:mask."+o,context:q,handler:function(){if(this.datasIMG.available&&this.currentlyOK){h(this);}}},{name:"hide>ui:mask."+o,context:q,handler:function(){this.available=true;this.mask.element.empty();}});q.disabled=false;q.available=true;}},isDead:function(){return this.success===0&&this.available===true;},reveal:function(){var n=this;if(!n.displayed){n.rootElm.css({display:"block"});n.coreElm.animate({height:n.baseHeight},0,function(){n.displayed=true;n.boxPublish("reveal");});}},updateContent:function(o){if(!this.pendingURL&&o&&o.length){if(this.contentRollClass){this.contentElm.unbind("mouseenter mouseleave");}this.boxPublish("unload");this.contentElm.replaceWith(o);this.contentElm=this.rootElm.find("div.cap-content");var n=this.contentElm[0].className.match(j),p=this.contentElm.getBoxDatas("roll");this.pageId=n?n[1]:null;this.contentRollClass=p||null;if(p){this.contentElm.hover(i(this),b(this));}this.nextHeight=Math.max(this.baseHeight,this.contentElm.height());this.nextContentElm=null;this.success++;this.boxPublish("load",{reset:this.resetting});this.resetting=false;if(this.success===1){this.boxPublish("initcomplete",{status:"success"});}if(this.nextHeight!==this.currentHeight){this.boxPublish("changeheight",{change:this.nextHeight-this.currentHeight});}}},getDefaultURL:function(){return this.baseURL+(this.currentURL?this.rootFile:this.rootForceFile||this.rootFile);},getCurrentFile:function(){return this.currentURL?this.currentURL.match(e)[0]:"";},reset:function(){var n=this.getDefaultURL();if(!this.disabled&&this.currentURL!==n){this.resetting=true;this.startLoading(n);}},startLoading:function(o,n){if(this.available&&typeof o==="string"&&o&&this.currentURL!==o){this.available=false;this.pendingURL=o;this.datasHTML.request({url:o,cache:n!==false});}},stopLoading:function(){if(!this.disabled&&!this.available){this.stopPlaying();this.datasHTML.abort();this.datasIMG.abort();this.mask.remove();this.available=true;this.resetting=false;}},stopPlaying:function(){var r=this.mediaPlayerId;if(r){var o=r.length,n,p,q;while(o--){n=r[o];p=g.get(n);if(p){p.pause();}else{q=g.getDoc().getElementById(n);if(q&&g.isHostMethod(q,"playerPauseVideo")){q.playerPauseVideo();}}}}},registerMediaPlayer:function(n){this.mediaPlayerId=n;},getExportURL:function(p){var n=g.getWin().location,s=g.getWin().encodeURIComponent,r=p||this.tplURL||this.getDefaultURL(),q=s(this.getCurrentFile()),o=(r.indexOf("?")>-1?"&dl=":"?dl=")+this.id+"%3A"+q;return(r.indexOf("http")>-1?"":n.protocol+"//"+n.hostname)+r+o;}};return k;});box.store("lop").addConstructor("capsule-control",function(d,c){var a=/(&|\?)dl=[^&]+/;var b=function(e){this.id=e;};b.prototype={boxCreate:function(h){var g=this;g.rootElm=d(h.rootElm);g.requestTimeout=h.requestTimeout||10000;g.preloadTimeout=h.preloadTimeout||30000;g.loadImmediatly=h.loadImmediatly===true;g.countLoad=0;g.items=[];var f=this.getPagesInUrl(),e=h.baseHeight||440;g.rootElm.find(h.itemsElm).each(function(l,k){var j=(k.getAttribute("data-cap-static")==="true"?"capsule-static.":"capsule.")+k.id;g.items[l]=c.get("lop").create(j,{index:l+1,rootElm:k,baseURL:h.baseURL,rootFile:h.rootFile,rootForceFile:f[k.id],requestTimeout:h.requestTimeout,preloadTimeout:h.preloadTimeout,baseHeight:e,loadImmediatly:l===0&&g.loadImmediatly,l10n:h.l10n,msgLoading:h.msgLoading,msgError:h.msgError});});this.enable();},boxDestroy:function(){this.disable();var f=this.items.length,e=c.get("lop");while(f--){e.destroy("capsule."+this.items[f].id);}},disable:function(){if(this.disabled!==true){c.unsubscribe("initcomplete>lop:capsule","startplaying>lop:capsules-players");var e=this.items.length;while(e--){this.items[e].disable();}this.disabled=true;this.available=false;}},enable:function(){if(this.disabled!==false){c.subscribe({name:"initcomplete>lop:capsule",context:this,handler:function(f){this.countLoad++;if(this.items[this.countLoad]){this.items[this.countLoad].reveal();}}},{name:"startplaying>lop:capsules-players",context:this,handler:function(f){this.stopPlaying(f.data.target);}});var e=this.items.length;while(e--){this.items[e].enable();}this.disabled=false;this.available=true;}},getPagesInUrl:function(){var j=c.getURLParams().dl,e={},k=c.getWin().decodeURIComponent,f,h,g;if(j){f=j.split("%3B");g=f.length;while(g--){h=f[g].split("%3A");e[h[0]]=k(h[1]);}}return e;},getPageExportURL:function(){var g=this.items.length,m=c.getWin(),k=m.encodeURIComponent,j=m.location.href.replace(a,""),f=m.location.search,e="",l,h;while(g--){l=this.items[g];h=k(l.getCurrentFile());if(h!==l.rootFile){e+=(e?"%3B":"")+l.id+"%3A"+h;}}return j+(e?(f?"&dl=":"?dl=")+e:e);},stopLoading:function(){if(this.disabled!==false){var e=this.items.length;while(e--){this.items[e].stopLoading();}}},stopPlaying:function(e){if(this.disabled!==true){var f=this.items.length,g;while(f--){g=this.items[f];if(g.id!==e){g.stopPlaying();}}}}};return b;});box.store("lop").addModule("capsules-players",function(c,b){var a={};return{isPlaying:function(d){return a[d]===true;},play:function(e,g,f,d){a[e]=true;if(!f||f<=0.2){b.publish({type:"startplaying",label:"lop:capsules-players."+e,data:{target:e,video:g,tag:d}});}},pause:function(d){a[d]=false;b.publish({type:"pauseplaying",label:"lop:capsules-players."+d,data:{target:d}});},complete:function(d){a[d]=false;b.publish({type:"complete",label:"lop:capsules-players."+d,data:{target:d}});}};});(function(){var b=/^p(lay|ause)$/,a=function(d){var c=b.test(d.type)?d.type:"complete",e=box.get("lop:capsule."+this.id);if(e){box.get("lop:capsules-players")[c](this.id,this.currentUrl,this.currentTime,this.getCurrentDatas().tag);}};box.subscribe({name:"play>ui:player",handler:a},{name:"pause>ui:player",handler:a},{name:"endmedia>ui:player",handler:a});}());box.store("lop").addConstructor("capsule-remote",function(e,h){var j,b,a,i,n,o,m,c,g,k,f=0;j={
/*!
         * Easing Equations v2.0
         * (c) 2003 Robert Penner, all rights reserved.
         * This work is subject to the terms in http://www.robertpenner.com/easing_terms_of_use.html
         */
sineInOut:function(q,u,p,r){return u/2*(1-Math.cos(Math.PI*p/r))+q;}};b=function(r,u,v){var p=v-u,w=Math.sqrt(p<0?-p:p)*r.fxDurationFactor,s=-1,q=Math.round(w/r.fxInterval),t=[];w=q*r.fxInterval;while(++s<=q){t[s]=(Math.round(j.sineInOut(u,p,w/q*s,w)*1000)/1000);}return t;};n=function(){e(this).addClass("expanded");};o=function(){e(this).removeClass("expanded");};m=function(p){return function(q){q.preventDefault();p.gotoItem(this.getAttribute("data-cap-id"));};};var l=function(q,p){h.getWin().clearTimeout(q._timer);q._timer=h.getWin().setTimeout(function(){q.call(p);},150);};var d=function(){var q=this,s=h.getJWin().scrollTop(),p=q.items,r=p.length,t=s-q.lastScrollOffset,u=(new Date()).getTime(),v;if(t!==0){while(r--){v=p[r];if(s>=v.inViewFrom){if(q.currentItem){q.currentItem.removeClass("on");}q.currentItem=c(q,v.id).addClass("on");q.currentId=v.id;break;}}}q.lastScrollOffset=s;};i=function(p){return function(){l(d,p);};};c=function(r,q){var p=r.items,s=p.length;while(s--){if(p[s].id===q){return r.itemsElm.eq(s);}}};g=function(q,p,s,t,r){return('<li data-cap-id="'+q+'"><a href="#'+q+'" class="label"><span>'+p+'</span></a><div class="expand"><a href="#'+q+'"><img alt="" src="'+s+'img/remote/expand.jpg" class="visual"><span class="content"><span class="wrap1"><span class="wrap2"><strong>'+t+"</strong><em>"+r+"</em></span></span></span></a></div></li>");};a=function(p){f=p.data.change;this.items[p.source.index-1].height+=f;};k=function(p){this.id=p;};k.prototype={boxCreate:function(q){this.rootElm=e(q.rootElm);this.targetElm=this.rootElm.find(q.targetElm).hover(n,o).click(m(this));this.fxInterval=30;this.fxDurationFactor=q.fxDurationFactor||20;this.inViewFactor=q.inViewFactor||0.25;this.baseOffsetTop=q.baseOffsetTop||0;this.lastScrollOffset=0;var p=this.targetElm.data("cap-id");this.items=[{offsetTop:this.baseOffsetTop,height:e("#"+p).outerHeight(),id:p}];h.getJWin().scroll(i(this));h.subscribe("changeheight>lop:capsule",a,this);this.available=true;},addItem:function(t){var s=this.items.length-1,w=t.rootElm.data("cap-name"),u=t.rootElm.data("cap-baseline"),r=t.id,v=e(g(r,t.index,t.baseURL,w,u)).insertBefore(this.targetElm).hover(n,o).click(m(this)),p=t.baseHeight,q;t.offsetTop+=f;f=0;this.items.splice(s,0,{offsetTop:t.offsetTop,height:p,inViewFrom:s===0?0:t.offsetTop-this.items[s-1].height*this.inViewFactor-this.baseOffsetTop,id:r});q=this.items[s+1];q.offsetTop=e("#"+q.id).offset().top;q.inViewFrom=q.offsetTop-p*this.inViewFactor-this.baseOffsetTop;this.itemsElm=this.rootElm.find("li");if(s===0){this.currentItem=v.addClass("on");this.currentId=r;h.getWin().scrollTo(0,0);}},gotoItem:function(r){var q=this;if(q.available&&h.getDoc().getElementById(r)){q.available=false;var t=r==="footer"?q.items[q.items.length-1]:h.get("lop:capsule."+r),p=t.offsetTop-q.baseOffsetTop,s=h.getJWin().scrollTop();q.fxValues=b(q,s,p);q.fxFrame=0;q.fxFrames=q.fxValues.length-1;if(q.currentItem){q.currentItem.removeClass("on");}q.currentItem=c(q,r).addClass("on");q.currentId=r;q.fxTimer=h.getWin().setInterval(function(){q.fxFrame++;if(q.fxFrame<=q.fxFrames){h.getWin().scrollTo(0,q.fxValues[q.fxFrame]);}else{q.stop();}},q.fxInterval);}},stop:function(){if(this.available===false){h.getWin().clearInterval(this.fxTimer);this.fxTimer=null;this.available=true;this.boxPublish("scrolled");}}};return k;});


/*global box: false, LOP: false, _gaq: false*/
(function() {
    var reId = /\d+_/,
        reExtractFile = /[a-zA-Z0-9._-]+$/,
        sBaseUrl = box.getWin().location.protocol + '//' + box.getWin().location.hostname,
        getCapId = function(sId) {
            return sId.replace(reId, '');
        },
        getCategory = function() {
            return $('#catCapBase').val();
        },
        getVideoFile = function(sUrl) {
            return sUrl ? sUrl.match(reExtractFile)[0] : '';
        };
    
    if(!this.console) {
        this.console = {
            log: function() {}
        };
    }
    
    box.subscribe(
        {
            name: 'load>lop:capsule',
            handler: function() {
                var sCapName = getCapId(this.id),
                    sPage = this.pageId,
                    sCatBase, sCatFull;
                if(sPage && sPage !== 'home') {
                    sCatBase = getCategory();
                    if(sCatBase) {
                        sCatFull = sCatBase + '_' + sCapName;
                        LOP.execStatCM('type=tagPageView;category=' + sCatFull + ';tag=' + sCapName + '_' + sPage);
                        _gaq.push(['lorealparis._trackPageview', '/' + sCatBase + '/' + sCapName + '/' + sPage+'-en']);
						_gaq.push(['lorealparis_coremetrics._trackPageview', '/' + sCatBase + '/' + sCapName + '/' + sPage]);
                        //console.log('CM', 'type=tagPageView;category=' + sCatFull + ';tag=' + sCapName + '_' + sPage);
                        //console.log('GA', ['_trackPageview', '/' + sCatBase + '/' + sCapName + '/' + sPage]);
                    }
                }
            }
        }, {
            name: 'scrolled>lop:capsule-remote',
            handler: function() {
                var sCapName = getCapId(this.currentId),
                    sCatBase = getCategory();
                if(sCatBase && sCapName !== 'footer') {
                    LOP.execStatCM('type=tagElementView;category=' + sCatBase + '_click;tag=' + sCapName);
                    trackBscEvent(sCatBase, 'click', sCapName);
                    //console.log('CM', 'type=tagElementView;category=' + sCatBase + '_click;tag=' + sCapName);
                    //console.log('GA', ['_trackEvent', sCatBase, 'click', sCapName]);
                }
            }
        }, {
            name: 'clicklink>lop:capsule',
            handler: function(oEvt) {
                var sCapName = getCapId(this.id),
                    sCatBase = getCategory(),
                    sHref = oEvt.data.element.getAttribute('href', 2),
                    sType = oEvt.data.element.getAttribute('data-stats'),
                    oBox = oEvt.data.boxDatas;
                if(sCatBase) {
                    if(sHref === '#')  {
                        if(sType) {
                            trackBscEvent(sCatBase, 'link', sCapName + '_' + sType);
                            //console.log('GA', ['_trackEvent', sCatBase, 'link', sCapName + '_' + sType]);
                        }
                    } else {
                        if(sType && sHref.indexOf('http:') === -1) {
                            sHref = sType;
                        }
                        if(oBox.video) {
                            sHref += '/' + oBox.video;
                        }
                        trackBscEvent(sCatBase, 'link', sCapName + '_' + sHref);
                        //console.log('GA', ['_trackEvent', sCatBase, 'link', sCapName + '_' + sHref]);
                    }
                }
            }
        }, {
            name: 'outgoing>lop:capsule',
            handler: function(oEvt) {
                var sCapName = getCapId(this.id),
                    sCatBase = getCategory(),
                    sType = oEvt.data.element.getAttribute('data-stats'),
                    sFullName;
                if(sCatBase && sType) {
                    sFullName = sCapName + '_' + sType;
                    if(sFullName.length > 50) {
                        sFullName = sFullName.substring(0, 50);
                    }
                    LOP.execStatCM('type=tagElementView;category=' + sCatBase + '_outgoing_link;tag=' + sFullName);
                    trackBscEvent(sCatBase, 'outgoing_link', sFullName);
                    //console.log('CM', 'type=tagElementView;category=' + sCatBase + '_outgoing_link;tag=' + sFullName);
                    //console.log('GA', ['_trackEvent', sCatBase, 'outgoing_link', sFullName]);
                }
            }
        }, {
            name: 'startplaying>lop:capsules-players',
            handler: function(oEvt) {
                var sId = oEvt.data.target,
                    sCatBase = getCategory(),
                    sUrl = getVideoFile(oEvt.data.video),
                    sTag = oEvt.data.tag,
                    uVideo = box.get('stats:' + sId),
                    sVideo;
                if(sCatBase && (sTag || uVideo)) {
                    sVideo = sTag || uVideo[sUrl] || uVideo;
                    if(sVideo.length > 50) {
                        sVideo = sVideo.substring(0, 50);
                    }
                    LOP.execStatCM('type=tagElementView;category=' + sCatBase + '_video;tag=' + sVideo);
                    trackBscEvent(sCatBase, 'video', sVideo);
                    //console.log('CM', 'type=tagElementView;category=' + sCatBase + '_video;tag=' + sVideo);
                    //console.log('GA', ['_trackEvent', sCatBase, 'video', sVideo]);
                }
            }
        }
    );
}());
