var content_breite = 0;
var content_hoehe = 0;
var hoehe_center = 0;

var opened_clip_detail = 0;

var preloads = new Array();
var site_loads = new Array();
var site_unloads = new Array();

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i, x, a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function my_MM_swapImgRestore() { //v3.0
  var i, x, a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++){
  		if (/t\.gif$/i.test(x.oSrc)){
			x.src = x.pngsrc;
		} else {
	  		x.src=x.oSrc; 
	  	}
	}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){
  	document.MM_sr[j++]=x; 
	if (!x.oSrc) x.oSrc=x.src; 
	x.src=a[i+2];
  }
}

function zentrieren() {
	var i, obj, breite, hoehe;
	
	
 	if (window.innerWidth) {
		breite = window.innerWidth;
  	} else if (document.body && document.body.offsetWidth) {
    	breite = document.body.offsetWidth;
	} else {
    	breite = 0;
	}	

	if (window.innerHeight) {
		hoehe = window.innerHeight;
  	} else if (document.body && document.body.offsetHeight) {
    	hoehe = document.body.offsetHeight;
	} else {
    	hoehe = 0;
	}
	obj = document.getElementById("center_div");


	if (obj) {
		i = breite - content_breite;
		i = i / 2;
		if (i < 0) i = 0;

		j = hoehe - content_hoehe;
		j = j / 2;
		if (j < 0) j = 0;
	
		obj.style.left = i+"px";
		if (hoehe_center) {
			obj.style.top = j+"px";
		}
	}
}

function zentrierenBreite(breite) {
	var i, obj, tmpBreite;
	
	content_breite = breite;
	
 	if (window.innerWidth) {
		tmpBreite = window.innerWidth;
  	} else if (document.body && document.body.offsetWidth) {
    	tmpBreite = document.body.offsetWidth;
	} else {
    	tmpBreite = 0;
	}	
	
	i = tmpBreite - breite;
	i = i / 2;
	if (i < 0) i = 0;
	
	/*return i;*/
	document.write('<style type="text/css">');
	document.write('#center_div { position: absolute; left: '+i+'px; }');
	document.write('</style>');
}

function zentrierenHoehe(hoehe, vertikal) {
	var i, obj, tmpHoehe;

	content_hoehe = hoehe;
	hoehe_center = vertikal;

	if (window.innerHeight) {
		hoehe = window.innerHeight;
  	} else if (document.body && document.body.offsetHeight) {
    	hoehe = document.body.offsetHeight;
	} else {
    	hoehe = 0;
	}

	j = hoehe - content_hoehe;
	j = j / 2;
	if (j < 0) j = 0;
	
	if (!vertikal) {
		j = 0;
	} 
	
	/*return j;*/
	document.write('<style type="text/css">');
	document.write('#center_div { position: absolute; top: '+j+'px; }');
	document.write('</style>');
}

function preload() {
  var d = document; 
  if (d.images){ 
  	if (!d.MM_p) d.MM_p = new Array();
    var j = d.MM_p.length;
    for (var i = 0; i < preloads.length; i++) {
		if (preloads[i].indexOf("#") != 0) {
			d.MM_p[j] = new Image; 
			d.MM_p[j++].src = preloads[i];
		}
    }
  }
}

function site_unload() {
	for(var i = 0; i < site_unloads.length; i++){
		site_unloads[i]();
	}
}

function site_load() {
	for(var i = 0; i < site_loads.length; i++){
		site_loads[i]();
	}
}

function getSel()
{
	var txt = '';
	var foundIn = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
		foundIn = 'window.getSelection()';
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
		foundIn = 'document.getSelection()';
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
		foundIn = 'document.selection.createRange()';
	}
	else return;
	document.forms[0].selectedtext.value = 'Found in: ' + foundIn + '\n' + txt;
}

function addResizeEvent(func) {
  var old = window.onresize;
  if (typeof window.onresize != 'function') {
    window.onresize = func;
  } else {
    window.onresize = function(e) {
      old(e);
      func(e);
    }
  }
}

