/*
 * Copyright (C) 2008-2010 APN, LLC. All rights reserved
 * 
 * Ask.com Toolbar - Widgets JavaScript module. Author: Tanmay Shrivastava 
 * Description: Contains functions and logic required for notificaitons -popup
 */
var ATB=null;var ATB_NotificationController={_minOpacity:0,_maxOpacity:1,_opacityStep:0.1,_fadeSpeed:100,_toastSpeed:10,_toastIntervalRef:null,_marginTop:window.innerHeight,_marginBottom:window.innerHeight,_marginLeft:window.innerWidth,_marginRight:window.innerWidth,_windowWatcher:Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher),_mainBoxObject:null,_fadeIn:function(){var b=this;if(this._minOpacity<1){this._minOpacity=this._minOpacity+this._opacityStep;if(this._mainBoxObject){this._mainBoxObject.style.opacity=this._minOpacity+"";setTimeout(function(){b._fadeIn()},this._fadeSpeed)}}else{var a=window.arguments[0].fadeTime;if(a){window.setTimeout(function(){b._fadeOut()},a)}}},_fadeOut:function(){if(this._maxOpacity>0){this._maxOpacity=this._maxOpacity-this._opacityStep;if(this._mainBoxObject){this._mainBoxObject.style.opacity=this._maxOpacity+"";var a=this;setTimeout(function(){a._fadeOut()},this._fadeSpeed);return}}window.close()},_closePopupOnBlur:function(){if(window!=this._windowWatcher.activeWindow){window.close()}},_adjustAnchor:function(b){var a=b[0]=="b"?"bottom":"top";document.getElementById(a+"LeftBox").setAttribute("class",a+"LeftBox_pointer_"+b);document.getElementById(a+"Box").setAttribute("class",a+"Box_pointer");document.getElementById(a+"RightBox").setAttribute("class",a+"RightBox_pointer_"+b)},_animate:function(c){var a="margin"+c;if(this["_"+a]>0){if(this._mainBoxObject){this._mainBoxObject.style[a]=this["_"+a]--+"px";var b=this;window.setTimeout(function(){b._animate(c)},this._toastSpeed)}}},popupFrame:null,init:function(c){ATB=window.opener.ATB;if(!ATB){window.close()}if(!window.arguments[0]){ATB.Logger.warn("Insufficient arguments to the notification-popup window - extraParams missing, closing this window");window.close()}this.popupFrame=document.getElementById("asktb-popup-browser");if(!this.popupFrame){ATB.Logger.warn("The element with id asktb-popup-browser is not defined");window.close()}if(!ATB.Net.isNetworkAvailable(true)){ATB.Logger.warn("No internet connection available, closing notificaiton popup");window.close()}this._mainBoxObject=document.getElementById("mainVBox");var e=window.arguments[0].url;var a=window.arguments[0].userClose;var b=window.arguments[0].fadeTime;var d=window.arguments[0].anchor;var g=window.arguments[0].toastDir;var f=this;ATB.Notifications.addProgressListenerOnWindow(this.popupFrame);this.popupFrame.addEventListener("load",function(){f._fadeIn()},true);if(!d&&g){this.popupFrame.addEventListener("load",function(){f._animate(g)},true)}if(!a&&!b){this.popupFrame.addEventListener("load",function(){window.addEventListener("blur",function(){f._closePopupOnBlur()},true)},true)}this.popupFrame.setAttribute("src",e);if(d){this._adjustAnchor(d)}},destroy:function(){ATB.Notifications.removeProgressListenerOnWindow(this.popupFrame)}};