var YOOBase={matchDivHeight:function(selector,divBorder,minWidth){var maxHeight=0;var matchDivs=[];var selectors=selector.split(" ");var elements=selectors.shift();var script='';selectors.each(function(el,i){script+='.getElement("'+el+'")'});$ES(elements).each(function(element,i){eval('matchDivs.push(element'+script+');')});matchDivs.each(function(div,i){if(!$chk(div))return;var divHeight,divPadding;if(div.offsetHeight){divHeight=div.offsetHeight;divPadding=0;divPadding+=div.getStyle('padding-top').toInt();divPadding+=div.getStyle('padding-bottom').toInt();divHeight-=divPadding;if(divBorder!=undefined){divHeight-=divBorder}}else if(div.style.pixelHeight){divHeight=div.style.pixelHeight}maxHeight=Math.max(maxHeight,divHeight)});if(minWidth!=undefined){maxHeight=Math.max(maxHeight,minWidth)}matchDivs.each(function(div,i){if(!$chk(div))return;if(window.ie6){div.setStyle('height',maxHeight+'px')}else{div.setStyle('min-height',maxHeight+'px')}})}};var YOOStyleSwitcher=new Class({initialize:function(wrappers,options){this.setOptions({widthDefault:'width-wide',widthThinPx:780,widthWidePx:940,widthFluidPx:0.9,transition:Fx.Transitions.quadOut,duration:500,afterSwitch:Class.empty},options);this.fontSmall='font-small',this.fontMedium='font-medium',this.fontLarge='font-large',this.widthThin='width-thin';this.widthWide='width-wide';this.widthFluid='width-fluid';this.wrappers=$$(wrappers);this.htmlbody=new Element(document.body);this.addEvent('afterSwitch',this.options.afterSwitch);this.widthStyle='';var obj=this;var switchWidthThin=$E('#switchwidththin');var switchWidthWide=$E('#switchwidthwide');var switchWidthFluid=$E('#switchwidthfluid');var switchFontSmall=$E('#switchfontsmall');var switchFontMedium=$E('#switchfontmedium');var switchFontLarge=$E('#switchfontlarge');if(switchWidthThin)switchWidthThin.addEvent('click',function(){obj.widthSwitch(obj.widthThin)});if(switchWidthWide)switchWidthWide.addEvent('click',function(){obj.widthSwitch(obj.widthWide)});if(switchWidthFluid)switchWidthFluid.addEvent('click',function(){obj.widthSwitch(obj.widthFluid)});if(switchFontSmall)switchFontSmall.addEvent('click',function(){obj.fontSwitch(obj.fontSmall)});if(switchFontMedium)switchFontMedium.addEvent('click',function(){obj.fontSwitch(obj.fontMedium)});if(switchFontLarge)switchFontLarge.addEvent('click',function(){obj.fontSwitch(obj.fontLarge)})},fontSwitch:function(font){var obj=this;var fonts=[this.fontSmall,this.fontMedium,this.fontLarge];fonts.each(function(currentFont,i){if(currentFont==font){obj.htmlbody.addClass(font)}else{obj.htmlbody.removeClass(currentFont)}});Cookie.set('ytstylefont',font,{path:'/'});this.fireEvent('afterSwitch')},widthSwitch:function(width){var obj=this;var curWidth=this.getWidthPx(Cookie.get('ytstylewidth')||this.options.widthDefault);var newWidth=this.getWidthPx(width);Cookie.set('ytstylewidth',width,{path:'/'});this.wrappers.each(function(wrapper,i){var fx=wrapper.effect('width',obj.options);fx.addEvent('onComplete',obj.widthSwitchComplete).addEvent('onComplete',obj.options.afterSwitch);fx.start(curWidth,newWidth)})},widthSwitchComplete:function(){var obj=this;var widthStyle=Cookie.get('ytstylewidth')||this.options.widthDefault;if(widthStyle==this.widthFluid){this.wrappers.each(function(wrapper,i){wrapper.setStyle('width',(obj.options.widthFluidPx*100)+'%')})}},getWidthPx:function(width){if(width==this.widthThin)return this.options.widthThinPx;if(width==this.widthFluid)return parseInt((Window.getWidth())*this.options.widthFluidPx);return this.options.widthWidePx}});YOOStyleSwitcher.implement(new Events);YOOStyleSwitcher.implement(new Options);var YOOMorph=new Class({initialize:function(element,enter,leave,enterFx,leaveFx,elementFx){this.setOptions({duration:500,transition:Fx.Transitions.expoOut,wait:false,ignoreClass:''},enterFx);var options=this.options;$$(element).each(function(el,i){var elfx=el;if(elementFx){elfx=el.getElement(elementFx)}var fx=new Fx.Styles(elfx,options);if(!($chk(options.ignoreClass)&&el.hasClass(options.ignoreClass))){el.addEvent('mouseenter',function(e){fx.setOptions(options,enterFx).start(enter)});el.addEvent('mouseleave',function(e){fx.setOptions(options,leaveFx).start(leave)})}})}});YOOMorph.implement(new Options); 

