// use the pDomApi to make the eva menu appear and disappear (rather then jQuery, since then
// we would need to include that in nearly every view of MA, which might cause problems in
// combination with the pDomApi

pDomApi.addEvent(window,'domload', function() {
	initEvaButtonClick();
	initBannerRotator();
});

function initEvaButtonClick() {
	pDomApi.addEvent(
		'evaButton',
		'click',
		function(e) {
			pDomApi.preventDefault(e);
			var menu = eId('evaExtra');
			pDomApi.showHide(menu);

			// very ugly, but seems to be necessary to let IE6/7 get their rendering shit together
			var container = eId('categoryList');

			if (container != null) {
				setTimeout(
					function(){
						container.className = container.className;
					}, 1
				);
			}

			// for the myfields view, we need to call another function, to make sure the fields are
			// properly displayed. We can of course only call this function if it exists...
			// the reason to put it here, is that the event needs to be triggered AFTER the
			// show/hide of the eva menu. If we would put it in a different file, we would have no
			// guarantees about the order of execution of the click events
			if (typeof clearFields == 'function') {
				clearFields();
			}
		}
	);
}

function initBannerRotator() {

	if (typeof jQuery == 'undefined') {
		return;
	}

	var banners			= $('#rightBanners div.banner');
	var animInterval	= 6000;
	var animSpeed		= 1500;
	var curBanner		= 0;
	var numBanners		= banners.length;
	window.setInterval(
		function() {
			for (var i = 0; i < numBanners; i++) {

				var banner = banners[i];
				if (i == curBanner) {
					$(banner).fadeIn(animSpeed);
				} else {
					$(banner).fadeOut(animSpeed);
				}
			}
			curBanner = (curBanner + 1 >= numBanners) ? 0 : curBanner + 1;

		}, animInterval
	);
}
