var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
 && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
 && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1) && (is_major < 5));
var is_nav6up = ((is_nav && (is_major >= 5)) || (agt.indexOf('gecko') != -1));
var is_moz = (agt.indexOf('gecko') != -1);
var is_opera = (agt.indexOf("opera") != -1);
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie55up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var MAC = navigator.platform.indexOf("Mac") != -1;
var lHeight;
var logoY = 0;
var lastScrY;
var demY = 0.7;
var sY = 0;
var accY = 24;
var align = "bottom";
var loopFunc = "";

function ajaxLoad(id) {
	
	var inst = tinyMCE.getInstanceById('textarea_'+id);
	inst.setHTML($(id+'_text').innerHTML);
}

function editText(p){
	
	var editorblock;
	editorblock  = '<div id="textEditor" class="editor">';
	editorblock += '<textarea id="editor" name="editor" class="mceEditor">';
	editorblock += $('textContent').innerHTML;
	editorblock += '</textarea>';
	editorblock += '<input type="button" class="button bold" style="margin-left: 3px; margin-top: 5px; font-weight: bold;" value="Speichern" onclick="ajaxSave('+p+');" />';
	editorblock += '<input type="button" class="button" style="margin-top: 5px;" value="Abbrechen" onclick="editCancel()" />';
	editorblock += '</div>';
	
	new Insertion.Before('textBox', editorblock);
	Element.hide('textBox');
	
	tinyMCE.execCommand('mceAddControl', true, 'editor');
	tinyMCE.execInstanceCommand('editor','mceFocus',false);
}

function ajaxSave(obj) {
	
	tinyMCE.execCommand('mceRemoveControl', false, 'editor');
	
	var success	= function(t){editComplete(t, obj);}
	var failure	= function(t){ajax_error(t, obj);}
  	var url = 'process.php';
	var pars = 'm=editText&p='+obj+'&text='+str_replace("&", "###", $('editor').value);
	var myAjax = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});
	
	msgShow("Die Text&auml;nderungen wurden gespeichert.");
	
}

function editComplete(t, obj){

	editCancel();
	var response = str_replace("\\", "", t.responseText);
	$('textContent').innerHTML = response;
	
	msgShow("Die Text&auml;nderungen wurden &uuml;bernommen.");
	
}

function editCancel(){
	
	Element.remove('textEditor');
	Element.show('textBox');
}

function showSubNav(parent){
	
	$($$('#nav div.nav2')).invoke('hide');
	$($$('#nav div.nav3')).invoke('hide');
	$($$('#nav div.parent'+parent)).invoke('show');
	
	Element.removeClassName("nav1_1", "nav1Active");
	Element.removeClassName("nav1_2", "nav1Active");
	Element.removeClassName("nav1_3", "nav1Active");
	Element.removeClassName("nav1_4", "nav1Active");
	
	Element.addClassName("nav1_"+parent, "nav1Active");
	
	$('main').style.background = 'transparent url(img/backgrounds/' + parent + '.jpg) no-repeat scroll left top';	
	
	contentDisappear(0);
	
	//}
}

function getWindowWidth() 
{
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
			x = self.innerWidth;
			y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
	{
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
			x = document.body.clientWidth;
			y = document.body.clientHeight;
	}
	
	if(is_moz){ x -= 18; }
	return x;
	
}

function getWindowHeight() 
{
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
			x = self.innerWidth;
			y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
	{
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
			x = document.body.clientWidth;
			y = document.body.clientHeight;
	}
	return y;
}

function horizontalScroll(direction){
	
	if(direction=="left"){
		if($F('imgActive') > 1){
			$('imgActive').value = parseInt($('imgActive').value) - 1;
			var scrollToImg = 'img'+$F('imgActive');
		}
		
	} else {
		
		if($F('imgActive') < $F('countImages')){
			$('imgActive').value = parseInt($F('imgActive')) + 1;
			var scrollToImg = 'img'+$F('imgActive');
		}
	}	
	
	if(scrollToImg){
		new Effect.ScrollTo(scrollToImg, {offsetX: -370, offsetY: 0, duration: 0.3});
	}
}


Effect.ScrollTo = Class.create();
Object.extend(Object.extend(Effect.ScrollTo.prototype, Effect.Base.prototype), {

  initialize: function(element) {
    this.element = $(element);
    this.start(arguments[1] || {});
  },
  
  setup: function() {
    Position.prepare();
    var offsets = Position.cumulativeOffset(this.element);
    if(this.options.offsetX) offsets[0] += this.options.offsetX;
    if(this.options.offsetY) offsets[1] += this.options.offsetY;

    var maxWidth = window.innerWidth ? 
      window.width - window.innerWidth :
      document.body.scrollWidth - 
        (document.documentElement.clientWidth ? 
          document.documentElement.clientWidth : document.body.clientWidth);
    this.scrollStartX = Position.deltaX;
    this.deltaX = (offsets[0] > maxWidth ? maxWidth : offsets[0]) - this.scrollStartX;

    var maxHeight = window.innerHeight ? 
      window.height - window.innerHeight :
      document.body.scrollHeight - 
        (document.documentElement.clientHeight ? 
          document.documentElement.clientHeight : document.body.clientHeight);
    this.scrollStartY = Position.deltaY;
    this.deltaY = (offsets[1] > maxHeight ? maxHeight : offsets[1]) - this.scrollStartY;
  },
  
  update: function(position) {
    Position.prepare();
    window.scrollTo(
      this.scrollStartX + (position * this.deltaX),
      this.scrollStartY + (position * this.deltaY)
    );
  }
});	

function scrollDiv(strId,intSpd) {
	
	if ( objScrll=document.getElementById(strId) ) {
		var top = parseInt(objScrll.style.top);
		if ( (intSpd>0) ? (top<0) : (top>parseInt(objScrll.parentNode.style.height)-objScrll.offsetHeight) ) 
			objScrll.style.top = (top + intSpd) +"px";
		eval( 'tvar' + strId +'= setTimeout("scrollDiv(\''+ strId +'\',' + intSpd + ')",50)' );
		if (objSelf=scrollDiv.arguments[2]) 
			objSelf.onmouseup = objSelf.onmouseout = new Function('fx','clearTimeout(tvar' + strId + ')');
	}
	
	if(top < 0){ Element.show('scrollUp'); } else { Element.hide('scrollUp'); }
	if(top>=parseInt(objScrll.parentNode.style.height)-objScrll.offsetHeight){ Element.show('scrollDown'); } else { Element.hide('scrollDown'); }
}

function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}

function scrollDivHorizontal(strId,intSpd) {

	if ( objScrll=document.getElementById(strId) ) {
		var left = parseInt(objScrll.style.left);
	
		if ( (intSpd>0) ? (left<0) : (parseInt(left)>parseInt(getWindowWidth())-objScrll.offsetWidth+10) ) 
			objScrll.style.left = parseInt(left) + intSpd +"px";
		
		eval( 'tvar' + strId +'= setTimeout("scrollDivHorizontal(\''+ strId +'\',' + intSpd + ')",5)' );
		if (objSelf=scrollDivHorizontal.arguments[2]) 
			objSelf.onmouseup = objSelf.onmouseout = new Function('fx','clearTimeout(tvar' + strId + ')');
	}

	if(left < 0){ Element.show('scrollLeft'); } else { Element.hide('scrollLeft'); }
	if(parseInt(left)>parseInt(getWindowWidth())-objScrll.offsetWidth){ Element.show('scrollRight'); } else { Element.hide('scrollRight'); }
}

















