/*

    Copyright © 2000-2010 Apple Inc. All Rights Reserved.
    
*/

var lpMTagConfig={lpTagLoaded:false,lpTagSrv:"storechat.apple.com",pageStartTime:(new Date()).getTime(),deploymentID:"1"};lpMTagConfig.deploymentConfigPath=lpMTagConfig.lpTagSrv+"/visitor/addons/deploy.asp";lpMTagConfig.lpLoadScripts=function(){lpAddMonitorTag(lpMTagConfig.lpProtocol+"://"+lpMTagConfig.deploymentConfigPath+"?site="+lpMTagConfig.lpNumber+"&d_id="+lpMTagConfig.deploymentID)};function lpAddMonitorTag(B){if(!lpMTagConfig.lpTagLoaded){if(typeof (B)=="undefined"||typeof (B)=="object"){if(lpMTagConfig.lpMTagSrc){B=lpMTagConfig.lpMTagSrc}else{if(lpMTagConfig.lpTagSrv){B=lpMTagConfig.lpProtocol+"://"+lpMTagConfig.lpTagSrv+"/hcp/html/mTag.js"}else{B="/hcp/html/mTag.js"}}}if(B.indexOf("http")!==0){B=lpMTagConfig.lpProtocol+"://"+lpMTagConfig.lpServer+B+"?site="+lpMTagConfig.lpNumber}else{if(B.indexOf("site=")<0){if(B.indexOf("?")<0){B=B+"?"}else{B=B+"&"}B=B+"site="+lpMTagConfig.lpNumber}}var A=document.createElement("script");A.setAttribute("type","text/javascript");A.setAttribute("charset","iso-8859-1");A.setAttribute("src",B);document.getElementsByTagName("head").item(0).appendChild(A)}}lpMTagConfig.calculateSentPageTime=function(){var A=(new Date()).getTime()-lpMTagConfig.pageStartTime;lpAddVars("page","pageLoadTime",Math.round(A/1000)+" sec")};if(typeof (lpMTagConfig.pageVar)=="undefined"){lpMTagConfig.pageVar=[]}if(typeof (lpMTagConfig.sessionVar)=="undefined"){lpMTagConfig.sessionVar=[]}if(typeof (lpMTagConfig.visitorVar)=="undefined"){lpMTagConfig.visitorVar=[]}if(typeof (lpMTagConfig.onLoadCode)=="undefined"){lpMTagConfig.onLoadCode=[]}if(typeof (lpMTagConfig.dynButton)=="undefined"){lpMTagConfig.dynButton=[]}if(typeof (lpMTagConfig.ifVisitorCode)=="undefined"){lpMTagConfig.ifVisitorCode=[]}function lpAddVars(B,A,C){if(A.indexOf("OrderTotal")!==-1||A.indexOf("OrderNumber")!==-1){if(C===""||C===0){return }else{lpMTagConfig.sendCookies=false}}C=lpTrimSpaces(C.toString());if(A.length>50){A=A.substr(0,50)}if(C.length>50){C=C.substr(0,50)}switch(B){case"page":lpMTagConfig.pageVar[lpMTagConfig.pageVar.length]=escape(A)+"="+escape(C);break;case"session":lpMTagConfig.sessionVar[lpMTagConfig.sessionVar.length]=escape(A)+"="+escape(C);break;case"visitor":lpMTagConfig.visitorVar[lpMTagConfig.visitorVar.length]=escape(A)+"="+escape(C);break;default:break}}function onloadEMT(){var B=document.cookie,A=window.lpMTag;if(A.lpBrowser=="IE"&&B.length>1000){lpMTagConfig.sendCookies=false}}function lpTrimSpaces(A){return A.replace(/^\s+|\s+$/g,"")}function lpSendData(C,B,D){var A=window.lpMTag;if(typeof (A)!="undefined"&&typeof (A.lpSendData)!="undefined"){A.lpSendData(C.toUpperCase()+"VAR!"+B+"="+D,true)}}try{if(typeof (lpCountryCode)=="undefined"){lpCountryCode="us"}if(typeof (lpAddVars)!="undefined"){lpAddVars("page","lpCountryCode",lpCountryCode)}if(typeof (lpSegment)=="undefined"){lpSegment="consumer"}if(typeof (lpAddVars)!="undefined"){lpAddVars("page","lpSegment",lpSegment)}if(typeof (lpUnit)=="undefined"){lpUnit="sales"}if(typeof (lpAddVars)!="undefined"){lpAddVars("page","lpUnit",lpUnit)}if(typeof (lpLanguage)=="undefined"){lpLanguage="english"}if(typeof (lpAddVars)!="undefined"){lpAddVars("session","lpLanguage",lpLanguage)}lpMTagConfig.defaultInvite="chat-"+lpCountryCode+"-"+lpSegment+"-"+lpUnit+"-"+lpLanguage}catch(e){}lpMTagConfig.onLoadCode[lpMTagConfig.onLoadCode.length]=onloadEMT;lpMTagConfig.onLoadCode[lpMTagConfig.onLoadCode.length]=function(){if(typeof (lpMTagConfig.dynButton)!="undefined"){for(var A=0;A<lpMTagConfig.dynButton.length;A++){if(typeof (lpMTagConfig.dynButton[A].pid)!=="undefined"&&document.getElementById(lpMTagConfig.dynButton[A].pid)===null){lpMTagConfig.dynButton.splice(A,1);A--}}}};lpMTagConfig.onLoadAll=function(){lpMTagConfig.calculateSentPageTime();lpMTagConfig.lpLoadScripts()};lpMTagConfig.dynButton[lpMTagConfig.dynButton.length]={name:"chat-"+lpCountryCode+"-"+lpSegment+"-"+lpUnit+"-"+lpLanguage+"-1",pid:"lpButton1",afterStartPage:true};lpMTagConfig.dynButton[lpMTagConfig.dynButton.length]={name:"chat-"+lpCountryCode+"-"+lpSegment+"-"+lpUnit+"-"+lpLanguage+"-2",pid:"lpButton2",afterStartPage:true};lpMTagConfig.dynButton[lpMTagConfig.dynButton.length]={name:"chat-"+lpCountryCode+"-"+lpSegment+"-"+lpUnit+"-"+lpLanguage+"-3",pid:"lpButton3",afterStartPage:true};lpMTagConfig.dynButton[lpMTagConfig.dynButton.length]={name:"chat-"+lpCountryCode+"-"+lpSegment+"-"+lpUnit+"-"+lpLanguage+"-4",pid:"lpButton4",afterStartPage:true};lpMTagConfig.dynButton[lpMTagConfig.dynButton.length]={name:"chat-"+lpCountryCode+"-"+lpSegment+"-"+lpUnit+"-"+lpLanguage+"-5",pid:"lpButton5",afterStartPage:true};Event.onLoad(function(){Package("apple.chat");(function(N,Q,R,X,S,a,I,K,P,J){if(!N||!Q||!R||!X||!S||!a){throw new Error("Chat Module does not have required dependencies available")}var W=".chat-button",F=".chat",D="chat-standby",G="chat-online",U=/online/,B="lpButton",M=0,O=R.locateAncestor,L=R.addClassName,C=R.hasClassName,H=R.query,T=a.observe,V,Z=S.create({constructor:function(d){this.maxButtonCount=d&&d.dynButton&&d.dynButton.length;V=d;var f=this.buttons=R.queryAll(F);for(var c=0,b=f.length;c<b;c++){f[c]=E.create(f[c],this)}},maxButtonCount:0,assignBtnID:function(f){var g=f&&f.el||null,h=this.buttons;if(g){for(var d=0,b=h.length,c;d<b;d++){if(h[d]===f.el||h[d].el===f.el){c=++d;break}}}return c&&(c<=this.maxButtonCount)?B+c:false},canReveal:function(){var d=this.buttons,b=true,c=d.length;while(c--){if(!d[c].ready||!d[c].online){b=false;break}}return b},reveal:function(){if(!this.canReveal()){return false}for(var c=0,b=this.buttons.length;c<b;c++){this.buttons[c].online();this.buttons[c].accessibilityFix()}return true}}),E=S.create({constructor:function(c,b){this.el=c;this.manager=b;this.buttonEl=H(c,W);this._setID();if(this.shouldResizeAncestor()){this._setButtonBounds()}this.update();if(!this.ready){T(this.buttonEl,"DOMNodeInserted",this);this.pollID=K.setInterval(this.update.bind(this),250)}},el:null,manager:null,pollID:null,ready:false,online:false,handleEvent:function(b){switch(b.type){case"DOMNodeInserted":a.stopObserving(this.buttonEl,"DOMNodeInserted",this);this.update();break;case"click":this._trackClick();break;default:break}},standby:function(){if(this._hasButton()){L(this.el,D)}},reveal:function(d,c){if(!this.ready){return }var b=d||L;c&&c();this.online=function(){b(this.el,G,{only:["opacity"],curve:Q.easing.easeInOut(500),callback:this.track.bind(this)})};this.accessibilityFix=function(){var k=this.buttonEl,j=k.parentNode,h=H(k,"a"),i=H(j,"span"),l=h.innerHTML,f=l;R.setInnerHTML(h,f);if(R.hasClassName(j,"chat-resize")){R.setStyle(j,"overflow","visible")}var g=h.getAttribute("onclick");g=g+"return false;";h.setAttribute("onclick",g);h.setAttribute("href","#")};if(this.manager){this.manager.reveal()}else{this.online()}},update:function(){var b=U.test(this.buttonEl.innerHTML),c=this;if(!this._hasButton()||!b){return false}if(!this.ready&&this.shouldResizeAncestor()){this._animateButtonBounds(function(){c._setButtonBounds({width:"auto",height:"auto"});c._markReady();c.update()})}else{this._markReady()}if(this.pollID){K.clearInterval(this.pollID)}this.reveal(X.addClassName,this.standby.bind(this));return true},track:function(){var c=this.buttonEl,b=H(c,"a");if(b&&c.id&&I){T(this.buttonEl,"click",this)}},shouldResizeAncestor:function(){return C(this.el,"chat-resize")},_setButtonBounds:function(c){var b=this.el,d=c||R.getDimensions(b);this._bounds=d;R.setStyles(b,{width:d.width,height:d.height,overflow:"hidden"})},_animateButtonBounds:function(c){var b=this.el;b.style.cssText=" ";(function(){this.standby();var d=R.getDimensions(b);this._setButtonBounds(this._bounds);X.setStyles(b,{width:d.width,height:d.height},{duration:250,callback:c})}).bindAndDelay(this,0)},_setID:function(){var b=this.manager&&this.manager.assignBtnID(this);if(b){this.buttonEl.id=b}},_hasButton:function(){return this.buttonEl.firstChild&&this.buttonEl.firstChild.nodeType===1},_markReady:function(){this.ready=true},_trackClick:function(){var b=this.buttonEl;I.fireMicroEvent({feature:"chat",action:"Selected: "+b.id});if(V.doEVar21Capture){I.fireMicroEvent({eVar:"eVar21",feature:"chat",action:"Selected: "+b.id})}}});E.create=function(c,b){return new E(c,b)};Z.create=function(b,c){if(!b){return false}return new Z(b,c)};function Y(d){var c=K.lpAddVars||null;if(!c||!d){return false}for(var g in d){switch(g){case"page":case"session":case"visitor":for(var f=0,h=d[g],b=h.length;f<b;f++){c(g,h[f].name,h[f].value)}break;default:V[g]=d[g];break}}V.onLoadAll&&V.onLoadAll();return true}N._ChatButton=E;N.create=function(b){return Z.create(b||K.lpMTagConfig)};N.Chat=N.create;N.applyConfig=Y})(apple.chat,coherent,Element,coherent.Animator,Class,Event,apple.metrics,window,document);var A=new apple.chat.Chat();apple.chat.applyConfig(window.chatConfig.chat)});
