// JavaScript Document

function initPage(theEvent,category) {
	var pageHeight = document.getElementById('BODY').offsetHeight;
//	$('A').innerHTML = theEvent+' / '+category+' ('+pageHeight+')';
	if((theEvent == 'onload' && readCookie('pageHeight') == null) || theEvent == 'onresize') {
		writeCookie('pageHeight',pageHeight,'');
		if(pageHeight < 650) {
		//	$('B').innerHTML = 'pageHeight: - '+pageHeight+'px';
			$('TITLE').style.display = 'none';
			$('TEASER1').style.display = 'none';
			$('TITLE_ALT').style.display = 'block';
			if(category != 'home')
			$('TEASER1_ALT').style.display = 'block';
			$('MAIN').style.marginTop = '-301px';
		} else {
		//	$('B').innerHTML = 'pageHeight: + '+pageHeight+'px';
			$('TITLE').style.display = 'block';
			if(category != 'home')
			$('TEASER1').style.display = 'block';
			$('TITLE_ALT').style.display = 'none';
			$('TEASER1_ALT').style.display = 'none';
			$('MAIN').style.marginTop = '-280px';
		}
	//	if(pageHeight < 600) { }
	}
}


/** AJAX-Funktionen: */

function updateData (target, url, pars, loader) { 
	var rand   = Math.random(9999);
	var pars   = pars + '&rand=' + rand;
	Effect.Fade(target, { duration: 0.5, from: 1, to: 0.1 });
	if(loader != '') { showLoader(loader); }
	var myAjax = new Ajax.Request( url, { method: 'get', 
								   parameters: pars, 
								   onComplete: function(updateTarget) { $(target).innerHTML = updateTarget.responseText; 
								   		Effect.Appear(target, { duration: 0.5, 
										from: 0.1, to: 1 } ); 
								   hideLoader(loader); 
								// makeDraggables(); 
								   }
	} );
}	

function reloadData (target, url, pars, loader) {
	var rand   = Math.random(9999);
	var pars   = pars + '&rand=' + rand;
	Effect.Fade(target, { duration: 0.5, from: 1, to: 0.1 });
	if(loader != '') { showLoader(loader); }
	var myAjax = new Ajax.Updater(target, url, {
  								  method: 'get', 
								  parameters: pars,
								  evalScripts: true
  	});
	
}

function showLoader (loader) {
	$(loader).style.display = "block";
}
function hideLoader (loader) {
	Effect.Fade(loader, { duration: 0.5 });
}

function submitForm(target, url, form, loader) {
//	alert(target);
	var rand   = Math.random(9999);
//	Effect.Fade(target, { duration: 0.5, from: 1, to: 0.1 });
	if(loader != '') { showLoader(loader); }
	new Ajax.Updater(target, url, {
		method: 'post',
  		parameters: $(form).serialize(),
		evalScripts: true
	});
}

/** Popup-Funktionen: (Prototype) */

function viewPopup() {
	if ( Prototype.Browser.IE ) var t = 0;
	else var t = 0.3;
	$('PopupContent').innerHTML = '<div class="Close"><a href="javascript:void(0);" onclick="hidePopup();"><img src="/assets/content/btn-close.png" width="13" height="13" alt="x" title="Popup schließen" /></a></div>';
	new Effect.Appear('PopupOverlay', { duration: t, from: 0, to: 0.9 });
	new Effect.Appear('PopupContent', { duration: t, from: 0, to: 1 });
}
function hidePopup() {
	if ( Prototype.Browser.IE ) var t = 0;
	else var t = 0.3;
	new Effect.Fade('PopupOverlay', { duration: t, from: 0.9, to: 0 });
	new Effect.Fade('PopupContent', { duration: t, from: 1, to: 0 });
}
function setPopup(url, insert) {
	target = 'PopupContent';
//	alert($(target).style.display);
	if($(target).style.display == 'none') {
		new Ajax.Updater(target, url, {
			method: 'post',
			insertion: insert,
			evalScripts: true
		});
		viewPopup();
	} 
	else alert('Bitte schließen Sie zuerst das aktuelle Popup!');
} 

function viewVideoTut() {
	if ( Prototype.Browser.IE ) var t = 0;
	else var t = 0.3;
	new Effect.Appear('PopupOverlay', { duration: t, from: 0, to: 0.9 });
	new Effect.Appear('PopupVideo', { duration: t, from: 0, to: 1 });
}
function hideVideoTut() {
	if ( Prototype.Browser.IE ) var t = 0;
	else var t = 0.3;
	new Effect.Fade('PopupOverlay', { duration: t, from: 0.9, to: 0 });
	new Effect.Fade('PopupVideo', { duration: t, from: 1, to: 0 });
}

/** Cookies: */

function writeCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	writeCookie(name,"",-1);
}


/** NC-Standart-Funktionen: ---------- */

var MSIE = document.all ? true : false;
var NSC6 = (document.getElementById && !MSIE) ? true : false;
var NSC4 = (navigator.appName == 'Netscape' && !(MSIE || NSC6)) ? true : false;


function reloadPage() {
	location.reload();
}

function getBrowserWidth() {
	if (document.all) return document.all.thisdoc.offsetWidth;
	else return self.innerWidth;
}

function getBrowserHeight() {
	if (document.all) return document.all.thisdoc.offsetHeight;
	else return self.innerHeight;
}

function Popup(theURL,winName,features) { 
	window.open(theURL,winName,features);
}

function slideTab(obj) {
	var t = 0.4;
	if($(obj).style.display == 'none') { Effect.SlideDown(obj, { duration: t }); } 
	else { Effect.SlideUp(obj, { duration: t }); }
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

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

function 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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

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

//alert('JS loaded!');
