var sprache_shown = false;

function hover_sprache() {
	$('sprachen').show();
	$('sprache_wrap').onmouseover = sprache_show;
	$('sprache_wrap').onmouseout = sprache_hide;
	sprache_shown = true;
}

function sprache_show() {
	sprache_shown = true;
}

function sprache_hide() {
	delay_sprache = new PeriodicalExecuter(sprache_hide_now, 3);
	sprache_shown = false;
}

function sprache_hide_now() {
	if (!sprache_shown) {
		$('sprachen').hide();
	}
}

function replaceViewerLinks() {
  var links = document.getElementsByTagName('a');
  for (var i = 0; i < links.length; ++i) {
    if (links[i].href.match(/^http:\/\/viewer.dialogperfect.de\/(\d)+\/.*\.html$/)) {
      links[i].className = 'lightwindow';
      links[i].title = links[i].innerHTML;
      if (dia_id == 1) {
      	links[i].href = links[i].href + "?dia_id=1";
      }
    }
  }
}

function checkNewsletterAnmeldung() {
	if (document.forms.newsletter_form.newsletter_anmelden.value.length > 3) {
		document.forms.newsletter_form.submit();
	}
}

function checkNewsletterAbmeldung() {
	if (document.forms.newsletter_form.email.value.length > 3) {
		document.forms.newsletter_form.submit();
	}
}

function toggle_referenz(id) {
	hideAllRefs();
	elem = $(id);
	elem.show();
	//periodical.stop();
	//periodical = new PeriodicalExecuter(untoggle_referenz, 30);
}

function untoggle_referenz() {
	hideAllRefs();
	elem = $('idbild');
	elem.show();
	//periodical.stop();
}

function hideAllRefs() {
	$('referenzen').descendants().each(function(top) {
	 if("refdet" == top.className || "refdet3" == top.className){
	    if(Element.visible(top)) {
	    	top.hide();
	    }
	 }
	});
}

function showInfoPr( opener, elem_num, name ) {
	elem = $("row"+elem_num);
	cur_pos = Position.cumulativeOffset(elem);
	//alert(cur_pos);
	$('info_text').innerHTML = "<a href='"+opener.href+"'>" + name + "</a>";
	$('info_text').style.top = (cur_pos[1])+"px";
	$('info_text').style.left = "38px";
	$('info_text').show();
}

function hideInfoPr() {
	$('info_text').hide();
}

function showMenuImg(elem_num, actsrc) {
	bild = $("img"+elem_num);
	bild.src = actsrc;
}

function hideMenuImg(elem_num, src) {
	bild = $("img"+elem_num);
	bild.src = src;
}

var act_elements = new Array();
var act_active = new Array();
//var periodical = new PeriodicalExecuter(untoggle_referenz, 60*60*24);

function tg(opener, element_nr){
	element = $('s'+element_nr);

	if (element) {
		hideAll();
		element.show();
		act_elements[0] = opener;
		act_elements[1] = element;
		act_active[0] = 1;
		act_active[1] = 0;
		opener.onmouseout = function(opener) { ele_0_out(); }
		//$('output').value = $('output').value + "rein "+act_active[0]+""+act_active[1]+"\n";
	}

	return false;
}

function act(actor) {
	if (actor == act_elements[0]) {
		actor.onmouseout = function() { ele_0_out() };
		act_active[0] = 1;
	} else if (actor == act_elements[1]) {
		actor.onmouseout = function() { ele_1_out() };
		act_active[1] = 1;
	}
	//$('output').value = $('output').value + "rein "+act_active[0]+""+act_active[1]+"\n";
}

function ele_0_out() {
	act_out(0);
}

function ele_1_out() {
	act_out(1);
}

function act_out(actor) {
	if (actor == 0) {
		$(act_elements[0]).onmouseout = "";
		act_active[0] = 0;
		//$('output').value = $('output').value + "ele 0 auf 0\n";
	} else if (actor == 1) {
		$(act_elements[1]).onmouseout = "";
		act_active[1] = 0;
		//$('output').value = $('output').value + "ele 1 auf 0\n";
	}
	if (act_active[0] == 0 && act_active[1] == 0) {
		window.setTimeout("act_hide()",250);
	}
	//$('output').value = $('output').value + "raus "+act_active[0]+""+act_active[1]+"\n";
}

