//toggle year from 2007,2008,2009 etc
function showYear(year){
	$$(".year").each(function(item){item.hide();});
	$("events_"+year).show();
	activeYear = year;
          //alert('DCS.dcsuri, '+window.location.pathname+', WT.ti, '+document.title+',WT.cusEventCalendar, '+activeYear);
          dcsMultiTrack('WT.cusEventCalendar', activeYear); dcsAlreadySend = true;
          //dcsMultiTrack('DCS.dcsuri', window.location.pathname, 'WT.ti', document.title,'WT.cusEventCalendar', activeYear);
}
user='HCP';
//toggle individual toggle group within a given year
var activeEvent = 0;
var animationStarted = false;
function showEvent(shortname){

	if (!$('heading_'+activeYear+'_'+shortname)   ) return;
	if (animationStarted == true) return;
	animationStarted = true;
	
	if (!$('heading_'+activeYear+'_'+shortname).hasClassName('closed')) {
		if ($('heading_'+activeYear+'_'+shortname).hasClassName('open')) {
			//if already open
			var effectScrollToAnch = new Effect.ScrollTo($('heading_'+activeYear+'_'+shortname), {queue: { position: 'end', scope: 'events'}});
			animationStarted = false;
		}
	} else {



		//open it!
		//if (activeEvent ) {
		//	if ($('heading_'+activeEvent).hasClassName('open')) {
		//		$('heading_'+activeEvent).removeClassName('open')
		//		var hideEvent = new Effect.BlindUp($('content_'+activeEvent), {queue: { position: 'end', scope: 'events'},
		//					afterFinish:function() {
		//						$('heading_'+activeEvent).addClassName('closed');
		//					}
		//			});
		//	}
		//}
		
		$$("h4.toggle").each(function(item){
			if(item.hasClassName('open')){
				item.removeClassName('open');
			}
			if(!item.hasClassName('closed')){
				item.addClassName('closed');
			}
		});
		$$("div.toggle").each(function(item){item.hide();});

		$('heading_'+activeYear+'_'+shortname).removeClassName('closed');
		var effectScrollToAnch = new Effect.ScrollTo($('heading_'+activeYear+'_'+shortname), {queue: { position: 'end', scope: 'events'},
					afterFinish:function() {
						var showEvent = new Effect.BlindDown($('content_'+activeYear+'_'+shortname), {queue: { position: 'end', scope: 'events'},
									afterFinish:function() {
										var effectScrollToAnch = new Effect.ScrollTo($('heading_'+activeYear+'_'+shortname), {queue: { position: 'end', scope: 'events'}});
										$('heading_'+activeYear+'_'+shortname).addClassName('open');
										activeEvent = activeYear+'_'+shortname;
										animationStarted = false;
									}
							});
					}
		});
	}

  //alert('DCS.dcsuri, '+window.location.pathname+', WT.ti, '+document.title+',WT.cusEventCalendar, '+activeYear);
  dcsMultiTrack('WT.cusEventCalendar', activeYear+'/'+shortname,'WT.cusEngage','Engagement','WT.cusEPoint','2');
	
}
function toggleEvent(shortname){

	if ($('heading_'+activeYear+'_'+shortname).hasClassName('open')) {
	animationStarted = true;
		$('heading_'+activeYear+'_'+shortname).removeClassName('open');
		var hideEvent = new Effect.BlindUp($('content_'+activeYear+'_'+shortname), {queue: { position: 'end', scope: 'events'},
					afterFinish:function() {
						$('heading_'+activeYear+'_'+shortname).addClassName('closed');
						animationStarted = false;
					}
			});
	} else if ($('heading_'+activeYear+'_'+shortname).hasClassName('closed')) {
		
		showEvent(shortname);
	}
}
document.observe('dom:loaded',function(){
	showYear(activeYear);
	//toggle event based on xml positioning
	$$("h4.toggle").each(function(item){item.addClassName('closed')});
	$$("div.toggle").each(function(item){item.hide();});
	//auto-show year when page loads
	//var firstElement = $('events_'+activeYear).childElements()[3].identify();
	//alert(firstElement);
	//var sn = firstElement.substring((firstElement.indexOf("_")+1),firstElement.length);
	//alert(sn);
	//highlight special event via url param from iframe
	var myURL = window.location.search;
	var Start= myURL.indexOf("?");
	if (Start==-1) {return("");}
	//var sn = activeYear+'_'+myURL.substr(1,myURL.length);
	var sn = myURL.substr(1,myURL.length);
	if (sn.length>1) {		
		showEvent(sn);
		/*$('heading_'+sn).addClassName('open');
		$('content_'+sn).setStyle({
			  overflow: 'visible',
			  display: 'block'
			});
		activeEvent =sn;*/
	}
});