function addScrollEvent(func) {
  var old = window.onscroll;
  if (typeof window.onscroll != 'function') {
    window.onscroll = func;
  } else {
    window.onscroll = function(e) {
      old(e);
      func(e);
    }
  }
}

function restoreClass() {
  var i, x, a=document.sclasses;
  for (i = 0; a && i < a.length && ( x=a[i]) && x.oClass; i++)  {
	  x.className = x.oClass;
  }
}

function swapClass() { //v3.0
  var i, j = 0, x, a=swapClass.arguments; 
  
  document.sclasses=new Array; 
  
  for (i = 0; i< (a.length - 1); i+=2) {
    if ((x = document.getElementById(a[i])) != null) {
  	  document.sclasses[j++] = x; 
  	  if (!x.oClass) {
	    x.oClass = x.className; 
	  }
      x.className=a[i + 1];
    }
  }
}

function showClip(flv, div, width, height, autoplay, clip) {
  var myAjax = new Ajax.Request('/cgi/runtime/index.pl?action=klick_update&clip_id=' + clip, {
	method: 'get',
	parameters: '',
	onComplete:	function (transport) {
				}
		}
	);
 
  var so = new SWFObject("/shared/swf/player" + width + "x" + height + ".swf?test", "laufleiste", width, 1*height + 40, "6", "#ffffff");
  so.addVariable("video",flv);
  so.addVariable("player","/shared/swf/skin" + width + "x" + height + ".swf");
  so.addVariable("autoplay", autoplay);
  so.addVariable("quality","high");
  so.addVariable("name", "htdocs/player");
  so.addVariable("allowScriptAccess=", "sameDomain");
  so.write(div);
}

function clip_details(id, art) {
  if (art) {
	art = '&art=' + art;  
  } else {
	art = '';
  }
  
  // die noch geoeffneten Details schliessen
  if(opened_clip_detail > 0){
  	clip_details_close(opened_clip_detail);
  }
  opened_clip_detail = id;
  
  var myAjax = new Ajax.Request('/cgi/runtime/index.pl?action=clip_detail&clip_id=' + id + art, {
	method: 'get',
	parameters: '',
	onComplete:	function (transport) {
					zoom();
					$('theclipdetail').innerHTML = transport.responseText;
					$('theclipdetail').style.display='';
				}
		}
	);
}

function clip_details_close(id) {
	//$('ajax' + id).style.display='none';
	closeZoom();
}

function ajax_call(action, method, paras, on_complete, on_exception, on_failure){
	var url  = "/cgi/runtime/index.pl?action=" + action;
		
	var para_string = null;

	if(paras != null) {
		var h = $H(paras);
		h.merge({ rand: Math.random() });
		para_string = h.toQueryString();
		if(para_string == "") {
			para_string = null
		}
	}
	
	var paras = {
			method:     method, 
			parameters: para_string, 
			onSuccess: on_complete
		};
		
	if(on_exception){
		paras['onException'] = on_exception;
	}
	
	if(on_failure){
		paras['onFailure'] = on_failure;
	}
	
	var ajax = new Ajax.Request(
		url, 
		paras);
}
 
function keyPressed(e) {
    var key;
    if (window.event) key = window.event.keyCode
    else if (e) key = e.which
    return key;
}

function zoom() {
    div = document.getElementById('clipdetailbg');
    
    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){
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else {
            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) {
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) {
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }   
       
        if(yScroll < windowHeight){
            hoehe = windowHeight;
        } else {
            hoehe = yScroll;
        }
    
        if(xScroll < windowWidth){   
            breite = xScroll;       
        } else {
            breite = windowWidth;
        }
    
    breite = breite + 'px';
    hoehe = hoehe + 'px';
    
    if (typeof window.pageYOffset == "number") {
		pagetop = window.pageYOffset;
		pageleft = window.pageXOffset;
	} else {
		if (typeof document.body.scrollTop == "number") {
			pagetop = document.body.scrollTop;
			pageleft = document.body.scrollLeft;
		}
	}
	
	pageleft = pageleft + 250;
	pagetop = pagetop + (windowHeight / 2) - 100;
	
	$('theclipdetail').setStyle({left: pageleft + 'px'});
	$('theclipdetail').setStyle({top: pagetop + 'px'});
    
    if (div) {
        div.style.position='absolute';
        div.style.zIndex='5000';
        div.style.top='0px';
        div.style.left='0px';
        div.style.width=breite;
        div.style.height=hoehe;
        div.style.backgroundColor='#000000';
        div.style.filter = 'alpha(opacity=50)';
        div.style.MozOpacity = 0.5;
        div.style.opacity='0.50';
        div.style.display='';
    }
}

