(function() {
	// create some shortcuts
	YAHOO.util.Event.onDOMReady(function() {
		// add mouseover listeners to the top and left menu
		mouseEventsTopMenu();
		mouseEventsLeftMenu();
		
		// do we have a statement?
		checkStatement();
		
		// adjust height of content
		// adjustContentHeight();
		
		// window.adjustContentHeight = adjustContentHeight;
		
		// add browser resize handler
		// YAHOO.util.Event.addListener(window, 'resize', adjustContentHeight);
		
		// print version?
		if (window.print) checkPrintVersion();
		
	}, this, true);
})();


/**
 * Adds mouse listener to the top menu spans
 */
function mouseEventsTopMenu(){
	var mouseOverMenuTop = function(e){
		var Dom = YAHOO.util.Dom;
		Dom.setStyle(this, 'background-color', '#FFFFFF');
		Dom.setStyle(YAHOO.util.Selector.query('a', this, true), 'color', '#c50347');
		document.body.style.cursor = 'pointer';
	}
	var mouseOutMenuTop = function(e){
		YAHOO.util.Dom.setStyle(this, 'background-color', '#e3e38d');
		var elLink = YAHOO.util.Selector.query('a', this, true);
		YAHOO.util.Dom.setStyle(elLink, 'color', '#000000');
		document.body.style.cursor = 'default';
	}
	var mouseClickMenuTop = function(e){
		// get the link location
		var linkEl = YAHOO.util.Selector.query('a', this, true);
		location.href = linkEl.getAttribute('href');
	}
	// do some preparsing..
	var el = YAHOO.util.Dom.getElementsBy(
		function(el){
					var Dom = YAHOO.util.Dom;
					if(Dom.getAttribute(el, 'class')){
						return ((Dom.getAttribute(el, 'class').toLowerCase().indexOf('menutop') > -1) 
							&&(Dom.getAttribute(el, 'class').toLowerCase().indexOf('menutopactive') == -1)
							&&(Dom.getAttribute(el, 'class').toLowerCase().indexOf('menutophome') == -1)
							&&(Dom.getAttribute(el, 'class').toLowerCase().indexOf('menutopcoord') == -1))
					} else {
						return false;	
					}
		},
		'',
		YAHOO.util.Dom.get("mainDiv"),
		function(el){
			// add a listener to the button
			YAHOO.util.Event.addListener(el, 'mouseover', mouseOverMenuTop, this);
			YAHOO.util.Event.addListener(el, 'mouseout', mouseOutMenuTop, this);
			YAHOO.util.Event.addListener(el, 'click', mouseClickMenuTop, this);
		}
	);

}


/**
 * Adds mouse listener to the left menu divs
 */
function mouseEventsLeftMenu(){
	var mouseOverMenuLeft = function(e){
		YAHOO.util.Dom.setStyle(this, 'background-color', '#FFFFFF');
		var elLink = YAHOO.util.Selector.query('a', this, true);
		YAHOO.util.Dom.setStyle(elLink, 'color', '#c50347');
		document.body.style.cursor = 'pointer';
	}
	var mouseOutMenuLeft = function(e){
		YAHOO.util.Dom.setStyle(this, 'background-color', '#edf4fa');
		var elLink = YAHOO.util.Selector.query('a', this, true);
		YAHOO.util.Dom.setStyle(elLink, 'color', '#000000');
		document.body.style.cursor = 'default';
	}
	var mouseClickMenuLeft = function(e){
		// get the link location
		var linkEl = YAHOO.util.Selector.query('a', this, true);
		location.href = linkEl.getAttribute('href');
	}
	
	var r;
	// do some preparsing..
	var el = YAHOO.util.Dom.getElementsBy(
		function(el){
			r = (YAHOO.util.Dom.getAttribute(el, 'class')=='menuLeft') || (YAHOO.util.Dom.getAttribute(el, 'class')=='menuLeftIndent')
			return r;
			
		},
		'',
		YAHOO.util.Dom.get("mainDiv"),
		function(el){
			// add a listener to the button
			YAHOO.util.Event.addListener(el, 'mouseover', mouseOverMenuLeft, this);
			YAHOO.util.Event.addListener(el, 'mouseout', mouseOutMenuLeft, this);
			YAHOO.util.Event.addListener(el, 'click', mouseClickMenuLeft, this);
		}, 
		this, 
		true
	);
}


/*
 * Checks wheather there is a statement and handles some styles
 */
function checkStatement(){
	var Dom = YAHOO.util.Dom;
	el = Dom.getElementsByClassName('statement_container');
	elTdA = Dom.getElementsByClassName('bereich_rechts');
	elTd = elTdA[0];
	if(el.length > 0){
		// there is a statement on the page
		Dom.setStyle(elTd, 'background-color', '#f1f1c6');
		Dom.setStyle(Dom.get('statementBalken'), 'background-color', '#c50347');
	} else {
		Dom.setStyle(elTd, 'background-color', '#ffffff');
		elTd.innerHTML = "<div class='blaugross' style='margin-left:16px;line-height:1.3;font-weight:bold'>UNIFEM - " + window.sloganReplacement + "</div>";
	}
	
}


/*
 * Checks wheather we have to display the print version
 */
function checkPrintVersion(){
	// handle all the elements containing the noPrint class
	var el = YAHOO.util.Dom.getElementsBy(
		function(el){
			if (YAHOO.util.Dom.getAttribute(el, 'class')){
				return (YAHOO.util.Dom.getAttribute(el, 'class').toLowerCase().indexOf('noprint')>-1)
			} else {
				return false;
			}
		},
		'',
		'',
		function(el){
			YAHOO.util.Dom.setStyle(el, 'background-color', '#FFFFFF');
			YAHOO.util.Dom.setStyle(el, 'background-image', 'none');
			// handle menu entries of home site
			if (window.seite == null){
				YAHOO.util.Dom.setStyle(el, 'color', '#c50347');
			}
		}
	);
	
	// handle body background
	YAHOO.util.Dom.setStyle(document.body, 'background-image', 'none');
}


function adjustContentHeight(){
	var Dom = YAHOO.util.Dom;
	var height = document.body.clientHeight - parseInt(Dom.getStyle(Dom.get('bereich_oben'), 'height'));
	Dom.setStyle(Dom.get('table_bereich_unten'), 'height', height + 'px');
}