function act_hide() {
	//$('output').value = $('output').value + "hide "+act_active[0]+""+act_active[1]+"\n";
	if (act_active[0] == 0 && act_active[1] == 0) {
		hideAll2();
		act_elements[0] = null;
		act_elements[1] = null;
	}
}

function hideAll() {
	$('menu').descendants().each(function(top) {
	 if(("subsubmenue" == top.className) & ("UL" == top.tagName)){
	    if(Element.visible(top)) {
	    	top.hide();
	    }
	 }
	});
}

function hideAll2() {
	$('menu').descendants().each(function(top) {
	 if(("subsubmenue" == top.className) & ("UL" == top.tagName)){
	    if(Element.visible(top)) {
	    	top.hide();
	    }
	 }
	});
}

/*
function nextText() {
	if (cur_text < max_text-1) {
		$('text_'+cur_text).hide();
		cur_text++;
		$('text_'+cur_text).show();

		if (cur_text == max_text-1) {
			$('nextTextLink').style.visibility = 'hidden';
		}
	}
	else {
		$('nextTextLink').style.visibility = 'hidden';
	}

	if (cur_text > 1) {
		$('prevTextLink').style.visibility = 'visible';
	}
}
*/

function showText(text) {
	if (text < max_text+1) {
		$('text_'+cur_text).hide();
		$('link_'+cur_text).style.fontWeight = "normal";
		cur_text = text;
		$('link_'+text).style.fontWeight = "bold";
		$('text_'+text).show();
	}
}

/*
function prevText() {
	if (cur_text > 0) {
		$('text_'+cur_text).hide();
		cur_text--;
		$('text_'+cur_text).show();

		if (cur_text == 1) {
			$('prevTextLink').style.visibility = 'hidden';
		}
	}
	else {
		$('prevTextLink').style.visibility = 'hidden';
	}

	if (cur_text < max_text) {
		$('nextTextLink').style.visibility = 'visible';
	}
}
*/

function gotoUrl( url ) {
	window.location.href = url;
}

function showInfo(id) {
	if ($('info_'+id) && posSet) {
		$('info_'+id).style.left = (posX-10)+'px';
		$('info_'+id).style.top = (posY+25)+'px';
		$('info_'+id).show();
	}
	else waitInfo = id;
	//alert(posX + " - " + posY);
}

function hideInfo(id) {
	$('info_'+id).hide();
	posSet = false;
}


var on = false;
var pos = false;
var posX = -1;
var posY = -1;
var posSet = false;
var waitInfo = -1;

function Start(e)
{
    if(on)
    {
         if(window.document.releaseEvents)  window.document.releaseEvents( Event.MOUSMOVE);
         window.document.onmousemove = null;
         e.value ='Start';
    }else
    {
         if(window.document.captureEvents) window.document.captureEvents(Event.MOUSEMOVE);
         window.document.onmousemove = showMousePos;
         e.value ='Stopp';
    }
    on = !on;
}
function showMousePos(e)
{
    var p = mouse_pos(e);
    posX = p.left;
    posY = p.top;
    posSet = true;

    if (waitInfo > 0) {
    	showInfo(waitInfo);
    	waitInfo = -1;
    }
}

function mouse_pos(evt)

{

    if(!evt) evt = window.event;

    var pos = new Object();

    pos.left = evt.clientX;

    pos.top = evt.clientY;

    var b = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ?

   window.document.documentElement : window.document.body || null;

    if (b)

    {

        pos.scrollLeft= pos.left + b.scrollLeft;

        pos.scrollTop = pos.top + b.scrollTop;

    }

    else if(document.layers)

    {

        // Netscape 4.

        pos.scrollLeft = evt.pageX;

        pos.scrollTop = evt.pageY;

        pos.left = evt.pageX - window.pageXOffset;

        pos.top = evt.pageY - window.pageYOffset;

    }

	//alert(pos.left + " - " + pos.top);

    return pos;

}

var cur_ref = 1;
function startRefShow() {
	Effect.Appear('ref1', { duration: 2.5 });
	window.setInterval("nextRef()", 3500);
}

function nextRef() {
	if (cur_ref != max_ref) {
		changeRef(cur_ref, cur_ref+1);
		cur_ref++;
	}
	else {
		changeRef(cur_ref, 1);
		cur_ref = 1;
	}
}

function changeRef(f, a) {
	Effect.Fade('ref'+f, { duration: 1.5 });
	Effect.Appear('ref'+a, { duration: 1.5 });
}