function closeZoom() {
    var div = document.getElementById('clipdetailbg');
    if (div) {
        div.style.display='none';
        newdiv = document.getElementById('theclipdetail');
        newdiv.style.display='none';
        newdiv.innerHTML = "";
    }
} 

function keyPressed(e) {
    var key;
    if (window.event) key = window.event.keyCode
    else if (e) key = e.which
    return key;
}

function submit_search_formular(){
	var f = document.forms['gesamtsuche'];
	f.submit();
}

function show_gesundheitsnews_movie(){
	
}

(function() {
  function ellipsis(e) {
    e.style.display='';
    var w = e.getWidth() - 10000;
    var t = e.innerHTML;
	e.innerHTML = "<span>" + t + "</span>";
    e = e.down();
    while (t.length > 0 && e.getWidth() >= w) {
      t = t.substr(0, t.length - 1);
	  e.innerHTML = t + "...";
    }

  }
  document.write('<style type="text/css">' +
    '.ellipsis { margin-right:-10000px; }</style>');
  Event.observe(window, "load", function() {
    $$('.ellipsis').each(ellipsis);
  });
})();


function getBody(w){
	return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ? w.document.documentElement : w.document.body || null;
}

function t_height() {
	var obj = $('transparenz');

	var h;

  
	var win = window;
  
	if(typeof win.innerWidth != 'undefined'){
		h = win.innerHeight;

	} else {

		h = parseInt(getBody(window).clientHeight);

	}
	if (h < document.body.scrollHeight) { h = document.body.scrollHeight }
	if (obj) {obj.style.height = h+'px'}

}

function show_news_movie(file) {
	$('transparenz').style.display='';
	$('newsplayer').style.display='';
	$('video').style.display='none';
	$('videodummy').style.display='';
	startMovie(file)
}

function hide_news_movie() {
	$('transparenz').style.display='none';
	$('newsplayer').style.display='none';
	$('news_flash_player').innerHTML = '';
	$('video').style.display='';
	$('videodummy').style.display='none';
}

function startMovie(file) {
	
		var s1 = new SWFObject("/shared/swf/news_player.swf","jstest","640","360","6");
		s1.addParam("allowfullscreen","true");
		s1.addVariable("width","640");
		s1.addVariable("height","360");
		s1.addVariable("file",file);
		s1.addVariable("autostart","false");
		s1.addVariable("backcolor","0x679D11")
		s1.addVariable("frontcolor","0xFFFFFF");
		//s1.addVariable("image","/images/"+image_id+"/source."+type);
		s1.write("news_flash_player");
	
}

function showClip2(file,image,width,height,id,autoplay) {
	
		var s1 = new SWFObject("/shared/swf/news_player.swf","player"+id,width,height,"6");
		s1.addParam("allowfullscreen","true");
		s1.addVariable("width",width);
		s1.addVariable("height",height);
		s1.addVariable("file",file);
		s1.addVariable("autostart",autoplay);
		s1.addVariable("backcolor","0x679D11")
		s1.addVariable("frontcolor","0xFFFFFF");
		
		if (image) {s1.addVariable("image",image);}
		s1.write(id);
	
}

function showGhnewsImage (id) {
  var o;
  if (o = $('ghnewsImage'+id)) {
    o.style.display = "";
    for (var i = 1; i <= 5; i++) {
      if (i != id && (o = $('ghnewsImage'+i)))
        o.style.display = "none";
    }
  }
}

function click_count(aktion) {
  var myAjax = new Ajax.Request('/cgi/runtime/index.pl?action=bannerklick&aktion=' + aktion, {
	method: 'get',
	parameters: '',
	onComplete:	function (transport) {
				}
		}
	);
}
