/**
 * @author stewan
 */

  
  gloader.load(["glow", "1", "glow.events", "glow.dom"],{
  	onLoad: function(glow) {
		
		//get contentdiv nodelist, and hide the nodes, then display the default, so that if no
		//js, all divs will be displayed
		glow.dom.get("div#eu_bud_spend_contentSubWrapper > div").css("display", "none")
		glow.dom.get("div#eu_bud_spend_contentSubWrapper > div").css("position", "absolute")
		glow.dom.get("div#eu_bud_spend_contentSubWrapper > div#Overview").css("display", "block")
				
		var i = 0;
		
		glow.dom.get("div#eu_bud_spend_buttonBar div").each(
			function() {
				var j = i++;
				
				glow.events.addListener(
					glow.dom.get(this),
					"click",
					function (){divDisplay(j)}
				);				
			}
		);		
		
		function divDisplay(i){		
			//alert("hello: " + i);			
			//var myButtonList = glow.dom.get("div#buttonBar > div");
			var myContentList = glow.dom.get("div#eu_bud_spend_contentSubWrapper > div");
			//alert(myContentList[i].id);
			var targetElement = myContentList[i];
			
			if ( targetElement.style.display != 'block' ) {//if a new button is clicked
				myContentList.css("display", "none");//set all divs to hidden						
				targetElement.style.display = 'block';//show the new one
				//set height of div.eu_bud_spend_Spending differently for each content div
				if ( targetElement.id == "Foreign Aid" ) {
					glow.dom.get("div.eu_bud_spend_Spending").css("height", "625px")
				} else {
					glow.dom.get("div.eu_bud_spend_Spending").css("height", "600px")
				}
				/*switch(targetElement.id) {
					case "Agriculture":
						//alert("targetElement is "+targetElement.id);
						glow.dom.get("div.eu_bud_spend_Spending").css("height", "600px")
						break;
					case "Regional Aid":
						glow.dom.get("div.eu_bud_spend_Spending").css("height", "600px")
						break;
					case "Foreign Aid":
						glow.dom.get("div.eu_bud_spend_Spending").css("height", "625px")
						break;
					case "Administration":
						glow.dom.get("div.eu_bud_spend_Spending").css("height", "600px")
						break;
					case "Research":
						glow.dom.get("div.eu_bud_spend_Spending").css("height", "600px")
						break;
					case "Education":
						glow.dom.get("div.eu_bud_spend_Spending").css("height", "600px")
						break;
					case "Crime & border control":
						glow.dom.get("div.eu_bud_spend_Spending").css("height", "600px")
						break;
					case "Other":
						glow.dom.get("div.eu_bud_spend_Spending").css("height", "600px")
						break;
					case "Overview":
						glow.dom.get("div.eu_bud_spend_Spending").css("height", "600px")
				}*/
			}
		}
	}
	
  });
