/*
 *	bp-install-lib.js - A little javascript library which makes it easy
 *				 to integrate in-page browserplus installation.
 *
 *	Usage:
 *
 *	  installer = BPInstaller({
 *		config: "params"
 *	  });
 *
 *	  installer.start(callback);
 *
 *	(c) Yahoo! Inc 2010 All rights reserved
 */
BPInstaller=typeof BPInstaller!="undefined"&&BPInstaller?BPInstaller:function(G){var Q="bp75717a74cec54ae480567a4a7b07b60d";var S="allocated";var J=false;var K=false;var R=BrowserPlus;var L=null;var C=null;var A=null;var M=[];var D={start:[false,false,U],bpCheck:[true,true,H],javaCheck:[true,true,V],startJavaInstall:[true,true,W],running:[true,false,null],startFallbackInstall:[true,true,I],waitForUserCompletion:[true,false,E],complete:[true,false,T]};var O=function(Y){if(G&&G.debug){G.debug(Y)}};var X=function(Z,c,Y){if(G&&G.eventHandler){var b={type:Z,pausable:c,pause:c?function(){K=true}:null};if(Y===null){Y={}}for(k in Y){if(Y.hasOwnProperty(k)){b[k]=Y[k]}}G.eventHandler(b,N)}};function B(Y,Z){if(Y===null){Y="bp.installationError"}if(Z===null){Z=""}F("complete",{success:false,error:Y,verboseError:Z})}var F=function(b,Y){O("Attempt to transition from '"+S+"' to '"+b+"'");if(!D[b]){throw"attempt to transition to non-existent state: "+b}S=b;var Z=D[S];if(Z[0]){X(b,Z[1],Y)}if(!K&&!J&&typeof Z[2]==="function"){Z[2](Y)}};function P(g,d,h,Z,c){var i='<applet codebase="'+G.pathToJar+'" code="'+Z+'" archive="'+h+'" id="'+d+'" width="0" height="0" name="Yahoo! BrowserPlus Installer" mayscript="true">';if(!c.codebase_lookup){c.codebase_lookup=false}for(var b in c){if(c.hasOwnProperty(b)){i+='<param name="'+b+'" value="'+c[b]+'"></param>'}}i+="</applet>";var Y=document.createElement("div");Y.id=g;Y.style.visibility="hidden";try{Y.style.borderStyle="hidden"}catch(f){}Y.style.width=0;Y.style.height=0;Y.style.border=0;Y.style.position="absolute";Y.style.top=0;Y.style.left=0;Y.innerHTML=i;return Y}function V(){O("building java check DOM node");var Y=Q+"_check_id";var Z=Q+"_check_applet";var b=P(Y,Z,G.checkJarName,"com.yahoo.browserplus.installer.javatest.class",{});O("appending java check DOM node to DOM");document.body.appendChild(b);O("async break to allow for applet readiness");setTimeout(function(){try{A=document.getElementById(Z).getJavaVersion()}catch(c){}try{document.body.removeChild(document.getElementById(Y))}catch(c){try{O("couldn't remove applet tag: "+c)}catch(c){}}if(A!==null){F("startJavaInstall")}else{F("startFallbackInstall")}},0)}function W(){O("building java check DOM node");var Z=Q+"_install_div";var c=Q+"_install_applet";var e=P(Z,c,G.installJarName,"com.yahoo.browserplus.installer.bplusloader.class",{installerBaseURL:G.installURL});O("appending java check DOM node to DOM");function b(){try{document.body.removeChild(document.getElementById(Z))}catch(f){try{O("couldn't remove applet tag: "+f)}catch(f){}}}document.body.appendChild(e);O("async break to allow for applet readiness");var d=-1;var Y=setInterval(function(){try{var g=document.getElementById(c);if(R.clientSystemInfo().browser!=="Safari"||g.hasOwnProperty("isActive")){var f=String(g.status().status);O("applet status: "+f);if(f==="starting"){}if(f==="error"){clearInterval(Y);O("java installer encountered an error");b();B("bp.installerJavaError","java installer encountered an error")}else{if(f==="complete"){clearInterval(Y);b();if(R.clientSystemInfo().browser==="Firefox"){try{navigator.plugins.refresh(false)}catch(i){}}setTimeout(function(){R.init(C,function(j){F("complete",j)})},0)}else{if(f==="running"){var h=g.status().percent;if(d!=h){d=h;F("running",{percent:g.status().percent,localPercent:g.status().localPercent,phase:g.status().phase})}}else{O("UNEXPECTED STATUS: "+f)}}}}}catch(i){clearInterval(Y);b();O("that was exceptional: "+i.name+": "+i.message);B("bp.installerJavascriptError",i.name+": "+i.message)}},250)}function I(){var Z=BrowserPlus.clientSystemInfo();var Y="";if(Z.os==="Mac"){Y=G.installURL+"osx/"}else{Y=G.installURL+"win32/"}var c=Q+"_download_iframe";var b=document.createElement("iframe");b.src=Y;b.style.display="none";b.id=c;document.body.appendChild(b);M.push(function(){try{document.body.removeChild(document.getElementById(c))}catch(d){try{O("couldn't remove download iframe: "+d)}catch(d){}}});F("waitForUserCompletion")}function E(){setTimeout(function(){try{navigator.plugins.refresh(false)}catch(Y){}R.init(C,function(Z){if(Z.success||Z.error!=="bp.notInstalled"){F("complete",Z)}else{E()}})},700)}function U(){O("validating inclusion of browserplus.js");if(typeof BrowserPlus=="undefined"||!BrowserPlus){throw"bp-install-lib.js requires browserplus.js to have been included"}O("validated!");O("validating required arguments");var Y=["pathToJar","installJarName","checkJarName","installURL"];for(a in Y){if(Y.hasOwnProperty(a)){if(!G||!G[Y[a]]){throw"BPInstaller missing required '"+Y[a]+"' config parameter"}}}O("validated!")}function T(Y){J=true;L(Y);while(M.length){try{var Z=M.pop();Z()}catch(b){try{O("couldn't run cleanup function: "+b)}catch(b){}}}}function H(){R.init(C,function(Y){if(Y.success){F("complete",Y)}else{if(Y.error==="bp.notInstalled"){O("BrowserPlus not installed, checking for presence of java");F("javaCheck")}else{O("error returned from init, aborting installation: "+Y.error);F("complete",Y)}}})}F("start");var N={start:function(Y,Z){if(Z==null){Z=Y;Y={}}L=Z;C=Y;F("bpCheck")},cancel:function(){J=true},resume:function(){O("client invokes resume when in the '"+S+"' state");if(K){K=false;if(D[S]&&D[S][2]){O("resuming from '"+S+"'");D[S][2]()}else{O("no work to be done to continue from this state")}}}};return N};BPInstallerUI=typeof BPInstallerUI!="undefined"&&BPInstallerUI?BPInstallerUI:function(){var E={id:"ybp_wi",ahref:'a target="blank" style="color:{linkcolor}" href',title:"Yahoo! BrowserPlus",java_title:"Installing Yahoo! BrowserPlus...",fallback_title:"Installing Yahoo! BrowserPlus...",done_title:"Setup Complete",autoupdate_link:"http://browserplus.org/autoupdate",eula_link:"http://info.yahoo.com/legal/us/yahoo/browserplus/",bd_text:"To use all the features of this website, you need the latest version of the Yahoo! BrowserPlus plug-in.<br><br>Installing BrowserPlus takes less than a minute, and you won't even need to restart your browser.<br><br>",bd_eula:'I agree to the <{ahref}="{eula_link}">end user license agreement</a> and <{ahref}="{autoupdate_link}">automatic feature updates</a>.',bd_continue:"Continue",bd_notnow:"Not Now",bd_eulanotchecked:"In order to continue, you need to accept the end user license agreement.",fallback_head:"Installing is Easy!",fallback_text_win:"During installation, click Run or Allow if prompted by dialog boxes.",fallback_text_mac:"To install Yahoo! BrowserPlus, double-click the setup file in your Downloads folder.",fallback_text:"",done_head:"You have successfully installed Yahoo BrowserPlus.",done_text:"Yahoo! BrowserPlus updates will automatically be downloaded to provide you with the latest features and security improvements.",done_button:"Close",icon:"http://browserplus.org/i/bp-install-logo.png",icon_w:"75",icon_h:"75",font:"arial, sans-serif",fontsize:"12px",fontcolor:"#333",linkcolor:"#00c",titlebg:"#0081c2",titlebg1:"#6ad",titlebg2:"#35a",titlefg:"white",dialogbg:"#f7fcfe",s_overlay:"background:#000; opacity: 0.33; filter:alpha(opacity=33); position: fixed; top:0; left:0; height:100%; width:100%; z-index:500;",s_dialog:"text-align:left;background:{dialogbg}; color:{fontcolor}; position:fixed; top:100px; left:200px; width: 500px; border:2px solid {titlebg}; border-top:1px solid {titlebg1};font:{fontsize} {font}; z-index:501;line-height:1.3em;",s_image:"width:{icon_w}px;height:{icon_h}px; background: transparent url({icon}) no-repeat 0 0; margin:0 auto; padding:0 5px;",s_titlebar:"text-align:left;background:{titlebg}; color:{titlefg}; padding: 4px 5px; font: bold 108% {font};",s_bd:"padding:10px 10px 5px 10px; text-align:left; border-top:1px solid {titlebg2};",s_dialog_head:"font:bold 108% {font};color:{fontcolor};margin-bottom:1em;",s_buttons:"border-top: 1px solid #e7ecee; padding-top:5px;",s_eula_not:"color:green;",s_progress_outer:"text-align:center;",s_progress:"position:relative; border:1px solid #69c; width:300px; height:18px; margin:10px auto;",s_progress_bar:"position:absolute; top:0px; left:0px; background:#cdf; width:0; height:18px;",s_progress_text:"position:absolute; top:0px; left:0px; text-align:center; width:100%; font:bold 14px/18px {font}; z-index:511;",s_input:"padding:2px 6px 3px; margin:2px 5px;font-size: 93%; font-family:'lucida grande',arial,sans-serif;",s_td1:"padding-right:10px;",s_td:"padding:0; border:0px;",noop:""},X,Z,C=false,K,W='<table border=0 width="100%" height="auto"><tbody><tr><td style="{s_td}" valign="top"><div style="{s_image}"></div></td><td style="{s_td} {s_td1}" valign="top"><h2 style="{s_dialog_head}">{fallback_head}</h2>{fallback_text}<br></td></tr></tbody></table>',Q='<div style="{s_progress_outer}"><div><div style="{s_image}"></div></div><div id="{id}_progress" style="{s_progress}"><div id="{id}_progress_bar" style="{s_progress_bar}"></div><div id="{id}_progress_text" style="{s_progress_text}">0%</div></div></div>',S='<table border=0 width="100%" height="auto"><tbody><tr><td style="{s_td}" valign="top"><div style="{s_image}"></div></td><td style="{s_td}" valign="top"><h2 style="{s_dialog_head}">{done_head}</h2>{done_text}<br><br></td></tr></tbody><tfoot><tr><td align=right colspan=2 style="{s_td} {s_buttons}"><button id="{id}_bt3" style="{s_input}">{done_button}</button></td></tr></tfoot></table>',P='<div id="{id}_dialog" style="{s_dialog}"><div id="{id}_title" style="{s_titlebar}">{title}</div><div id="{id}_bd" style="{s_bd}"><table border=0 width="100%" height="auto"><tbody><tr><td style="{s_td}" valign="top"><div style="{s_image}"></div></td><td style="{s_td}">{bd_text}</td></tr><tr><td align="center" colspan="2" style="{s_td}"><div><input id="{id}_cb" type="checkbox" style="{s_input}"><label for="{id}_cb">{bd_eula}</label></div><div id="{id}_eula_not" style="display:none; {s_eula_not}"><br>{bd_eulanotchecked}</div><br></td></tr></tbody><tfoot><tr><td align=right colspan=2 style="{s_td} {s_buttons}"><button id="{id}_bt1" style="{s_input}">{bd_continue}</button><button id="{id}_bt2" style="{s_input}">{bd_notnow}</button></td></tr></tfoot></table></div></div>',G='<div id="{id}_overlay" style="{s_overlay}"></div>',F,H,T=function(){var e={ie:0,opera:0,gecko:0,webkit:0};var d=navigator.userAgent,c;if((/KHTML/).test(d)){e.webkit=1}c=d.match(/AppleWebKit\/([^\s]*)/);if(c&&c[1]){e.webkit=parseFloat(c[1])}if(!e.webkit){c=d.match(/Opera[\s\/]([^\s]*)/);if(c&&c[1]){e.opera=parseFloat(c[1])}else{c=d.match(/MSIE\s([^;]*)/);if(c&&c[1]){e.ie=parseFloat(c[1])}else{c=d.match(/Gecko\/([^\s]*)/);if(c){e.gecko=1;c=d.match(/rv:([^\s\)]*)/);if(c&&c[1]){e.gecko=parseFloat(c[1])}}}}}return e}();function Y(c){return(c&&c.nodeType)?c:document.getElementById(c)}function L(c){return typeof c==="string"}function J(c){return typeof c==="object"}function R(t,d){var h,g,f,n,p,r,m=[],e,l=" ",c="{",q="}";for(;;){h=t.lastIndexOf(c);if(h<0){break}g=t.indexOf(q,h);if(h+1>=g){break}e=t.substring(h+1,g);n=e;r=null;f=n.indexOf(l);if(f>-1){r=n.substring(f+1);n=n.substring(0,f)}p=d[n];t=t.substring(0,h)+p+t.substring(g+1)}for(h=m.length-1;h>=0;h=h-1){t=t.replace(new RegExp("~-"+h+"-~"),"{"+m[h]+"}","g")}return t}function I(e,d,c){if(L(e)){e=Y(e)}if(e.addEventListener){e.addEventListener(d,c,false)}else{if(e.attachEvent){e.attachEvent("on"+d,c)}}}function D(e,d,c){if(L(e)){e=Y(e)}if(!e){return}if(e.removeEventListener){e.removeEventListener(d,c,false)}else{if(e.detachEvent){e.detachEvent("on"+d,c)}}}function O(){var d=window.innerWidth,c=window.innerHeight,e=document.compatMode;if((e||T.ie)&&!T.opera){if(e==="CSS1Compat"){c=document.documentElement.clientHeight;d=document.documentElement.clientWidth}else{c=document.body.clientHeight;d=document.body.clientWidth}}return[d,c]}function V(){var d=O();var g=window.XMLHttpRequest===null?document.documentElement.scrollLeft:0;var f=window.XMLHttpRequest===null?document.documentElement.scrollTop:0;var e=F.offsetHeight;var c=F.offsetWidth;F.style.left=Math.floor(Math.max((g+(d[0]-c)/2),0))+"px";F.style.top=Math.max(0,Math.floor(Math.max((f+(d[1]-e)/2),0))-50)+"px"}function A(){D(E.id+"_bt1","click",b);D(E.id+"_bt2","click",A);D(E.id+"_bt3","click",A);D(window,"resize",V);F.parentNode.removeChild(F);H.parentNode.removeChild(H);if(Z){K(Z)}}function b(d){var c=Y(E.id+"_cb");if(c.checked){X.resume()}else{Y(E.id+"_eula_not").style.display="block"}}function U(){var c=document.createElement("div");c.innerHTML=R(G,E);document.body.appendChild(c);H=Y(E.id+"_overlay")}function M(){var c=document.createElement("div");document.body.appendChild(c);c.innerHTML=R(P,E);F=Y(E.id+"_dialog");V();I(window,"resize",V);I(E.id+"_bt1","click",b);I(E.id+"_bt2","click",A)}function N(g,m){var f,l,h,j=g.type,d,c,i;i=Y(E.id+"_dialog");f=Y(E.id+"_bd");l=Y(E.id+"_title");h=0;if(j==="javaCheck"){C=true;g.pause();U();M()}else{if(j==="startFallbackInstall"){D(E.id+"_bt1","click",b);D(E.id+"_bt2","click",A);f.innerHTML=R(W,E);l.innerHTML=E.fallback_title}else{if(j==="startJavaInstall"){D(E.id+"_bt1","click",b);D(E.id+"_bt2","click",A);f.innerHTML=R(Q,E);l.innerHTML=E.java_title}else{if(j==="running"){if(g.hasOwnProperty("percent")){d=Y(E.id+"_progress_bar");c=Y(E.id+"_progress_text");if(d&&c){h=""+parseInt(g.percent,10)+"%";Y(E.id+"_progress_bar").style.width=h;Y(E.id+"_progress_text").innerHTML=h}}}else{if(j==="complete"&&i){f.innerHTML=R(S,E);l.innerHTML=E.done_title;I(E.id+"_bt3","click",A)}}}}}}function B(c){if(C){Z=c}else{K(c)}}return{start:function(c,f){var e,g,d={pathToJar:".",installJarName:"bp-installer.jar",checkJarName:"bp-java-check.jar",installURL:"http://browserplus.yahoo.com/dist/v2/installer/"};K=f;if(!K){K=c;c={}}c=c||{};if(typeof K!=="function"){throw"No callback function provided to start()"}if(typeof c!=="object"){throw"Config object passed to start() is not an object."}for(e in d){if(d.hasOwnProperty(e)){c[e]=c[e]||d[e]}}if(c.hasOwnProperty("strings")&&J(c)){g=c.strings;for(e in g){if(g.hasOwnProperty(e)&&L(g[e])){E[e]=g[e]}}}c.eventHandler=N;X=BPInstaller(c);if(BrowserPlus.clientSystemInfo().os==="Mac"){E.fallback_text=E.fallback_text_mac}else{E.fallback_text=E.fallback_text_win}X.start({},B)}}}();