var YOOAccordionMenu=new Class({initialize:function(togglers,elements,options){this.setOptions({accordion:'default'},options);this.togs=togglers;this.elms=elements;switch(this.options.accordion){case'slide':this.createSlide();break;default:this.createDefault()}},createDefault:function(){var options={};if(!$defined(this.options.display)){options={show:-1}}$ES(this.togs).each(function(tog,i){if(tog.hasClass('active'))options={show:i}}.bind(this));var accordionMenu=new Fx.Accordion(this.togs,this.elms,$extend(this.options,options))},createSlide:function(){$ES(this.togs).each(function(tog,i){var span=tog.getElement('span');var ul=tog.getElement(this.elms);var fx=new Fx.Slide(ul,{transition:Fx.Transitions.linear,duration:250});if(!(tog.hasClass('active')||this.options.display=='all'||this.options.display==i)){fx.hide()}span.addEvent('click',function(){fx.toggle()})}.bind(this))}});YOOAccordionMenu.implement(new Options); 

var YOOFancyMenu=new Class({initialize:function(menu,options){this.setOptions({transition:Fx.Transitions.sineInOut,duration:500,wait:false,onClick:Class.empty,opacity:1,mode:'move',slideOffset:30,itemSelector:'li.level1',activeSelector:'li.active'},options);this.menu=$(menu),this.current=this.menu.getElement(this.options.activeSelector);this.li=[];this.div=[];this.menu.getElements(this.options.itemSelector).each(function(item,i){this.createBackground(item,i);item.addEvent('click',function(event){this.clickItem(event,item)}.bind(this));item.addEvent('mouseenter',function(){this.mouseenterItem(item,i)}.bind(this));if(this.options.mode=='move'){item.addEvent('mouseleave',function(){this.mouseleaveItem(this.current,i)}.bind(this))}else{item.addEvent('mouseleave',function(){this.mouseleaveItem(item,i)}.bind(this))}}.bind(this));if(this.options.mode=='move'){if(this.current){this.setCurrent(this.current)}else{var first=this.menu.getElement('li');first.addClass('active');first.addClass('current');this.setCurrent(first)}}},createBackground:function(item,i){if(this.options.mode=='move'&&i!=0)return;this.div[i]=new Element('div',{'class':'fancy-container'}).adopt(new Element('div',{'class':'fancy-l'}),new Element('div',{'class':'fancy-m'}),new Element('div',{'class':'fancy-r'}));this.div[i].fx=this.div[i].effects(this.options);this.li[i]=new Element('li',{'class':'fancy '+'bg'+(i+1)}).adopt(this.div[i]).injectInside(this.menu);this.li[i].fx=this.li[i].effects(this.options)},setCurrent:function(item){this.li[0].setStyles({'left':item.offsetLeft,'width':item.offsetWidth,'visibility':'visible','opacity':this.options.opacity});this.current=item},clickItem:function(event,item){if(!this.current)this.setCurrent(item);this.current=item;this.options.onClick(new Event(event),item)},mouseenterItem:function(item,i){switch(this.options.mode){case'fade':this.fadeFx(item,i,true);break;case'slide':this.slideFx(item,i,true);break;default:this.moveFx(item,0)}},mouseleaveItem:function(item,i){switch(this.options.mode){case'fade':this.fadeFx(item,i,false);break;case'slide':this.slideFx(item,i,false);break;default:this.moveFx(item,0)}},moveFx:function(item,i){if(!this.current)return;this.li[i].fx.custom({'left':[this.li[i].offsetLeft,item.offsetLeft],'width':[this.li[i].offsetWidth,item.offsetWidth]})},fadeFx:function(item,i,show){if(show){this.li[i].fx.setOptions(this.options);this.li[i].fx.set({'left':item.offsetLeft,'width':item.offsetWidth});this.li[i].fx.custom({'opacity':[0,1]})}else{var dur=this.options.duration*2;this.li[i].fx.setOptions({duration:dur});this.li[i].fx.custom({'opacity':[1,0]})}},slideFx:function(item,i,show){var offset=this.options.slideOffset;if(show){this.li[i].fx.set({'opacity':1,'left':item.offsetLeft,'width':item.offsetWidth});this.div[i].fx.set({'margin-top':offset});this.div[i].fx.custom({'margin-top':[offset,0]})}else{this.div[i].fx.set({'margin-top':0});this.div[i].fx.custom({'margin-top':[0,offset]})}}});YOOFancyMenu.implement(new Options); 

