google.setOnLoadCallback(function() {
	dojo.require("dijit.layout.ContentPane");
	dojo.require("dijit.layout.TabContainer");
	dojo.addOnLoad(function () {
		var rotator=null;
		var duration=6000;
		
		// Vertically align tab contents
		var valigntab=function(tab) {
			var contents=dojo.query('.tabcontents',tab);
			if (contents.length > 0) {
				contents=contents[0];
			}
			var owner=dojo.contentBox(tab);
			var me=dojo.contentBox(contents);
			if (me.h < owner.h) {
				var top=Math.floor((owner.h-me.h)/2);
				var bottom=owner.h-me.h-top;
				dojo.style(contents,'paddingTop',top+'px');
				dojo.style(contents,'paddingBottom',bottom+'px');
			}
		};
		
		// Cancel rotation on click
		var rcancel=function() {
			if (rotator) {
				clearInterval(rotator);
				rotator=null;
			}
		};
		
		// Reveal tab box.
		dojo.forEach(dojo.query('.tabbox'),function (item) {
			dojo.forEach(dijit.findWidgets(item),function (tabcontainer) {
				valigntab(tabcontainer.selectedChildWidget.domNode);
				// Cancel rotation on click
				for (var i in tabcontainer.tablist.pane2button) {
					dojo.connect(tabcontainer.tablist.pane2button[i],'onClick',rcancel);
				}
				// Since tab container dimensions are undefined until they are selected, vertical align
				// when a tab container is revealed.
				dojo.connect(tabcontainer,'selectChild',function() {
					valigntab(tabcontainer.selectedChildWidget.domNode);
				});
				rotator=setInterval(function() {
					tabcontainer.forward();
				},duration);
			});
			dojo.style(item,'visibility','visible');
		});
	});
});
google.load("dojo", "1.6");
