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 && el.getElement(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 YOOBackgroundFx = new Class({
	initialize: function (options) {
		this.setOptions({
			transition: Fx.Transitions.linear,
			duration: 9000,
			wait: false,
			colors: ['#FFFFFF', '#999999']
		},
		options);
		var body = new Element(document.body);
		var fx = body.effects(this.options);
		var index = 0;
		var colors = this.options.colors;
		var timer = animate.periodical(this.options.duration * 2);
		animate();
		function animate() {
			fx.start({
				'background-color': colors[index]
			});
			if (index + 1 >= colors.length) {
				index = 0
			} else {
				index++
			}
		}
	}
});
YOOBackgroundFx.implement(new Options);
