// alltrix.js

var loc = '';
var smooth_timer = 0;
var gsrc='';

function $$() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

function cumulativeOffset(element) {  
    var valueT = 0, valueL = 0;
    do {
      valueT += element.offsetTop  || 0;
      valueL += element.offsetLeft || 0;
      element = element.offsetParent;
    } while (element);
    return [valueL, valueT];
}

function smoothHeight(id, curH, targetH, stepH) {
  diff = targetH - curH;
  if (diff != 0) {
    newH = (diff > 0) ? curH + stepH : curH - stepH;
    $$(id).style.height = newH + "px";
    if (smooth_timer) window.clearTimeout(smooth_timer);
    smooth_timer = window.setTimeout( "smoothHeight('" + id + "'," + newH + "," + targetH + "," + stepH + ")", 17 );
  }
  if ($$(id).style.height == '0px' && targetH == 0) $$(id).style.display = 'none';
}

function toggler(id, src) {

	gsrc = src;
	window.setTimeout("gsrc='';", 3000);
	$$('i_'+id).src = src;
	loc=id;
	if ($$('i_'+id).style.display == '' || $$('i_'+id).style.display == 'none') {
		$$('s_'+id).style.display='inline';
		$$('i_'+id).style.display='block';
    pos_y = cumulativeOffset($$('i_'+id));
		window.scrollTo(0, pos_y[1]-148);	
		smoothHeight('i_'+id, 0, 400, 20);
		$$('i_'+id).focus();
		//new Element.scrollTo('h_'+id,{duration:5.0}); an die stelle in der seite gehen braucht scriptacoulus
	} else {
		
		smoothHeight('i_'+id, 400, 0, 40);	
		$$('s_'+id).style.display='none';
		loc='';
	};
}

function change_lang(el) {
	//if (window.location.href.indexOf('?')>0) { var sep='&'; } else { var sep = '?'; }
	//window.location.href=window.location.href+sep+'lang='+el.value;
	$$('langs').submit();
}

function position_hefo() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		$$('content').style.width = '886px';
		$$('content').style.left = ((document.body.clientWidth - 910) / 2) + 'px';
		$$('content').style.display='block';
		$$('head').style.left = ((document.body.clientWidth - 910) / 2) + 'px';
			//parseInt($('foot').offsetHeight) ) + 'px';
		$$('head').style.position = 'fixed';
		$$('foot').style.position = 'fixed';
		$$('foot').style.top = (document.documentElement.clientHeight - 48) + 'px'; 
		$$('foot').style.left = ((document.body.clientWidth - 910) / 2) + 'px';

	} else {
		$$('head').style.left = ((window.innerWidth - 910) / 2) + 'px';
		$$('content').style.width = '886px';
		$$('content').style.left = ((window.innerWidth - 910) / 2) + 'px';
		$$('content').style.display='block';
		$$('foot').style.top = (window.innerHeight - 48) + 'px'; 
		$$('foot').style.left = ((window.innerWidth - 910) / 2) + 'px';
		$$('head').style.position = 'fixed';
		$$('foot').style.position = 'fixed';
	}
}
//init if DOMready
$(document).ready(function(){

	//$$($('h2').get(0)).style.display='inline';
		
	if (breakoutsite) var breakoutwindow = window.open(breakoutsite, 'breakoutsite', 'height=400,width=720,menubar=no,location=no,resizable=yes,scrollbars=yes,status=no');

/*
		$('h2').click(function() {
		//$('iframe:visible').hide('xfast');
		$$('i_' + this.id).src = 'http://www.heise.de/';

    pos_y = cumulativeOffset(this);
		window.scrollTo(0, pos_y[1]-48);

		$('iframe#i_' + this.id).slideDown('slow');
	});
*/	
	$('input#action').focus(function (){ if (this.value=='suchen...') this.value=''; }); 
	$('input#action').blur(function (){ if (this.value=='') this.value='suchen...'; }); 
});

$(document).load(function (){
	position_hefo();
	$($$('lang')).change(function (){
	if ($$('action').value == 'suchen...') $$('action').value = '';
	$$('langs').submit();
	});
});

//do not let site break out of iframe
$(document).unload(function (){
	if (gsrc) {
		if (window.location.href.indexOf('?') > 0) { var sep='&'; } else { var sep='?'; }
		window.location.href = window.location.href+sep+'breakoutsite='+gsrc;
	}
});

//reposition elements on resize
$(document).resize(function (){
		position_hefo();	
});

$('a').click(function (){
	$$('indicator').style.display = 'inline';
});
