window.addEvent('domready', function() {
	$$('a.tipz').each(function(element,index) {  
			 var content = element.get('name').split('::');  
			 element.store('tip:title', content[0]);  
			 element.store('tip:text', content[1]);	
	 });  

	 //create the tooltips  
	 var tipz = new Tips($$('a.tipz'),{  
			 className: 'tipwrapper',  
			 fixed: true,  
			 hideDelay: 50,  
			 showDelay: 50,
			 offsets: {x: 20, y: -60},
			 onShow: function(tip) {
				 var textHeight = $$('div.tip-text')[0].getHeight();
				 if (textHeight>17&&textHeight<=34)
				   tip.setStyle('margin-top', '-18px');
				 else if (textHeight>34 && textHeight<=51)
				   tip.setStyle('margin-top', '-36px');	
				 else if (textHeight>51)
				 {
				   tip.setStyle('margin-top', '-54px');						 
				 }

				 tip.fade('show');				 
			 },
			 onHide: function(tip) {
				 tip.fade('hide');
			 }
	 });  	 

  currentContentRef = null;

	//create our Accordion instance
	myAccordion = new Accordion($('accordion'), 'li.tabtoggler', 'div.tabcontent', {
		opacity: false,
		onActive: function(tabtoggler, tabcontent){
			tabtoggler.setStyle('background-image', 'url(../../images/training/tab6_selected_background.png)');
			currentContentRef = tabcontent;
		},
		onBackground: function(tabtoggler, tabcontent){
			tabtoggler.setStyle('background-image', 'url(../../images/training/tab6_unselected_background.png)');				
		}
	});
	
// Create our Slider instances that are embedded inside the Accordion
	var list = $$('div.collapse');
	var headings = $$('p.sectiontoggler');
	collapsibles = new Array();

  headings.each( function(heading, i) {

		var collapsible = new Fx.Slide(list[i], { 
			duration: 500, 
			transition: Fx.Transitions.linear,
			onComplete: function(request){ 
			}
		});
		
		collapsibles[i] = collapsible;
		
		heading.addEvent('click', function(){
			// Adjust the height of the outer accordion div according to what slider is opened and closed
			fixHeight(collapsible);
			if (collapsible.open)
				heading.setStyle('background-image', 'url(../../images/arrow_up.png)');
			else
				heading.setStyle('background-image', 'url(../../images/arrow_down.png)');			
			collapsible.toggle();
			return false;
		});
		
		collapsible.hide();
		heading.set('rel', 'collapsible' + i);
		
	});

	// Add or subtract to the accordion height depending on if we are opening or closing a slider embedded in it
	function fixHeight(currentNode)
	{
		var par = currentNode.element;
		while (!par.hasClass('tabcontent')) {
			par = par.getParent();
		}
		par.setStyle('height', ''); // fix the accordion height		
		
	}	

// expand/contract all sliders at once

  $$('.expand-all').addEvent('click', function() {
    currentContentRef.setStyle('height', '');
    currentContentRef.getElements('p.sectiontoggler').each(function(c, i) {
      collapsibles[c.get('rel').replace('collapsible', '')].slideIn();
    });

		return false;
  });
  
  $$('.collapse-all').addEvent('click', function() {
    currentContentRef.setStyle('height', '');
    currentContentRef.getElements('p.sectiontoggler').each(function(c, i) {
      collapsibles[c.get('rel').replace('collapsible', '')].slideOut();
    });

		return false;
  });

  // See if we need to open a certain tab
	if ( String(document.location.href).indexOf('#tab2')>=0)
	{
		myAccordion.display(1);		
	}
	else if (String(document.location.href).indexOf('#tab3')>=0)
	{
		myAccordion.display(2);		
	}
	else if(String(document.location.href).indexOf('#tab4')>=0)
	{
		myAccordion.display(3);
	}
	else if(String(document.location.href).indexOf('#tab5')>=0)
	{
		myAccordion.display(3);
	}
	else if(String(document.location.href).indexOf('#tab6')>=0)
	{
		myAccordion.display(3);
	}

});

	

