/* main.js */

/* Author: Sascha Meier \ */
/* LastChangedDate: 2009-06-17 \ */
/* LastChangedBy: MZ \ */

function onLoadFunctions() {
	// add function calls here
	navHover();
	initHovers("ul", "date");
	initHovers("ul", "type");
	initHovers("ul", "destination");
	initPrint();
	initFontStepper();
	animateHover();
}
if (window.addEventListener) {
	window.addEventListener("load", onLoadFunctions, true);
} else if (window.attachEvent) {
	window.attachEvent("onload", onLoadFunctions);
}

// initialize print function
function initPrint() {
	// show print Link
	var print = document.getElementById("print");
	if (print) {
		print.style.visibility = "visible";

		// set print button events
		print.href = "javascript:window.print();"
	}
}

function animateHover() {

		var totalMenuWidth = $('div#topNavi').outerWidth();	

			
		
		var showTimeout1;
		var hideTimeout1;
		$('ul#Navigation li#nav1').hover(function () {
			clearTimeout(hideTimeout1);
			showTimeout1 = setTimeout(function() {$('ul#Navigation li#nav1 div').show(100);},200);
		},
		function() {
			clearTimeout(showTimeout1);
			hideTimeout1 = setTimeout(function(){$('ul#Navigation li#nav1 div').hide(100);},200);
		});

		var showTimeout2;
		var hideTimeout2;
		$('ul#Navigation li#nav2').hover(function () {
			clearTimeout(hideTimeout2);
			showTimeout2 = setTimeout(function() {$('ul#Navigation li#nav2 div').show(100);},200);
		},
		function() {
			clearTimeout(showTimeout2);
			hideTimeout2 = setTimeout(function(){$('ul#Navigation li#nav2 div').hide(100);},200);
		});
		
		var showTimeout3;
		var hideTimeout3;
		$('ul#Navigation li#nav3').hover(function () {
			clearTimeout(hideTimeout3);
			showTimeout3 = setTimeout(function() {$('ul#Navigation li#nav3 div').show(100);},200);
		},
		function() {
			clearTimeout(showTimeout3);
			hideTimeout3 = setTimeout(function(){$('ul#Navigation li#nav3 div').hide(100);},200);
		});
		
		var showTimeout4;	
		var hideTimeout4;
		$('ul#Navigation li#nav4').hover(function () {
			clearTimeout(hideTimeout4);
			showTimeout4 = setTimeout(showNav4,200);	
		},
		function() {
			clearTimeout(showTimeout4);
			hideTimeout4 = setTimeout(function(){$('ul#Navigation li#nav4 div').hide(100);},200);
		});
		
		var showTimeout5;	
		var hideTimeout5;
		$('ul#Navigation li#nav5').hover(function () {
			clearTimeout(hideTimeout5);
			showTimeout5 = setTimeout(showNav5,200);	
		},
		function() {
			clearTimeout(showTimeout5);
			hideTimeout5 = setTimeout(function(){$('ul#Navigation li#nav5 div').hide(100);},200);
		});
		
		var showTimeout6;	
		var hideTimeout6;
		$('ul#Navigation li#nav6').hover(function () {
			clearTimeout(hideTimeout6);
			showTimeout6 = setTimeout(showNav6,200);	
		},
		function() {
			clearTimeout(showTimeout6);
			hideTimeout6 = setTimeout(function(){$('ul#Navigation li#nav6 div').hide(100);},200);
		});
		
		var showTimeout7;	
		var hideTimeout7;
		$('ul#Navigation li#nav7').hover(function () {
			clearTimeout(hideTimeout7);
			showTimeout7 = setTimeout(showNav7,200);	
		},
		function() {
			clearTimeout(showTimeout7);
			hideTimeout7 = setTimeout(function(){$('ul#Navigation li#nav7 div').hide(100);},200);
		});
}

function showNav4() {
	$('ul#Navigation li#nav4 div').show();
	var totalMenuWidth = $('div#topNavi').outerWidth();
	var nav4 = $('ul#Navigation li#nav4 div'); 
	var nav4li = $('ul#Navigation li#nav4 div ul'); 
	var nav4Width = nav4li.outerWidth();
	var leftPos = totalMenuWidth - nav4Width; 
	nav4.css('position','absolute'); 
	nav4.css('left',leftPos);
}

function showNav5() {
	$('ul#Navigation li#nav5 div').show();
	var totalMenuWidth = $('div#topNavi').outerWidth();
	var nav5 = $('ul#Navigation li#nav5 div'); 
	var nav5li = $('ul#Navigation li#nav5 div ul'); 
	var nav5Width = nav5li.outerWidth();
	var leftPos = totalMenuWidth - nav5Width; 
	nav5.css('position','absolute'); 
	nav5.css('left',leftPos);
}

function showNav6() {
	$('ul#Navigation li#nav6 div').show();
	var totalMenuWidth = $('div#topNavi').outerWidth();
	var nav6 = $('ul#Navigation li#nav6 div'); 
	var nav6li = $('ul#Navigation li#nav6 div ul'); 
	var nav6Width = nav6li.outerWidth();
	var leftPos = totalMenuWidth - nav6Width; 
	nav6.css('position','absolute'); 
	nav6.css('left',leftPos);
}

