window.addEvent('domready', function() {
	new OverText($$('.overText'));
	if ($('dropdown1_content')) var myDropdown1 = new Fx.Slide('dropdown1_content').hide();
	if ($('dropdown2_content')) var myDropdown2 = new Fx.Slide('dropdown2_content').hide();
	if ($('dropdown3_content')) var myDropdown3 = new Fx.Slide('dropdown3_content').hide();
	if ($('dropdowncontainer')) $('dropdowncontainer').setStyle('display', '');

	// dropdown myaccount
	if ($('dropdown1_label')) {
		$('dropdown1_label').addEvent('click', function(e) {
			if (e) {
				e.stop();
			}
			if ($('dropdown2_content')) myDropdown2.hide();
			if ($('dropdown3_content')) myDropdown3.hide();
			$('content').addClass('dropdown-opened');
			myDropdown1.toggle();
		});
		$('dropdown1_content').addEvent('mouseleave', function(e) {
			if (e) {
				e.stop();
			}
			myDropdown1.slideOut();
		});
		myDropdown1.addEvent('complete', function() {
			if (myDropdown1.open) {
				$('dropdown1').setStyle('background-image', 'url(assets/etc/img/bg_dropdown_open.gif)');
				//Loginbox befuellen
				OverText.update();
			} else {
				$('dropdown1').setStyle('background-image', 'url(assets/etc/img/bg_dropdown.gif)');
				$('content').removeClass('dropdown-opened');
			}
		});
	}

	// dropdown events
	if ($('dropdown2_label')) {
		$('dropdown2_label').addEvent('click', function(e) {
			if (e) {
				e.stop();
			}
			if ($('dropdown1_content')) myDropdown1.hide();
			if ($('dropdown3_content')) myDropdown3.hide();
			$('content').addClass('dropdown-opened');
			myDropdown2.toggle();
		});
		$('dropdown2_content').addEvent('mouseleave', function(e) {
			if (e) {
				e.stop();
			}
			myDropdown2.slideOut();
		});
		myDropdown2.addEvent('complete', function() {
			if (myDropdown2.open) {
				$('dropdown2').setStyle('background-image', 'url(assets/etc/img/bg_dropdown_open.gif)');
			} else {
				$('dropdown2').setStyle('background-image', 'url(assets/etc/img/bg_dropdown.gif)');
				$('content').removeClass('dropdown-opened');
			}
		});
	}

	// dropdown recommend
	if ($('dropdown3_label')) {
		$('dropdown3_label').addEvent('click', function(e) {
			if (e) {
				e.stop();
			}
			if ($('dropdown1_content')) myDropdown1.hide();
			if ($('dropdown2_content')) myDropdown2.hide();
			$('content').addClass('dropdown-opened');
			myDropdown3.toggle();
		});
		$('dropdown3_content').addEvent('mouseleave', function(e) {
			if (e) {
				e.stop();
			}
			myDropdown3.slideOut();
		});
		myDropdown3.addEvent('complete', function() {
			if (myDropdown3.open) {
				$('dropdown3').setStyle('background-image', 'url(assets/etc/img/bg_dropdown_open.gif)');
			} else {
				$('dropdown3').setStyle('background-image', 'url(assets/etc/img/bg_dropdown.gif)');
				$('content').removeClass('dropdown-opened');
			}
		});
	}

	if ($('langswitch')) {
		// tween langswitch
		var iLangSwitchWidthClose = parseInt($('langswitch').style.width);
		var iLangSwitchWidthOpen  = iLangSwitchWidthClose + (($('langswitch').getElements('a').length - 1) * 54);
		var iLangSwitchWidthTo    = iLangSwitchWidthClose;
		var fLangSwitchWidth      = function(e){location.href=this.href;};
		$('langswitch').addEvent('click', function() {
			if (iLangSwitchWidthTo == iLangSwitchWidthClose) {
				iLangSwitchWidthTo = iLangSwitchWidthOpen;
				$('langswitch_ie8').setStyle('display', 'none');
			} else {
				iLangSwitchWidthTo = iLangSwitchWidthClose;
			}
			$('langswitch').tween('width', iLangSwitchWidthTo);
			if (iLangSwitchWidthTo == iLangSwitchWidthOpen) {
				(function(){$('langswitch').getElements('span[class=inactive]').setStyle('display', 'block');}).delay(300);
				$('langswitch').getElements('a').addEvent('click', fLangSwitchWidth)
			} else {
				$('langswitch').getElements('span[class=inactive]').setStyle('display', 'none');
				$('langswitch').getElements('a').removeEvent('click', fLangSwitchWidth);
				(function(){$('langswitch_ie8').setStyle('display', '');}).delay(500);
			}
			return false;
		});
	}
});

