/**
 * Javascript to make navigation word in ie6 
 */
sfHover = function() {
	var sfEls = document.getElementById("navPrimary").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/**
 * remove links from certain nav items 
 */
document.observe("dom:loaded", function() {   
	try{$('navBiodiversityNature').down('a').removeAttribute('href');}	catch(e){}
	try{$('navClimateEnergy').down('a').removeAttribute('href');}			catch(e){}
	try{$('navGovernanceAndTools').down('a').removeAttribute('href');}	catch(e){}
	try{$('navIndustryHealth').down('a').removeAttribute('href');}			catch(e){}
	try{$('navSustainability').down('a').removeAttribute('href');}			catch(e){}
}); 

/**
 * function: to show hide div elements for tabs
 */
function showTab(el,id){
	$(el).addClassName('selected');
	$(el).up('li').siblings().each(function(e){e.down('a').removeClassName('selected');});
	
	$(id).show();
	$(id).siblings().each(function(e){e.hide();});
}

/**
 * function: for sliding teaser on homepage
 * usage: setInterval(homepageTeaserRun,3000);
 */
 function homepageTeaserRun(){
	var container = $("homepageTeaser1").down('ul');
	var slides = container.childElements();
	var dots = $("homepageTeaser1Dots").down('span').childElements();
	for(i=0;i<slides.length;i++){
		if(slides[i].visible()){
			var current = i;
			i=999; //break loop
		}
	}
	var next = (current+1)%slides.length;
	/*
	// TOP TO BOTTOM ANIM
	var nextHeight = slides[next].getHeight();
	slides[next].show();
	slides[next].style.top = -nextHeight+'px';
	slides[next].style.position = 'absolute';
	slides[current].style.position = 'absolute';
	var currentHeight = slides[current].getHeight();
	container.style.height = currentHeight+'px';
	
	dots[next].addClassName('current');
	dots[current].removeClassName('current');
	
	new Effect.Parallel([
		new Effect.Move(slides[next], { 
			x: 0, 
			y: 0, 
			mode: 'absolute',
			sync: true 
			}),
		new Effect.Move(slides[current], { 
			x: 0, 
			y: nextHeight,
			mode: 'absolute', 
			sync: true, 
			afterFinish: function(effect){
				effect.element.hide();
				}
			}),
		new Effect.Morph(container,{style: "height:"+nextHeight+"px;",sync:true})
		],{
			duration: .8
		}
	);
	*/
	
	// left TO RIGHT ANIM
	var nextWidth = slides[next].getWidth();
	slides[next].show();
	slides[next].style.left = -nextWidth+'px';
	slides[next].style.position = 'absolute';
	slides[current].style.position = 'absolute';
	var currentHeight = slides[current].getHeight();
	container.style.height = currentHeight+'px';
	var nextHeight = slides[next].getHeight();
	
	dots[next].addClassName('current');
	dots[current].removeClassName('current');
	
	new Effect.Parallel([
		new Effect.Morph(container,{style:"height:"+nextHeight+"px;"}),
		
		new Effect.Move(slides[next], { 
			x: 0, 
			y: 0, 
			mode: 'absolute',
			sync: true 
			}),
		new Effect.Move(slides[current], { 
			x: nextWidth, 
			y: 0,
			mode: 'absolute', 
			sync: true, 
			afterFinish: function(effect){
				effect.element.hide();
				}
			})
		],{
			duration: 1.6
		}
	);
	
 }
 
/**
 * function: for second sliding teaser on homepage
 * usage: var groupFocusTime = setTimeout(groupFocusRun,10000);
 */
 function groupFocusRun(dir){
	var dir = (dir=="previous")? -1 : 1;
	
	try{clearTimeout(groupFocusTime)}catch(e){}
	var container = $("groupFocus").down('ul');
	var slides = container.childElements();
	for(i=0;i<slides.length;i++){
		if(slides[i].visible()){
			var current = i;
			i=999; //break loop
		}
	}
	
	var next = (current+slides.length+dir)%slides.length;
	var nextWidth = slides[next].getWidth();
	slides[next].show();
	slides[next].style.left = dir*nextWidth+'px';
	slides[next].style.position = 'absolute';
	slides[current].style.position = 'absolute';
	
	
	new Effect.Parallel([
		new Effect.Move(slides[next], { 
			x: 0, 
			y: 0, 
			mode: 'absolute',
			sync: true 
			}),
		new Effect.Move(slides[current], { 
			x: -dir*nextWidth, 
			y: 0,
			mode: 'absolute', 
			sync: true, 
			afterFinish: function(effect){
				effect.element.hide();
				}
			})
			],{
			duration: 1.2
		}
	);
	groupFocusTime = setTimeout(groupFocusRun,12000);
}

/**
 * function: show hide extra info in events
 * usage:
 */
 function showHide(el){
 	if(!$(el).hasClassName('showHideOpen')){
 		$(el).addClassName('showHideOpen');
 		$(el).next('.showHide').show();
 	}else {
 		$(el).removeClassName('showHideOpen');
 		$(el).next('.showHide').hide();
 	}
 	
 	
 }