var modules = [];
var currentModule = null;
var previousModule = null;
var timer = null;
var hds = null;
var dps = null;
var dps1 = null;

dojo.declare("NavigationPair", null, {
    constructor: function(handle, dropdown, dropdown1){
		this.handle=handle;
		this.dropdown=dropdown;
		this.dropdown1=dropdown1;
	},
	doShow: function() {					
		dojo.style(this.dropdown, "display", "block");
		dojo.style(this.dropdown1, "display", "block");
	},
	doHide: function() {
		dojo.style(this.dropdown, "display", "none");	
		dojo.style(this.dropdown1, "display", "none");	
	}
});

dojo.addOnLoad(function() {		
		
	hds = dojo.query(".popupHandle");				
	dps = dojo.query(".popupFootnotes");
	dps1 = dojo.query(".popupTriangle");
		
	timer = new dojox.timing.Timer(100);
	dojo.connect(timer, "onTick", reset);
	
	for (var i=0; i<dps.length; i++) {
		modules.push(new NavigationPair(hds[i], dps[i], dps1[i]));				
	}
	
	dojo.forEach(modules, function (module, index) {			
			dojo.connect(module.handle, "onmouseenter", showPopup);						
			dojo.connect(module.handle, "onmouseleave", timerStart);
			dojo.connect(module.dropdown, "onmouseenter", timerStop);				
			dojo.connect(module.dropdown, "onmouseleave", timerStart);
			dojo.connect(module.dropdown1, "onmouseenter", timerStop);				
			dojo.connect(module.dropdown1, "onmouseleave", timerStart);
		}
	);	
});	

function timerStart() {				
	timer.start();
}

function timerStop() {				
	timer.stop();
}	

function reset() {
//	if (currentModule != null)	{
//		currentModule.doHide();
//	} else {
		dojo.forEach(modules, function(module) {
				module.doHide();
			}
		);
//	}
	timer.stop();
}

function showPopup(evt) {
	currentModule = modules[dojo.indexOf(hds, evt.currentTarget)];
	if (previousModule != null && previousModule != currentModule) {
		reset();
	} else {
		timer.stop();
	}	
	currentModule.doShow();	
	dojo.style(currentModule.dropdown, "top", popupAttribute[dojo.indexOf(hds, evt.currentTarget)][0]);	
	dojo.style(currentModule.dropdown, "left", popupAttribute[dojo.indexOf(hds, evt.currentTarget)][1]);	
	dojo.style(currentModule.dropdown, "width", popupAttribute[dojo.indexOf(hds, evt.currentTarget)][2]);	
	dojo.style(currentModule.dropdown, "height", popupAttribute[dojo.indexOf(hds, evt.currentTarget)][3]);	
	dojo.style(currentModule.dropdown1, "top", popupAttribute[dojo.indexOf(hds, evt.currentTarget)][4]);	
	dojo.style(currentModule.dropdown1, "left", popupAttribute[dojo.indexOf(hds, evt.currentTarget)][5]);	
	previousModule = modules[dojo.indexOf(hds, evt.currentTarget)];
}			