gmSimpleDownload=Class.create({urls:{ajax:"/browser/ping",gmasync:"/gmasync/download",chrome:"/extension/GlobalMojo-3.1.0-1.crx",ie:"/extension/GlobalMojo-3.1.1-1.exe",ff:"/extension/GlobalMojo-3.1.1-1.xpi",badsafari:"/extension/GlobalMojo-3.1.3-1.safariextz"},downloadInstructionWrapperId:"gmSimpleDownload",downloadInstructionFooter:"gmSimpleDownloadFooter",downloadInstructionTrustedId:"gmSimpleDownload_trusted",currentBrowser:false,instructionAnimationType:{MOVE:"move",SLIDE:"slide"},INSTANCE_NAME:"gmSimpleDownload",browser_name_map:{ie:"microsoftie",ff:"firefoxaddon",chrome:"googlechrome",safari:"safari"},partner:false,mvtest_page:false,product_build_id:window.gm_product_build_id,initialize:function(){if(this.browserType.Gecko&&this.urls.ff){this.currentBrowser="ff"}else{if(this.browserType.Chrome&&this.urls.chrome){this.currentBrowser="chrome"}else{if(this.browserType.IE&&this.urls.ie){this.currentBrowser="ie"}else{if(this.browserType.Safari&&this.urls.safari){$("gmSimpleDownloadHeader").addClassName("classHeaderRadius");$("gmSimpleDownloadFooter").removeClassName("borderbottomOthers");this.currentBrowser="safari"}else{this.currentBrowser=false}}}}$$("a.addon_download").invoke("observe","click",this.processDownload.bindAsEventListener(this));$("gmSimpleDownloadClose").observe("click",this.hideOverlay.bindAsEventListener(this));$("notifyMePluginEmail").observe("click",this.notifyViaEmail.bindAsEventListener(this));this.downloadInstructionsWrap=$(this.downloadInstructionWrapperId);this.downloadInstructionTrusted=$(this.downloadInstructionTrustedId);this.mvtest_page=this.getCookie("gm_mvtest_page");this.product_build_id=window.gm_product_build_id;this.downloadParams={}},downloadFile:function(a){var b;b=document.getElementById("hiddenDownloader");if(b===null){b=document.createElement("iframe");b.id="hiddenDownloader";b.style.visibility="hidden";document.body.appendChild(b)}b.src=a},processDownload:function(){if(this.currentBrowser){this.downloadFile(this.urls[this.currentBrowser]);this.pingServer()}this.showOverlay()},showOverlay:function(){Effect.Appear("down_overlay",{duration:0.5,from:0,to:0.7});switch(this.currentBrowser){case"ff":$("gmSimpleDownloadFF").show();document.getElementById("gmSimpleDownloadClose").style.marginLeft="490px";break;case"ie":$("gmSimpleDownloadIE").show();document.getElementById("gmSimpleDownloadClose").style.marginLeft="-300px";break;case"chrome":$("gmSimpleDownloadChrome").show();document.getElementById("gmSimpleDownloadClose").style.marginLeft="-490px";document.getElementById("gmSimpleDownload").style.marginLeft="50%";break;case"safari":$("gmSimpleDownloadSafari").show();document.getElementById("gmSimpleDownloadClose").style.marginLeft="-490px";break;default:$("gmSimpleDownloadUnsupported").show()}$("gmSimpleDownload").addClassName("gmSimpleDownload"+this.currentBrowser);this.setInstructionPosition()},setInstructionPosition:function(){var a=0;var e=0;var d={};var b={};if(this.downloadInstructionsWrap!==null){var c=new Element.Layout(this.downloadInstructionsWrap)}else{return}switch(this.currentBrowser){case"ff":$("gmSimpleDownloadFF").show();a=c.get("height");d={right:"0px",top:"-"+a+"px",position:"fixed"};break;case"ie":$("gmSimpleDownloadIE").show();a=-(c.get("height"));d={left:"-100px",top:"-"+a+"px",position:"fixed"};break;case"chrome":$("gmSimpleDownloadChrome").show();a=-(c.get("height"));d={right:"0px",top:"-"+a+"px",position:"fixed"};if(this.downloadInstructionTrusted!==null){this.downloadInstructionTrusted.setStyle({height:150+"px"})}break;case"safari":$("gmSimpleDownloadSafari").show();break;default:$("gmSimpleDownloadUnsupported").show()}this.downloadInstructionsWrap.setStyle(d);this.downloadInstructionsWrap.show();new Effect.Move(this.downloadInstructionsWrap,{y:25,x:e,duration:1})},displayInstructions:function(a){var a=Object.extend({animationStyle:"MOVE"},a||{})},hideOverlay:function(){$("down_overlay").hide();$("gmSimpleDownload").hide()},pingServer:function(){this._setPageCookie();var a={formaction:"instant-download-guest",downloadtype:this.browser_name_map[this.currentBrowser],productbuildid:this.product_build_id};Object.extend(a,this.downloadParams);new Ajax.Request(this.urls.gmasync,{method:"post",evalJSON:"force",parameters:{typerequest:"submitdownload",pars:Object.toJSON(a)},onSuccess:function(e){var c=e.responseJSON;if(c.accessext!=="undefined"){var d=new Date();d.setTime(d.getTime()+(3600*24*365*5));var b="; expires="+d.toGMTString();document.cookie="ACCESSEXT="+c.accessext+b+"; path=/; domain=.globalmojo.com"}},onFailure:function(){},onComplete:this._pingServerComplete.bind(this)})},_pingServerComplete:function(){this._setPageCookie();new Ajax.Request(this.urls.ajax,{method:"get",parameters:{a:"download",eav:this.currentBrowser,gm_refcode:this.getCookie("gm_refcode"),accessext:this.getCookie("ACCESSEXT")},onComplete:this._resetPageCookie.bind(this)})},_setPageCookie:function(){var a=this.mvtest_page;if(a!="false"&&typeof a!=="undefined"&&this.partner!=false){a+="::"+this.partner}this.setCookie("gm_mvtest_page",a)},_resetPageCookie:function(){this.setCookie("gm_mvtest_page",this.mvtest_page)},notifyViaEmail:function(){if(!$("notifyMePluginEmail").value.trim()){return false}src="wait-for+"+this.currentBrowser;src+="-"+location.href;new Ajax.Request("/gmasync/saveMarketingEmail",{method:"post",parameters:{email:$("notifyMePluginEmail").value,source:src},onSuccess:function(a){$("gmSimpleDownloadUnsupported").update("<p>Thank you!  We will notify you as soon as the app is ready.</p>")},onFailure:function(a){$("gmSimpleDownloadUnsupported").update("<p>Whoops! Something went wrong. Please try again.</p>")}});return false},getCookie:function(a){var b=document.cookie.match(a+"=(.*?)(;|$)");if(b){return(unescape(b[1]))}else{return false}},setCookie:function(c,e,d){var b=new Date();b.setTime(b.getTime()+(3600*d));var a="; expires="+b.toGMTString();document.cookie=c+"="+e+a+"; path=/; domain=.globalmojo.com"},createUUID:function(){var a=function(){return(((1+Math.random())*65536)|0).toString(16).substring(1)};return(a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a())},setDownloadParams:function(a){Object.extend(this.downloadParams,a)},browserType:{IE:!!(window.attachEvent&&!window.opera),Opera:!!window.opera,WebKit:navigator.userAgent.indexOf("AppleWebKit/")>-1,Gecko:navigator.userAgent.indexOf("Gecko")>-1&&navigator.userAgent.indexOf("KHTML")==-1,MobileSafari:!!navigator.userAgent.match(/Apple.*Mobile.*Safari/),Chrome:!!navigator.userAgent.match("Chrome"),Safari:(navigator.userAgent.indexOf("Safari/")>-1&&!navigator.userAgent.match(/Apple.*Mobile.*Safari/))},setBrowser:function(a){if(typeof a==="string"){this.currentBrowser=a}},setPartner:function(a){if(typeof a==="string"){this.partner=a}}});document.observe("dom:loaded",function(){GM.instances.gmSimpleDownload=new gmSimpleDownload()});function gmStartDownload(b,a){if(typeof gmSimpleDownloadInst==="undefined"){gmSimpleDownloadInst=new gmSimpleDownload();gmSimpleDownloadInst.setBrowser(a);gmSimpleDownloadInst.setPartner(b);gmSimpleDownloadInst.processDownload()}};
