var toolbox={
id:'toolbox-wrap',
position:'',
object:null,
toolboxConfigure:null,
toolboxInfo:null,
toolboxMinimize:null,
toolboxClose:null,
widgetconfiguratorbody:null,
toolboxsidebar:null,
toolboxmenubar:null,
sidebarvisible:false,
server:location.hostname,
database:location.pathname.split('/')[1]+'/widgets.nsf',
viewName:'wtoolbox',
widgets:new Array(),
widgetCloseID:null,
widgetID:null,
widgetCount:0,
request:null,
parameters:'?ReadViewEntries&OutputFormat=json',
url:'',
view:null,
getJSON:function(){	
	this.request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	if (this.request) {
			this.request.open("GET", this.url,false);
			this.request.send(null);
			if (this.request.status == 200){
				this.view=eval("("+this.request.responseText+")");
			}	
			else {
				alert("Problem: " + this.request.status);
			}	
	}
		return null;	
	
	},	
move:function(){

},
configure:function(){

},
info:function(){

},
minimize:function(){
  if(!this.sidebarvisible){
  	this.sidebarvisible=true;
  	this.object.className='toolbox-hidden';
  	this.toolboxsidebar.className='wMenuBar';
  }
  else{
  	this.sidebarvisible=false;
  	this.object.className='toolbox';
  	this.toolboxsidebar.className='wMenuBar-hidden';
  }
},

close:function(){

},
init:function(){
//this.url='http://'+this.server+'/'+this.database+'/'+this.viewName+this.parameters;
//this.getJSON();
//this.buildToolbox();
this.object=document.getElementById(this.id);

this.toolboxmenubar=document.getElementById('wMenu-Bar');
addToolBoxEvent(this.toolboxmenubar, 'click', function(event) {
	toolbox.minimize();
});
this.toolboxsidebar=document.getElementById('toolbox-sidebar');
addToolBoxEvent(this.toolboxsidebar, 'click', function(event) {
	toolbox.minimize();
});
},
setWidget:function(parent,child,title,icon){
this.widgets[this.widgetCount]={"parent":parent,"child":child,"title":title,"icon":icon};
this.widgetCount++;
},
showWidgets:function(parent){		
	var widgetList=this.widgets;
	for(i=0;i < widgetList.length;i++){
		var div=document.getElementById(widgetList[i].child);
		if(widgetList[i].parent==parent){
			div.className='widgetList-child';
			var parentLi=document.getElementById('l'+widgetList[i].parent);
			parentLi.className='widgetList-parent-link-sel';
		}
		else{
			div.className='widgetList-child-hide';
			var parentLi=document.getElementById('l'+widgetList[i].parent);
			parentLi.className='widgetList-parent-link';
		}
	}
},
createWidget:function(closeId,id){
if(this.widgetCloseID!=null){
	var widgetListElement=document.getElementById(this.widgetCloseID);
	widgetListElement.className='widgetList-child';
	var dojoDndItem=document.getElementById(this.widgetID);
	dojoDndItem.style.display='none';
}
this.widgetCloseID=closeId;
this.widgetID=id;
var closeDiv=document.getElementById(closeId);
closeDiv.className='widgetList-child-hidden';
var div=document.getElementById(id);
div.style.display='block';
},
resetWidget:function(id){
var widgetListElement=document.getElementById('WG'+id);
widgetListElement.className='widgetList-child';
var dojoDndItem=document.getElementById('iw-'+id);
dojoDndItem.style.display='none';
},
getWidget:function(id){
var widget=null;
for(i=0;i < this.widgets.length;i++){
	if(this.widgets[i].child==id){
		widget=this.widgets[i];
	}
}
return widget;
}
}

function addToolBoxEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}


