// JavaScript Document


// sets the value of the search-field to '' with focus or to 'Suchbegriff eingeben' without focus
function setSearchValue(status){
	var text = "Suchbegriff eingeben"
	var id = document.getElementById('search-field');
	if ((status == 'focus') && id.value == text) {
		id.value = '';			
	} else if (id.value == ''){
		id.value = text;
	}
}

// changes the visibility of an element	
function visibility(box, visible){
	var id = document.getElementById(box);
	if(visible == true){
		id.className = 'show';
	}else{
		id.className = 'hide';
	}
}

function hideKitaPopup() {
	if (lastKita != null) {
		window.clearTimeout(timerKita);
		lastKita.className = 'hide'; // hide previously opened popup
	}	
}
//changes the visibility of an element for kita image map
var timerKita = null;
var lastKita = null;
var kitaTimeout = 3000;
function showKitaPopup(box, x, y) {
	hideKitaPopup();
	var id = document.getElementById(box);
	id.style.top = y + 'px';
	id.style.left = x + 'px';
	id.className = 'show';
	lastKita = id; // store reference to popup
	timerKita = window.setTimeout('hideKitaPopup();', kitaTimeout); // start timer
}


var bodyId;

function init(){
		
}

//changes the font-size
var count = 0;


function changeSize(){
	bodyId = document.getElementById('body');

	switch(this.count){
		case 0:	this.bodyId.className = 'large';
				this.count++;
				break;
				
		case 1:	this.bodyId.className = 'huge';
				this.count++;
				break;
				
		case 2:	this.bodyId.className = 'normal';
				this.count = 0;
				break;		
	}		
}










//float menu and quick navi

var timerQn = null;
var qnTimeout = 2500;

function showQn() {
  $("#quick-navi-display").fadeTo(0, 0.01).removeClass("hide").addClass("show");
  $("#quick-navi").fadeTo(1500, 0.01);
  $("#quick-navi-display").fadeTo(1000, 1);
}

function hideQn() {
  $("#quick-navi-display").fadeTo(1500, 0.01);
  $("#quick-navi").fadeTo(1000, 1);
  $("#quick-navi-display").removeClass("show").addClass("hide");
}

//$.fn.wait = function(time, type) {
//  time = time || 1000;
//  type = type || "fx";
//  return this.queue(type, function() {
//    var self = this;
//    setTimeout(function() {
//      $(self).dequeue();
//    }, time);
//  });
//};

$(document).ready(function(){
	
	
	// kita popup 
	$("#KITA-Map div").hover(
		function() { window.clearTimeout(timerKita); }, // stop timer
		function() { timerKita = window.setTimeout('hideKitaPopup();', kitaTimeout); } // restart timer
	);	
	
	
  //quick navi
  $("div").click(function () {
    if (this.id == "quick-navi") {
      showQn();
    }
    if (this.id == "quick-navi-display") {
      hideQn();
    }
  });
//  $("div").hover(
//	function() {  
//		if (this.id == "quick-navi") { // open qn
//			showQn();
//			window.clearTimeout(timerQn);
//		} // stop timer
//		if (this.id == "quick-navi-display") { 
//			window.clearTimeout(timerQn);
//		} 
//	}, 
//	function() { // restart timer
//		if (this.id == "quick-navi-display") { 
//			timerQn = window.setTimeout('hideQn();', qnTimeout);
//		}
//	}
//  );	

  
	var prevMain = '';
	var prevMenu = '';
	var defaultTimeout = 500;

	
	$("#menu li").hover(
		function () {
			var id = $(this).attr("id").substr(4,1);
			var subMenu = "#float" + id;
			var menu = "#main" + id;
			// hide layer of previous menu div (occurs when moving horizontally in menu bar)
			if (prevMenu != '' && prevMenu != subMenu) {
				$(prevMenu).hide();
			}
			// remove hover and active classes of previous menu (occurs when moving horizontally in menu bar)
			if (prevMain != '' && prevMain != menu) {
				$(prevMain).children().removeClass('hover');	// hide dotted line
				$(prevMain).children().removeClass('active');	// show default color
			}
			// show layer of current menu and toggle menu to active
			$(menu).children().addClass('hover');	// hide dotted line
			$(menu).children().addClass('active');	// show active color
			$(subMenu).get(0).donthide = true;
			$(subMenu).fadeIn("fast");
			if (this.timeout1) {
				window.clearTimeout(this.timeout1);
			}
		},
		function(){
			var id = $(this).attr("id").substr(4,1);
			var subMenu = "#float" + id;
			var menu = "#main" + id;
			$(subMenu).get(0).donthide = false;
			$(subMenu).get(0).timeout1 = window.setTimeout(function() {
				if (!$(subMenu).get(0).overme) {
					$(subMenu).fadeOut("fast");
					$(menu).children().removeClass('hover');	// show dotted line
					$(menu).children().removeClass('active');	// show default color
				}
			}, defaultTimeout);
			prevMain = menu;
			prevMenu = subMenu;
		}
	);

	// register event listeners for menu divs
	$("#menu").children().each(function() {
		var id = $(this).attr("id").substr(4,1);
		var menuDiv = "#float" + id;
		var menu = "#main" + id;
		$(menuDiv).hover(
			function(){
				$(menu).children().addClass('hover');	// hide dotted line
				$(menu).children().addClass('active');	// show active color
				this.overme = true;
				if (this.timeout2) {
					window.clearTimeout(this.timeout2);
				}
			},
			function(){
				$(menuDiv).get(0).overme = false;
				$(menuDiv).get(0).timeout2 = window.setTimeout(function() {
					if(!$(menuDiv).get(0).donthide) {
						$(menuDiv).fadeOut('fast');
						$(menu).children().removeClass('hover');	// show dotted line
						$(menu).children().removeClass('active');	// show default color
					}
				}, defaultTimeout);
			}
		);
	})
});



