/***********************************************************/
/* This is rollovered menu which contains all categories   */
/* It uses accordion effect                                */ 
/***********************************************************/


function init_accordion (id) {
	if(window.ie6) var heightValue='100%';
	else var heightValue='';
	var active = -1;
	id.each (function (item, index) {

       var i = -1;
	   
       $('accordion').getElements('.t'+item).each (function (item, index) {
          var class_name = (item.getProperty('class')).split(' ');
          if (class_name[0] == 'active') {
               i = index;
           }
       });


		new Accordion ('.t'+item, '.c'+item, {
			opacity: false,
			display: i,
			alwaysHide: true,
			link: 'cancel',
			initialDisplayFx: true,
			onComplete: function() {
			 	var element=$(this.elements[this.previous]);
			 	if(element && element.offsetHeight>0) element.setStyle('height', heightValue);
			}
		});
	});
	
	$$('.toggler').each(function(el, index){

		el.set('morph', {
			duration: 500,
			transition: Fx.Transitions.Cubic.easeOut,
			fps: 25
		});
		el.addEvents({
				'mouseover':function()
				{
					if (active != index || this.get('tag') == 'a') {
						this.morph('.togglerHover');
						this.store('active', '1');
					}
				},
				'mouseout':function() {	
					if (active != index || this.get('tag') == 'a') {
				        var class_name = (this.getProperty('class')).split(' ');
          				if (class_name[0] != 'active') {
							this.store('active', '0');
							my_mouseout.bind(this).delay(150);
						}						
					}
				}
		});
		
		
		el.addEvent('click', function () {
			if (!Browser.ie)
			if( this.hasClass('parent'))
				if (this.hasClass('active')) {
					//$$('.toggler').setStyle('background-position', 'top');
					//this.setStyle('background-position', 'center top');
					this.removeClass('active');
					$$('.toggler').removeClass('active');
				}
				else {
					//$$('.toggler').setStyle('background-position', 'top');
					//this.setStyle('background-position', 'center bottom');
					$$('.toggler').removeClass('active');
					this.addClass('active');
				}
			
			var back = false;
			try {
				while(el) {
					if (el == $$('.toggler')[active]) {
						back = true;
						break;
					}
					el = el.getParent().getPrevious('.toggler');
				}
						
			} catch (e) {}
			
			if (!back && $$('.toggler')[index].get('tag') != 'a') {
					var el_off = $$('.toggler')[active];

					while(el_off) {
					
						if (el_off.retrieve('active') == '1') {
							el_off.store('active', '0');
							my_mouseout.bind(el_off).delay(200);
						} else if (el_off.retrieve('active') == '0' && active  == index){
							el_off.store('active', '1');
							el_off.morph('.togglerHover');
						}
						
						el_off = el_off.getParent().getPrevious('.toggler');
					}

			
			} 
			if (this.get('tag') != 'a') {
				active = index;
			}
		});
		

	});
	
	$$('.link').each (function (el) {
		el.setStyle('display', 'block');
	})
	
	
	my_mouseout = function () {
		this.morph('.togglerUnhover');
	};
}
