
YAHOO.util.Event.onDOMReady(initPage);

function initPage(){
	// set up 'resources' tabs:
	//var tabView = new YAHOO.widget.TabView('resourcesTabbedContentContainer');

	// set up accordion:
	accordionWidget.init(
		{activateOnHover:false}, // if this is false, accordion sections will change 'onclick'
		[
			{btnId:"accordion_btn_1", contentId:"accordion_content_1"},
			{btnId:"accordion_btn_2", contentId:"accordion_content_2"},
			{btnId:"accordion_btn_3", contentId:"accordion_content_3"}//,
			//{btnId:"accordion_btn_4", contentId:"accordion_content_4"}
		]
	);
}

var accordionWidget = {
	activeIndex:0,
	activateOnHover:true,
	init:function(configObj,sectionsDataObjArray){
		this.activateOnHover = configObj.activateOnHover;
		for(var i = 0; i < sectionsDataObjArray.length; i++){
			this.sections.push(this.makeSection(sectionsDataObjArray[i].btnId,sectionsDataObjArray[i].contentId,i));
		}
		this.hideAll();
		// expand first section:
		//this.sections[0].expandContent(this.sections[0]);
	},
	sections:[],
	makeSection:function(triggerIdStr,contentIdStr,index){
		var s = document.getElementById(triggerIdStr);
		s.expanded = false;
		s.content = document.getElementById(contentIdStr);
		s.contentHeight = this.getElementHeight(contentIdStr);
		s.index = index;
		s.collapseContent = function(){
			if(this.expanded){
				this.expanded = false;
				
				sid = this.content.id;
				sid = sid.substr(18,sid.length);
				document.getElementById('arrow'+sid).src='/business/enterprise/emea/nld/pix/down_a.gif'
				
				// youtube video? 
				/*if(this.content.id == "accordion_content_2"){
					// get player state:
					var vidPlayerObj = document.getElementById("youtubeVideoFlash");
					try{
						var vidPlayerState = vidPlayerObj.getPlayerState();
						if(vidPlayerState >= 1 && vidPlayerState != 2 && vidPlayerState < 5){ // playing
							vidPlayerObj.pauseVideo();
							this.playVideoOnExpand = true;
						}else{
							this.playVideoOnExpand = false;
						}
					}
					catch(e){
						// Flash not loaded yet, or doesn't exist
					}
				}*/
				var anim = new YAHOO.util.Anim(this.content,{height:{to:21}},.5);
				anim.animate();
			}
		}
		s.expandContent = function(_this){
			ssid = _this.content.id;
			ssid = ssid.substr(18,ssid.length);
			if(_this.expanded){ 
			_this.expanded = false;
				document.getElementById('arrow'+ssid).src='pix/down_a.gif'
				
				var anim = new YAHOO.util.Anim(this.content,{height:{to:21}},.5);
				anim.animate();
			
			return false; }
			
			document.getElementById('arrow'+ssid).src='pix/up_a.gif'
			// hide item that is open:
			accordionWidget.sections[accordionWidget.activeIndex].collapseContent();

			// show this item:
			_this.expanded = true;
			accordionWidget.activeIndex = _this.index;
			var anim = new YAHOO.util.Anim(_this.content,{height:{to:_this.contentHeight}},.5);
			anim.animate();
			/*if(_this.playVideoOnExpand === true){
				var vidPlayerObj = document.getElementById("youtubeVideoFlash");
				vidPlayerObj.playVideo();
			}*/
			return false;
		}
		
		if(this.activateOnHover){
			s.onmouseover = function(){
				return this.expandContent(this);
			}
		}else{
			s.onclick = function(){
				return this.expandContent(this);
				//return false;
			}
			s.style.cursor = "pointer";
		}
		return s;
	},
	hideAll:function(){
		for(var i = 0; i < this.sections.length; i++){
			this.sections[i].content.style.height = "21px";
		}
	},
	getElementHeight:function(elIdStr){
		var region = YAHOO.util.Dom.getRegion(elIdStr);
		return region.bottom - region.top;
	}
}