// social bookmarks (filip)
this.page = new function() {
  this.url = encodeURIComponent(window.location);
  this.title = encodeURIComponent(document.title);
};






// dom
function switchExpandable(id) {
  e = document.getElementById("klapp" + id);
  clss = e.className;
  if (clss.indexOf("remove") > 0) {
    e.className = clss.replace(/remove/g, "add");
    document.getElementById("klapp_c" + id).className = "hide";
  } else {
    e.className = clss.replace(/add/g, "remove");
    document.getElementById("klapp_c" + id).className = "show";
  }
}
// jquery
function toggleExpandable(id) {
  e = document.getElementById("klapp" + id);
  clss = e.className;
  if (clss.indexOf("remove") > 0) {
    e.className = clss.replace(/remove/g, "add");
  } else {
    e.className = clss.replace(/add/g, "remove");
  }
  $("#klapp_c" + id).slideToggle("slow");
}
function toggleExpandableGM(id) {
  toggleExpandable(id);
  initGM(); // initialize google map (isn't done correctly in hidden div)
}





// based on jquery lightbox
function lbMail(cA) {
  var defWidth = 495;
  $('body').append('<div id="lbMail-overlay"></div>');
  var arrPageSizes = lbMail_getPageSize();
  var arrPageScroll = lbMail_getPageScroll();
  $('#lbMail-overlay').css({
  	backgroundColor:	'white',
	opacity:			0.9,
	width:				arrPageSizes[0],
	height:				arrPageSizes[1]
  }).fadeIn();
  $('body').append('<div id="lbMail-iframeDiv"><iframe frameborder="0" id="lbMail-iframe" src="Mail.300.0.html?to=' + cA + '&url=' + escape(window.location.href) + '" ></iframe></div>');
  $('#lbMail-overlay').click(function() {
	  lbMail_finish();									
  });
  $('#lbMail-iframeDiv').css({
 	left:	parseInt((arrPageSizes[0] - defWidth) / 2),
 	top: parseInt(arrPageScroll[1] + 100)
  }).fadeIn();
}

function lbMail_finish() {
//  $('#lbMail-overlay').remove();
  $('#lbMail-iframeDiv').remove();
  $('#lbMail-overlay').fadeOut(function() { $('#lbMail-overlay').remove(); });
  // Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
  $('embed, object, select').css({ 'visibility' : 'visible' });
}

/**
/ THIRD FUNCTION
* getPageSize() by quirksmode.com
*
* @return Array Return an array with page width, height and window width, height
*/
function lbMail_getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};
/**
/ THIRD FUNCTION
* getPageScroll() by quirksmode.com
*
* @return Array Return an array with x,y page scroll values.
*/
function lbMail_getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};