function showNav7() {
	$('ul#Navigation li#nav7 div').show();
	var totalMenuWidth = $('div#topNavi').outerWidth();
	var nav7 = $('ul#Navigation li#nav7 div'); 
	var nav7li = $('ul#Navigation li#nav7 div ul'); 
	var nav7Width = nav7li.outerWidth();
	var leftPos = totalMenuWidth - nav7Width; 
	nav7.css('position','absolute'); 
	nav7.css('left',leftPos);
}



// initialize font stepper
function initFontStepper() {
	// show font stepper
	if (document.getElementById("fontStepper")) {
		document.getElementById("fontStepper").style.visibility = "visible";

		// set font stepper button events
		document.getElementById("fontdec").href = "javascript:fontStepper(-1, false);"
		document.getElementById("fontinc").href = "javascript:fontStepper(1, false);"

		// get cookie value and set font stepper
		/*
		 * var stepValue = parseInt(getCookieValue()); if (stepValue < 0) { stepValue = stepValue*(-1); for (var i=0; i<stepValue;
		 * i++) { fontStepper(-1, false); } } else { for (var i=0; i<stepValue; i++) { fontStepper(1, false); } }
		 */
	}
}

/*
 * function getCookieValue() { value1 = ""; if(document.cookie) { value1 = document.cookie; value1 =
 * value1.slice(value1.indexOf("=")+1,value1.length); } return value1; }
 */

/* font stepper */
var spEmStepWidth = 0.125; // increase/decrease font every step by
// spEmStepWidth
var spEmBasis = 1.125; // font size of spArticleBody at startup
var spEmStep = -1; // counter for current step (leave as 0)
var spEmMaxSteps = 2; // maximum steps alowed

function fontStepper(spInc, spReset) {
	// reset font size
	if (spReset)
		spEmStep = -1;
	// inside allowed steps?
	if (Math.abs(spEmStep + spInc) <= spEmMaxSteps) {
		// increase/decrease spEmStep
		spEmStep += spInc;
		// set new font size for every tag inside "spEmStep"
		spEmFontSize = spEmStep * spEmStepWidth + spEmBasis;
		// get spArticleBody
		spEmBody = document.getElementById('volume');
		// set new fot size
		spEmBody.style.fontSize = spEmFontSize + "em";
		// spEmBody.style.lineHeight = spEmFontSize+0.54 + "em";
		// save value in cookie
		step = spEmStep + 1;
		document.cookie = 'spEmStep=' + step + ';path=/;';
	}
}

/* Bookmark functionality */

/* show navi items (ie 6) */
navHover = function() {
	var nav = document.getElementById("Navigation");
	if (nav) {
		var lis = document.getElementById("Navigation").getElementsByTagName(
				"LI");
		for ( var i = 0; i < lis.length; i++) {
			/* find Submenuitems for all browsers except ie */
			if (navigator.appName != "Microsoft Internet Explorer") {
				if (lis[i].fistchild != null
						&& lis[i].firstChild.parentNode.lastChild.tagName != "A") {
					lis[i].firstChild.className += " hasSub";
				}
			}
			/* find Submenuitems for ie */
			else if (lis[i].lastChild != null 
					&& lis[i].lastChild.tagName == "UL") {
				if (lis[i].firstChild != null
						&& lis[i].firstChild.tagName == "A") {
					lis[i].firstChild.className += " hasSub";
				}
			}

			var curentClass = '';

			lis[i].onmouseover = function() {
				curentClass = this.className;
				this.className += " iehover";
			}
			lis[i].onmouseout = function() {
				this.className = curentClass;
			}
			lis[i].onfocus = function() {
				curentClass = this.className;
				this.className = " iehover";
			}
			lis[i].onblur = function() {
				this.className = curentClass;
			}
		}
	}
}

// initialize hovers
function initHovers(tag, IdName) {
	// set hover
	var lis = document.getElementsByTagName(tag);
	for ( var i = 0; i < lis.length; i++) {
		if (lis[i].id == IdName) {
			lis[i].onmouseover = function() {
				this.className = this.id + "Hover";
			}
			lis[i].onmouseout = function() {
				this.className = "";
			}
		} else if (!IdName) {
			if (lis[i].className) {
				lis[i].classNames = lis[i].className.split(" ");
				if (lis[i].classNames.length > 0) {
					lis[i].classes = "";
					for ( var z = 0; z < lis[i].classNames.length; z++) {
						lis[i].classes += " " + lis[i].classNames[z];
					}

				}

				lis[i].onmouseover = function() {
					this.className = this.classes + " " + this.classNames[0]
							+ "Hover";
				}
				lis[i].onmouseout = function() {
					this.className = this.classes;
				}
				lis[i].onfocus = function() {
					this.className = this.classes + " " + this.classNames[0]
							+ "Hover";
				}
				lis[i].onblur = function() {
					this.className = this.classes;
				}
			}
		}
	}
}