// IE6 scroll fix
window.addEvent('load', function() {
	if ($('contentcontainer') && navigator.userAgent.toLowerCase().substr(25,6) == "msie 6") {
		$('contentcontainer').onscroll = function () {
			var scroll = $('contentcontainer').getScroll();
			if (scroll.y > 21) {
				$('dropdown3').setStyle('display', 'none');
				if (scroll.y > 52) {
					$('dropdown2').setStyle('display', 'none');
					if (scroll.y > 83) {
						$('dropdown1').setStyle('display', 'none');
					} else {
						$('dropdown1').setStyle('display', '');
					}
				} else {
					$('dropdown2').setStyle('display', '');
				}
			} else {
				$('dropdown3').setStyle('display', '');
			}
		}
	}
});

// switch sort dropdown 2
function switchalphachron(sTypeTo) {
	if (sTypeTo == 'chron') {
		$('fairschron').setStyle('display','');
		$('fairsalpha').setStyle('display','none');
		$('linkfairschron').setStyle('display','');
		$('linkfairsalpha').setStyle('display','none');
	}
	if (sTypeTo == 'alpha') {
		$('fairsalpha').setStyle('display','');
		$('fairschron').setStyle('display','none');
		$('linkfairsalpha').setStyle('display','');
		$('linkfairschron').setStyle('display','none');
	}
	Cookie.write('bSortFairs', sTypeTo);
}
window.addEvent('domready', function(){ if (Cookie.read('bSortFairs') == 'alpha') switchalphachron('alpha'); })

// topnav hover (f*** IE6)
function topnavcolor(myElement, myColor, job) {
	if (job == 'set') {
		var colorpath = 'img';
		if (myColor.length != 0) colorpath = 'rgb/' + myColor;
		$(myElement).setStyle('background-image', 'url(assets/etc/' + colorpath + '/topnav_active.png)');
		$(myElement).getElement('a').setStyle('color', '#ffffff');
	}
	if (job == 'rm') {
		$(myElement).setStyle('background-image', 'url(assets/etc/img/topnav_inactive.gif)');
		$(myElement).getElement('a').setStyle('color', '#50555f');
	}
}

// font size
var iMinFontSize =  9;
var iNowFontSize = 11;
var iMaxFontSize = 14;
var iUsrFontSize = parseInt(Cookie.read('iUsrFontSize'));
var bUsrFontHint = true;
function resizemytext(sUpDown, sDirectSize) {
	iNowFontSize = parseInt(iNowFontSize);
	sDirectSize = parseInt(sDirectSize);
	if (!sDirectSize && sUpDown == 'up') {
		iNowFontSize = iNowFontSize + 1;
	} else if (!sDirectSize && sUpDown == 'down') {
		iNowFontSize = iNowFontSize - 1;
	} else if (sDirectSize) {
		iNowFontSize = sDirectSize;
	}
	if (iNowFontSize > iMaxFontSize) {
		iNowFontSize = iMaxFontSize;
	} else if (iNowFontSize < iMinFontSize) {
		iNowFontSize = iMinFontSize;
	} else {
		$$('body').setStyle('font-size', iNowFontSize.toString() + 'px');
		var iToday = new Date();
		var sNextYear = new Date(iToday.getYear() + 1, iToday.getMonth(), iToday.getDate());
		Cookie.write('iUsrFontSize', iNowFontSize);
		iCheck = parseInt(Cookie.read('iUsrFontSize'));
		if (iCheck != iNowFontSize && bUsrFontHint) {
			alert("Dear User,\n\nwe are unable to remember Your prefered font size,\nbecause we are not allowed to store it in a cookie.");
			bUsrFontHint = false;
		}
	}
}
window.addEvent('domready', function(){ if (iUsrFontSize) resizemytext('', iUsrFontSize); })

function toggleLoginbox() {
	if ($('footerlinks').getStyle('display') == 'block') {
		var tweenFx1 = new Fx.Tween('footerlinks', {property: 'opacity', duration: 'short'});
		tweenFx1.start(1,0).chain(function() {
			$('footerlinks').setStyle('display', 'none');
			$('footerlogin').setStyle('display', 'block');
			var tweenFx2 = new Fx.Tween('footerlogin', {property: 'opacity', duration: 'short'});
			tweenFx2.start(0,1)
			OverText.update();
		});
	} else {
		var tweenFx1 = new Fx.Tween('footerlogin', {property: 'opacity', duration: 'short'});
		tweenFx1.start(1,0).chain(function() {
			$('footerlogin').setStyle('display', 'none');
			$('footerlinks').setStyle('display', 'block');
			var tweenFx2 = new Fx.Tween('footerlinks', {property: 'opacity', duration: 'short'});
			tweenFx2.start(0,1)
		});
	}
}

function toggleFields(oShow, oHide, focus) {
	$(oShow).removeClass('hidden');
	$(oHide).addClass('hidden');

	if (focus == true) {
		$(oShow).focus();
	}
}