var YOODropdownMenu=new Class({initialize:function(element,options){this.setOptions({mode:'default',duration:600,transition:Fx.Transitions.linear,wait:false},options);var reset={'width':0,'height':0,'opacity':0};switch(this.options.mode){case'width':reset={'width':0,'opacity':0};break;case'height':reset={'height':0,'opacity':0};break}$$(element).each(function(li){var ul=li.getElement('ul');if(ul){var fx=new Fx.Styles(ul,this.options);var styles=ul.getStyles('width','height','opacity');ul.setStyles(reset);li.addEvents({mouseenter:function(){var parent=li.getParent();if(parent.getStyle('overflow')=='hidden')parent.setStyle('overflow','visible');fx.element.setStyle('overflow','hidden');fx.start(styles)},mouseleave:function(){fx.stop();ul.setStyles(reset)}})}}.bind(this))}});YOODropdownMenu.implement(new Options); 

var YOOTools = {
		
	start: function() {
		
		/* Match height of div tags */
	

		/* Accordion menu */
		new YOOAccordionMenu('div#middle ul.menu li.toggler', 'ul.accordion', { accordion: 'slide' });

		/* Fancy menu */
		

		/* Dropdown menu */
		new YOODropdownMenu('div#menu li.parent', { mode: 'height', transition: Fx.Transitions.Expo.easeOut });

		/* Main menu (tab) color settings */
		var currentColor = '#323232';
		var leaveColor = '#ffffff';

		var menuEnter = { 'color': currentColor };
		var menuLeave = { 'color': leaveColor };
		
		new YOOMorph('div#menu li.level1', menuEnter, menuLeave,
			{ transition: Fx.Transitions.expoOut, duration: 300, ignoreClass: 'active' },
			{ transition: Fx.Transitions.sineIn, duration: 200 }, '.level1');
		
		/* Main menu (sub) color settings */
		var currentColor = '#DCDDDE';
		var leaveColor = '#FEFEFE';

		var menuEnter = { 'background-color': currentColor };
		var menuLeave = { 'background-color': leaveColor };
		
		new YOOMorph('div#menu li.level2 a, div#menu li.level2 span.separator', menuEnter, menuLeave,
			{ transition: Fx.Transitions.expoOut, duration: 300 },
			{ transition: Fx.Transitions.sineIn, duration: 500 });

		/* Sub menu color settings */
		/* color default */
		var currentColor = '#e6e7e8';
		var leaveColor = '#FEFEFE';
		
		/* Sub menu all levels */
		var submenuEnter = { 'background-color': currentColor};
		var submenuLeave = { 'background-color': leaveColor};

		new YOOMorph('div#middle ul.menu a, div#middle ul.menu span.separator', submenuEnter, submenuLeave,
			{ transition: Fx.Transitions.expoOut, duration: 300 },
			{ transition: Fx.Transitions.sineIn, duration: 500 });

		/* Style switcher */

		
		/* Smoothscroll */
		new SmoothScroll({ duration: 500, transition: Fx.Transitions.Expo.easeOut });
	},

	/* Include script */
	include: function(library) {
		$ES('script').each(function(s, i){
			var src  = s.getProperty('src');
			var path = '';
			if (src && src.match(/yoo_tools\.js(\?.*)?$/)) path = src.replace(/yoo_tools\.js(\?.*)?$/,'');
			if (src && src.match(/template\.js\.php(\?.*)?$/)) path = src.replace(/template\.js\.php(\?.*)?$/,'');
			if (path != '') document.write('<script language="javascript" src="' + path + library + '" type="text/javascript"></script>');
		});
	},

	/* Match height of div tags */
	setDivHeight: function() {

	}

};

/* Add functions on window load */
window.addEvent('domready', YOOTools.start);

/* Load IE6 fix */
if (window.ie6) {
	YOOTools.include('addons/ie6fix.js');
	YOOTools.include('yoo_ie6fix.js');
}
