if (typeof namespace == "object")
{
	// Code for changing the background of the search bar
	try{
		namespace.selectAppropriateEngine= function(engId){
			var searchbar = namespace.toolbar.getElementById(namespace.framework.applicationId+'-search');
			var currentSearchbarId = engId.id;
			
			var jacksonId = namespace.framework.applicationId+'-searchengine1484';
			var searchworksId = namespace.framework.applicationId+'-searchengine1522';
			var googleId = namespace.framework.applicationId+'-searchengine1566';
			var googleScholarId = namespace.framework.applicationId+'-searchengine1528';
			
			var searchbarTextbox = document.getElementById(searchbar.$id+searchbar.$ID_TEXTBOX);
			var searchbarIsEmpty = (searchbar.$textbox.value == "");
			
			if(currentSearchbarId==searchworksId && searchbarIsEmpty) {
				var searchworksImg = "chrome://"+namespace.framework.applicationId+"/skin/search-works.bmp";
				searchbar.setAttribute("backgroundimage", searchworksImg);
				if(dtxFramework.MOZILLA){					
					searchbar.$textbox.style.cssText = 'margin-top:4px;background-position: center center; background-repeat: no-repeat;background-image:url(' + searchworksImg + ')';
				} else if(dtxFramework.IE){
					searchbar.$textbox.style.cssText= 'background-position: center center;background-repeat: no-repeat;background-image:url(' + searchworksImg + ')';
				}
			}
			else if(currentSearchbarId==jacksonId && searchbarIsEmpty) {
				var jacksonImg = "chrome://"+namespace.framework.applicationId+"/skin/search-jackson.bmp";
				searchbar.setAttribute("backgroundimage", jacksonImg);
				if(dtxFramework.MOZILLA){					
					searchbar.$textbox.style.cssText = 'margin-top:4px;background-position: center center; background-repeat: no-repeat;background-image:url(' + jacksonImg + ')';
				} else if(dtxFramework.IE){
					searchbar.$textbox.style.cssText= 'background-position: center center;background-repeat: no-repeat;background-image:url(' + jacksonImg + ')';
				}
			}
			else if(currentSearchbarId==googleId && searchbarIsEmpty) {
				googleImg = "chrome://"+namespace.framework.applicationId+"/skin/search-google.bmp";
				searchbar.setAttribute("backgroundimage", googleImg);
				if(dtxFramework.MOZILLA){					
					searchbar.$textbox.style.cssText = 'margin-top:4px;background-position: center center; background-repeat: no-repeat;background-image:url(' + googleImg + ')';
				} else if(dtxFramework.IE){
					searchbar.$textbox.style.cssText= 'background-position: center center;background-repeat: no-repeat;background-image:url(' + googleImg + ')';
				}
			}
			else if(currentSearchbarId==googleScholarId && searchbarIsEmpty) {
				googleScholarImg = "chrome://"+namespace.framework.applicationId+"/skin/search-google-scholar.bmp";
				searchbar.setAttribute("backgroundimage", googleScholarImg);
				if(dtxFramework.MOZILLA){					
					searchbar.$textbox.style.cssText = 'margin-top:4px;background-position: center center; background-repeat: no-repeat;background-image:url(' + googleScholarImg + ')';
				} else if(dtxFramework.IE){
					searchbar.$textbox.style.cssText= 'background-position: center center;background-repeat: no-repeat;background-image:url(' + googleScholarImg + ')';
				}
			}
			else {
				var blankImg = "chrome://"+namespace.framework.applicationId+"/skin/searchbar-bg.png";
				searchbar.setAttribute("backgroundimage", blankImg);
				if(dtxFramework.MOZILLA){					
					searchbar.$textbox.style.cssText = 'margin-top:4px;background-position: center center; background-repeat: no-repeat;background-image:url(' + blankImg + ')';
				} else if(dtxFramework.IE){
					searchbar.$textbox.style.cssText= 'background-position: center center;background-repeat: no-repeat;background-image:url(' + blankImg + ')';
				}
			}

			searchbar.$textbox.blur();
		}
	}catch(e){
		//alert("error selecting engine background: "+e.message);
	}	
		

	namespace.emailTheLibrary = function(){
		namespace.framework.loadURI("mailto:library.DLT@gsb.stanford.edu?subject=My%20Suggestion&body="+namespace.framework.getCurrentURI());
	}
	
	namespace.shareALink = function(){
		namespace.framework.loadURI("mailto:YourFriend@email.com?subject=I%20am%20recommending%20this%20link%20to%20you.&body="+namespace.framework.getCurrentURI());
	}
	

	namespace.addApps = function(){
		try{
			
			 var myButton = namespace.toolbar.getElementById(namespace.framework.applicationId+'-widgetbutton');
			
			if(myButton == null)
				return;
			   
			if (myButton.$initialized == false)
				myButton.$init();
			   
			myButton.$createPanel();
		   
			var position = myButton.$getChromeBoundingBox();
			var x = position.x + parseInt((position.width - myButton.$PANEL_WIDTH) / 2, 10);
			var y = position.y + position.height;
		   
			myButton.$panel.showRelative(namespace.toolbar.getElementById(namespace.framework.applicationId+'-settings-box'), 0, 25);
		  
			if (dtxFramework.MOZILLA){
				myButton.$panel.addEventListener('documentready', function(evt) {
					myButton.$doc = evt.doc;
					myButton.$renderPanel();
					myButton.$addEventListenersToPanel();
				}, false );
			}else if(dtxFramework.IE) {
				myButton.$doc = myButton.$panel.$window.document ;
				myButton.$renderPanel();
				myButton.$addEventListenersToPanel();
			}
		}catch(e){
			//alert(e.message);
		}
	}


}