
/**
 * custom javascript functions
 */


function getWinHeight() {
	winHt=(window.innerHeight!=null)?window.innerHeight:document.documentElement.clientHeight; 
	return winHt; 
}
function getWinWidth() {
	winWd=(window.innerWidth!=null)?window.innerWidth:document.documentElement.clientWidth; 
	return winWd; 
}

function setImgSize() {
	
	var docHt = getWinHeight(); 
	/* if (docHt>maxheight) {
		docHt=maxheight;
	}*/
	
	var factor = imgheight/docHt;
	var docWd = imgwidth/factor;
	//$(document.body).setStyle({overflow:'hidden'});//changed 2009-10-22
	
	if (Prototype.Browser.IE){
					docWd=docWd-20;
				}
	
	if (docHt) {
		
		$('bgimgwrapper').setStyle({height:docHt+'px'});
		$('bgimgwrapper').setStyle({width:docWd+'px'});
	}
	
	return(docWd);
}

function resizeWin(){
	
  			/*-window------*/
			var menuleiste=90;
			//alert(Prototype.Browser.Gecko);
			if (Prototype.Browser.IE){
				menuleiste=140;
			}
			if (Prototype.Browser.Gecko){
				menuleiste=130;
			}
				winOuterHt=window.screen.availHeight-menuleiste; 
			
			
			
			var scale = winOuterHt/imgheight;
			var winWd = imgwidth*scale;
			
			if(winWd<875){
					winWd=875; //minimal window width
				}
			window.moveTo(0,0); 
			window.resizeTo(winWd, screen.availHeight);
	
	
			//$(document.body).setStyle({overflow:'hidden'}); //changed 2009-10-22
			
			/*-image------*/
			var docHt = getWinHeight(); 
				if (docHt>maxheight) {
					docHt=maxheight;
				}
				
				
				
				var factor = imgheight/docHt;
				var docWd = imgwidth/factor;
				
				if (Prototype.Browser.IE){
					docWd=docWd-20;
				}
				
				
				if (docHt) {
					$('bgimgwrapper').setStyle({height:docHt+'px'});
					$('bgimgwrapper').setStyle({width:docWd+'px'});
					$('bgimgwrapper').setStyle({overflow:'hidden'}); 
				}
			
		
		
	}
 
function handleText(maxtextheight){
	
	if($('scrollable')){
		//setImgSize();
		if(maxtextheight===undefined){
			var docHt = getWinHeight(); 
			maxtextheight=docHt-300; 
			}
		
		if($('scrollable').offsetHeight > maxtextheight){
				$('scrollable').setStyle({height:(maxtextheight)+'px'});
				$('slider_track').setStyle({height:maxtextheight+'px'});
		}
		
		//changed 2009-10-22
		if($('handlePeople')){
			
			$('contentwrapper').setStyle({height:'590px'});
	
		}
	}
}



/**
 * ADD/REMOVE PARAM URL
 * --------------------
 * class handling addition or removal of parameter to/from url
 */
var AlterUrl = Class.create();
AlterUrl.prototype = {
	initialize: function(currentUrl) {
		this.qs = {};
		this.filepath = '';
		var s = currentUrl.replace( /^\?|#.*$/g, '' );
		
		if (s) {
			var f = s.split('?');
			if (f[0]!=undefined && f[1]!=undefined) {
				this.filepath = f[0];
				var qsParts = f[1].split('&');
				var i, nv;
				for (i = 0; i < qsParts.length; i++) {
					nv = qsParts[i].split('=');
					this.qs[nv[0]] = nv[1];
					//alert(nv[0]);
				}
			}
		}
	},
	add: function(name, value) {
		if( arguments.length == 1 && arguments[0].constructor == Object ) {
			this.addMany( arguments[0] );
			return;
		}
		this.qs[name] = value;
	},
	remove: function(name) {
		if( arguments.length == 1 && arguments[0].constructor == Array ) {
			this.removeMany( arguments[0] );
			return;
		}
		delete this.qs[name];
	},
	readVar: function(name) { // returns value of variable
		return this.qs[name];
	},
	get: function() {
		var nv, q = [];
		for( nv in this.qs ) {
			q[q.length] = nv+'='+this.qs[nv];
		}
		return this.filepath + '?' + q.join( '&' );
	}
} // AlterUrl


function hoverOver(){
		new Effect.Opacity('subnavbox', { from: 1.0, to: 0.7, duration: 0.8 });

}
function hoverOut(){
		new Effect.Opacity('subnavbox', { from: 0.7, to: 1, duration: 0.8 });
}

/**
 * sets cookie
 */
function set_cookie(name, value, days, path) {

	var today = new Date();
	var expire = new Date();
	var duration = 3600000*1;// take days off, one hour enough hzue
	expire.setTime(today.getTime() + duration);
	document.cookie = name + '=' + value + '; expires='+expire.toGMTString()+'; path=' + path + ';';
	
} // set_cookie()

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

/**
 * SUBNAV POSITION
 * ---------------
 * handling window position (draggable sub navigation)
 * position either stored in:
 * COOKIE
 * javascript tries to set cookie with wpos value (x|y)
 * if this failes, storage falls back to:
 * GET VAR
 * wpos variable is added to href attribute of subnav2
 * and subnav3
 */
function storeSubNavPos(globalwpos) {
	
	if (globalwpos===undefined) {
		
		// position changed with cursor
		var pos = $('subnavwrapper').viewportOffset();
		var posX = pos[0];
		var posY = pos[1];
		
		set_cookie('wpos', posX+'|'+posY, 360, '/');
	
	} else {
		
		// position provided by GLOBALS
		var pos = globalwpos.split('|');
		var posX = pos[0];
		var posY = pos[1];
	
	} // if
	
	/** fall back if cookie could not be set, add wpos to href attribute */
	if (document.cookie.indexOf('wpos') == -1) {
		
		/** 1st SubNavigation */
		if ($('subnav')!=undefined) { // add parameter to first sub navigation if displayed
			var listNodes = $('subnav').select('li');
			alterSubNavUrls(listNodes, posX, posY);
		} // if
		
		/** 2nd SubNavigation */
		if ($('subnav2')!=undefined) { // add parameter to second sub navigation if displayed
			var listNodes = $('subnav2').select('li');
			alterSubNavUrls(listNodes, posX, posY);
		} // if
		
		/** 3rd SubNavigation */
		if ($('subnav3')!=undefined) { // add parameter to third sub navigation if displayed
			var listNodes = $('subnav3').select('li');
			alterSubNavUrls(listNodes, posX, posY);
		} // if
		
	} // if
	
} // storeSubNavPos()

/**
 * walks through all list elements and alters href attribute
 * by adding wpos parameter
 */
function alterSubNavUrls(listNodes, posX, posY) {

	listNodes.each(function(item) { // 
		if (item.down('a')!=undefined) {
			var currentUrl = item.down('a').getAttribute('href');
			var au = new AlterUrl(currentUrl);
			au.remove('wpos'); // prevent adding wpos parameter more than once
			au.add('wpos', posX + '|' + posY );
			item.down().setAttribute('href', au.get());
		} // if
	});

} // alterSubNavUrls()


