var ns = document.layers ? true : false;
var ie = document.all && !window.opera ? true : false;;    // IEs
var dom = document.getElementById && !ie ? true : false;  // DOM-Browser

/*
  ////////////////////////////////////////////////////////////////
 // MAIN FUNKTIONEN											   //
////////////////////////////////////////////////////////////////
*/

var loadingMainContent = "<table border='0' cellspacing='0' celpadding='0' width='100%'><tr><td style='padding-top: 200px; text-align: center;'><img src='images/loading/maincontent.gif' /><br /></td></tr></table>";

var activeModule=false;
var activeFotoLeiste = false;

var activeTN; // aktive TopNav
var activeSN; // aktive SubNav

var newOverflow;


function d(text){
	if(!$("debug")) document.body.insert("<div id='debug'></div>");
	$("debug").update(text);
	$("debug").setStyle({
		position: "absolute",
		left: "0px",
		top: "0px",
		backgroundColor: "#000000",
		color: "#ffffff",
		zIndex: "111111",
		padding: "1px",
		paddingRight: "3px",
		paddingLeft: "2px"
	});
}

function reloadNavigation() {
	reloadNavi('navi_oberpunkte');
	reloadNavi('navi_bottom');
}

function reloadNavi(typ) {
	new Ajax.Request('ajax/reloadNavi.php?typ='+typ,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $(typ).update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function restoreNav(){
	
	var tn=$('nav_top_link_'+activeTN);
	var sn=$('navi_bottom_'+activeSN);
	if(tn && sn){
		for(i=0;i<100;i++){
			if($('navi_bottom_'+i)) $('navi_bottom_'+i).hide();	
		}
		for(ii=0;ii<100;ii++){
			if($('nav_top_link_'+ii)) $('nav_top_link_'+ii).className="nav_top_inaktiv";	
		}
		tn.className="nav_top_aktiv";
		sn.show();
	} 
}

function loadModule(id){
	/*
	var jetzt = new Date();
	var tc=jetzt.getTime();
	var funcstring="modinclude(";
	for(var i=0; i < loadModule.arguments.length; i++) 
  		{ 
			funcstring+='"'+loadModule.arguments[i]+'"';
			if((i+1) < loadModule.arguments.length) funcstring+=',';
		}
	funcstring+=')';
	$('historyframe').src='history.php?tc='+tc+'&callback='+escape(funcstring)+'#'+jetzt.getTime();
	*/
	var funcstring = "&sid=";
	for(var i=1; i < loadModule.arguments.length; i++) 
  		{ 
			funcstring+=loadModule.arguments[i];
			if((i+1) < loadModule.arguments.length) funcstring+='&';
		}
	location.href="index.html?cat="+id+funcstring;
}

function modinclude(id) {
	//var tc=
	if(modinclude.arguments.length > 1) sid = modinclude.arguments[1];
	else sid = "";
	
	$('maincontent').show();
	$('pageflip').hide();
	$('pageflip').update("");
	$('maincontent').innerHTML = loadingMainContent;
	new Ajax.Request('modinclude.php?kat='+id+'&sid='+sid,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('maincontent').update(t.responseText);
		   spanToFlash();
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

var lastrequest;

function history(func) {
  var jetzt = new Date();
  var tc=jetzt.getTime();
  var funcstring=func+"(";
  for(var i=1; i < history.arguments.length; i++) 
	{ 
		funcstring+='"'+history.arguments[i]+'"';
		if((i+1) < history.arguments.length) funcstring+=',';
	}
  funcstring+=')';
  $('historyframe').src='history.php?tc='+tc+'&callback='+escape(funcstring)+'#'+jetzt.getTime();
}

function setHash(hash){
	window.location.hash=hash;	
}



function spanToFlash() {
	if(sIFR != null && sIFR.replaceElement != null){
		sIFR.replaceElement("span.inhalt_header", "images/inhalt/arial.swf", "#727271", null, null, null, 0, 0, 0, 0, null, null, "transparent");
	}
}

function sizeToSession(breite,hoehe) {
	new Ajax.Request('ajax/sizeToSession.php?breite='+breite+'&hoehe='+hoehe, {
		method: 'get',	
		onSuccess: function(t) {
			//$('modulecontent').update(t.responseText);
		},
		onFailure: function(t) {
			//$('modulecontent').update('Error ' + t.status + ' -- ' + t.statusText);
		},
		evalScript: true,
		asynchronous: true
		}
	);
}

function reloadFotoLeiste(id) {
	new Ajax.Request('ajax/fotoleiste.php?id='+id,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('fotoleiste_content').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function showWelcome(){
	newOverflow=$('maincontent').style.overflow;
	$('maincontent').style.overflow='hidden';
	var welc_pos=$('maincontent').positionedOffset();
	/*alert($('haupttabelle').getWidth());
	
	new Ajax.Request('ajax/fotoleiste.php?id='+id,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('welcome').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);*/
	
	//alert("film wird geladen...");
	//var welc_dim=$('maincontent').getDimensions();
	//alert(welc_pos);
	//var welcl=$('welcome').cumulativeOffset();
	//alert(welcl);haupttabellewelc_pos[0]
	$('welcome').style.top=welc_pos[1]+"px";
	
	$('welcome').style.left="0px";
	/*$('trennschicht').style.height=($('maincontent').getHeight()+welc_pos[1])+"px";
	$('trennschicht').style.width=$('haupttabelle').getWidth()+"px";
	$('trennimg').style.width=$('haupttabelle').getWidth()+"px";
	$('trennimg').style.height=($('maincontent').getHeight()+welc_pos[1])+"px";
	$('trennschicht').show();*/
	$('welcome').style.height=($('maincontent').getHeight())+"px";
	//alert(welc_dim);
	//$('welcomefilm').style.height=$('maincontent').getHeight()+"px";
	$('welcome').style.width=$('haupttabelle').getWidth()+"px";
	//$('welcomefilm').style.zIndex='999';
	//alert($('welcome').positionedOffset());
	//window.setTimeout("$('welcome').clonePosition($('maincontent'),true,true,true,true);",500);
	$('welcome').show();
	//$('welcome').update("<script language='javascript'>"+
	//					"AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','"+$('haupttabelle').getWidth()+"','height','"+($('maincontent').getHeight()+welc_pos[1])+"','align','middle','src','flash/startseite.swf','quality','high','wmode','transparent','allowscriptaccess','sameDomain','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','flash/startseite.swf' );"+
	//					"</script>");
	if(ie) { $('welcome').update('<object id="welcomefilm" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+$('haupttabelle').getWidth()+'" height="'+($('maincontent').getHeight())+'">  <param name="movie" value="flash/startseite.swf">  <param name="quality" value="high">  <param name="wmode" value="transparent"> </object>');
	} else { $('welcome').update('<embed id="welcomefilm" src="flash/startseite.swf" wmode="transparent" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+$('haupttabelle').getWidth()+'" height="'+($('maincontent').getHeight())+'"></embed>'); }
		
	//$('welcomefilm').setAttribute("wmode","transparent"); //style.display="none";
//	$('welcomefilm').style.display="";
}
function hideWelcome(){
	if($('welcome')) {
		$('welcome').update("&nbsp;");
		$('welcome').hide();
		if(typeof newOverflow !== 'undefined') $('maincontent').style.overflow=newOverflow;
	}
}

/*
  ////////////////////////////////////////////////////////////////
 // GRAYBOX FUNKTIONEN										   //
////////////////////////////////////////////////////////////////
*/

function showGrayBox() {
	center('gray_box');	
	$('gray_box').show();
	//$('gray_box').className = 'op';
	new Effect.Fade('gray_box',
			{ duration: 1.0,  
			  from: 0.0, to: 0.99 });
	$('gray_overlay').show(); 
	hideSelect();
}

function hideGrayBox(){   
   new Effect.Opacity('gray_box',
			{ duration: 0.5, 
			  transition: Effect.Transitions.linear, 
			  from: 0.99, to: 0.0,
			  afterFinish: hidegb});
    setTimeout("$('gray_overlay').hide();",500);
	setTimeout("$('gray_overlay').style.height = '1px';",500);
	/*
	if($('fotogalerie_frame').$('objectleiste') || $('fotogalerie_frame').$('embedleiste')) {
		if(ie) $('fotogalerie_frame').$('objectleiste').SetVariable("signal",true);
		else $('fotogalerie_frame').$('embedleiste').SetVariable("signal",true);
	}*/
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	//alert(window.document.body.offsetHeight + " - " + document.body.clientHeight + " - " + document.documentElement.clientHeight + " - " + window.innerHeight + " - " + document.documentElement.scrollTop);
    
	element.style.position = 'absolute';
    element.style.zIndex   = 999;

    var elementDimensions = Element.getDimensions(element);

	//alert(elementDimensions.width + " " + element +" " + elementDimensions.height);
	topsize = arrayPageScroll[1] + ((arrayPageSize[3] - elementDimensions.height) / 2);
	if(topsize < 5) topsize = 5;
	
	element.style.top = (topsize + 'px');
	element.style.left = (((arrayPageSize[0] - elementDimensions.width) / 2) + 'px');
	
	//Größe verändern	
	if(ie) breite = arrayPageSize[0]+"px";
	else breite = "100%";
		
	$('gray_overlay').style.width = breite;
	$('gray_overlay').style.height = arrayPageSize[1]+"px";
	
	//alert(arrayPageSize[0] + " - " + arrayPageSize[1] + " - " + arrayPageSize[2] + " - " + arrayPageSize[3]);
	//alert(arrayPageScroll[0] + " - " + arrayPageScroll[1]);
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



function hideSelect() {
	try{
		selects = parent.document.getElementsByTagName( 'select' );
		selects = parent.document.getElementsByTagName( 'object' );
	}  catch (e) {
		selects = document.getElementsByTagName( 'select' );
		selects = document.getElementsByTagName( 'object' );
	}
   	for ( i = 0; i != selects.length; i++ )
	{
		selects[i].style.visibility = 'hidden';
    }
}

function showSelect() {
	selects = parent.document.getElementsByTagName( 'select' );
    for ( i = 0; i != selects.length; i++ )
	{
		selects[i].style.visibility = 'visible';
	}
	
	selects = parent.document.getElementsByTagName( 'object' );
    for ( i = 0; i != selects.length; i++ )
	{
		selects[i].style.visibility = 'visible';
	}
}
function hidegb() {
	$('gray_box').hide();
	showSelect();
	$('gray_box_content').update("<img src='images/loading/sw.gif' width='73' height='12' hspace='20' vspace='20' /><br />");
}

function showgb() {
	$('gray_box').show();
}

/*
  ////////////////////////////////////////////////////////////////
 // NAVIGATION FUNKTIONEN									   //
////////////////////////////////////////////////////////////////
*/

var actualTopNavi;
var actualSubNavi;
var navirt;
var navidt;

function naviDisplayTimeout(id) {
	window.clearTimeout(navirt);
	navidt = window.setTimeout("naviDisplayBottom('"+id+"');", 100);
}

function naviDisplaycTimeout() {
	navirt = window.setTimeout("restoreNavi();",1000);
	window.clearTimeout(navidt);
}

function naviDisplayBottom(id) {
	
	for(i = 0; i < document.getElementsByClassName("nav_top_aktiv").length; i++) {
		$(document.getElementsByClassName("nav_top_aktiv")[i]).className='nav_top_inaktiv';
	}
	
	for(i = 0; i < document.getElementsByClassName("nav_bottom_aktiv").length; i++) {
		$(document.getElementsByClassName("nav_bottom_aktiv")[i]).className='nav_bottom_inaktiv';
	}
	
	for(i = 0; i < $('navi_bottom').getElementsByTagName("div").length; i++) {
		$($('navi_bottom').getElementsByTagName("div")[i]).hide();
	}
	
	$("navi_bottom_"+id).show();
	$("nav_top_link_"+id).className = 'nav_top_aktiv';	
	
	
	//pfeile
	for(j = 0; j < mySlideNav.length; j++){
		if(mySlideNav[j]["key"] == id){
			if(mySlideNav[j]["ueberhang"] != 0)
				$("sliderpfeile").show();
			
			else
				$("sliderpfeile").hide();
			
		}
	}
	
}

function naviHoverBottom(id) {
	window.clearTimeout(navirt);
	for(i = 0; i < document.getElementsByClassName("nav_bottom_aktiv").length; i++) {
		$(document.getElementsByClassName("nav_bottom_aktiv")[i]).className='nav_bottom_inaktiv';
	}
	//actualSubNavi=id;
	$("nav_bottom_link_"+id).className = 'nav_bottom_aktiv';	
	//navirt = window.setTimeout("restoreNavi();",1000);
}

function restoreNavi(){
	//alert(actualTopNavi+ " - "+actualSubNavi);
	if(actualTopNavi>0){
		naviDisplayBottom(actualTopNavi);
	}
	if(actualSubNavi>0){
		naviHoverBottom(actualSubNavi);
	}
}
/*
  ////////////////////////////////////////////////////////////////
 // MODUL-SPEZIFISCHE FUNKTIONEN							   //
////////////////////////////////////////////////////////////////
*/

function neueZeichnung() {
	$("weitere_zeichnungen").insert($('template').innerHTML);
}

function loadProjektStep2() {
	/*if(loadProjektStep2.arguments.length>0) var lps_pre=loadProjektStep2.arguments[0];
	else var lps_pre="";*/
	new Ajax.Request('/ajax/projekt_step2.php',
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('loading').hide();
		   $('productlist').update(t.responseText);
		   
		},
		// Handle other errors
		onFailure: function(t) {
			$('productlist').update('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
	
}

function displayTeam(id) {
	Effect.toggle('team_'+id,'blind');
	
	if($('team_'+id).style.display == 'none') {
		$('team_plus_'+id).hide();	
		$('team_minus_'+id).show();
	} else {
		$('team_plus_'+id).show();	
		$('team_minus_'+id).hide();
	}
}


function displayMesseTermin(id) {
	Effect.toggle('messetermin_'+id,'blind');
	Effect.toggle('messebild_'+id,'blind');
	
	if($('messetermin_'+id).style.display == 'none') {
		$('messe_plus_'+id).hide();	
		$('messe_minus_'+id).show();
	} else {
		$('messe_plus_'+id).show();	
		$('messe_minus_'+id).hide();
	}
}

function displayEvent() { 
	for(var i=0; i < displayEvent.arguments.length; i++) 
	{ 
		displayMesseTermin(displayEvent.arguments[i]); 
	}		 
}

function loadMesseKalender(dir) {
	$('kalender_loading').show();
	new Ajax.Request('ajax/messeKalender.php',
	{
		method: 'get',
		parameters: 'dir='+dir,
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('messekalender').update(t.responseText);
		   $('kalender_loading').hide();
		},
		// Handle other errors
		onFailure: function(t) {
			$('messekalender').update('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function checkContact(reg) {
	$('loading').show();
	var ref = true;
	if(reg == undefined) ref = false;
	new Ajax.Request('ajax/kontakt.php?reg='+ref,
	{
		method: 'post',
		postBody: $('kontakt_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('loading').hide();	
		   $('kontakt_result').update(t.responseText);
		   $('kontakt_tr').show();
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function checkProjekt() {
	$('loading').show();
	new Ajax.Request('ajax/projekt.php',
	{
		method: 'post',
		postBody: $('projekt_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('loading').hide();	
		   $('projekt_result').update(t.responseText);
		   $('projekt_tr').show();
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}


function checkNewsletter() {
	$('loading').show();
	new Ajax.Request('ajax/newsletter.php',
	{
		method: 'post',
		postBody: $('newsletter_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('loading').hide();	
		   $('newsletter_result').update(t.responseText);
		   $('newsletter_tr').show();
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}


function callReferenz(id) {
	displayReferenz(id, 'refimage');
	displayReferenz(id, 'productlist');
	displayReferenz(id, 'reftitel');
}

function displayReferenz(id,typ) {
	
	if(typ != "reftitel") $(typ).innerHTML = "<table border='0' cellspacing='0' cellpadding='0' width='100%' height='100'><tr><td align='center'><img src='images/loading/sw.gif' /></td></tr></table>";
	new Ajax.Request('ajax/referenzen.php?id='+id+'&type='+typ,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $(typ).update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function projektHighlight(id1, id2, direct) {
	
	if(direct == "over") {
		$('refoverlay').show();
	} else {
		$('refoverlay').hide();
	}
	
	
	$('refoverlay').clonePosition($('box_'+id1+'_'+ id2));
	
	posref = $('refoverlay').style.top.replace("px","");
	pospl = $('ploverlay').style.top.replace("px","");
	posref_w = $('refoverlay').style.width.replace("px","");
	
	posref = parseInt(posref);
	pospl = parseInt(pospl);
	pos2 = $('box_'+id1+'_'+ id2).cumulativeScrollOffset();
	
	if(ie) {
		posref+= pos2[1];
		posref_w-= 16;
	}
	
	posref2 = posref + $('refoverlay').getHeight();
	pospl2 = pospl + $('ploverlay').getHeight();
	
	$('refoverlay').style.top = posref+"px";
	$('refoverlay').style.width = posref_w+"px";
	
	if(posref < pospl) {
		diff = pospl - posref;
		toppos = $('refoverlay').style.top.replace("px","");
		if((toppos + $('refoverlay').getHeight()) < pospl) {
			$('refoverlay').hide();
		} else {		
			$('refoverlay').style.top = $('ploverlay').style.top;
			$('refoverlay').style.height = ($('refoverlay').getHeight()) - diff + "px";
		}
	}
	
	if(pospl2 < posref2) {
		toppos = $('refoverlay').style.top.replace("px","");
		maxheight = pospl + $('ploverlay').getHeight();
		
		if(toppos > maxheight) {
			$('refoverlay').hide();
		} else {
			diff = 	posref2 - pospl2;
			$('refoverlay').style.height = ($('refoverlay').getHeight()) - diff + "px";
		}
	}

}

//********     PAGEFLIP      *********\\
function zoomPage(img,site){
	showGrayBox();
	new Ajax.Request('ajax/zoomPage.php?i='+img+'&s='+site,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	); 
}
//********		Bildergalerie		********\\

function zoomPic(img){
	showGrayBox();
	new Ajax.Request('ajax/zoomPic.php?i='+img,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}
function gbZoom(element){
	if(element.src){
		var timg=element.src.split("?i=");
		
		if(timg.length<2) return false;
		else{
			
			uimg=timg[1].split("&");
			img=uimg[0];
		
			showGrayBox();
			
			new Ajax.Request('ajax/zoomPic.php?i='+img,
			{
				method: 'get',
				asynchronous: true,
				evalScript: true,
				onComplete: function(t) {	
				   $('gray_box_content').update(t.responseText);
				   center('gray_box');
				},
				// Handle other errors
				onFailure: function(t) {
					alert('Error ' + t.status + ' -- ' + t.statusText);
				}		
			}
			);
		}
	}
}

function pgalerieZoom(img){
	if($('szenegalerie')){
		if($('szenegalerie').className!='imgborder') $('szenegalerie').className='imgborder';
		$('szenegalerie').src='images/php/rsz.php?i='+img+'&w=260&h=380&nofill=true';
	}
}

function callOnLoad() {
	$('main_table').cumulativeOffset();
	$('weltkarte_link').style.top = "58px";
	$('weltkarte_link').style.left = ((screenBreite-900)/2 +707)+"px";
	$('weltkarte_link').show();
	if(typeof sIFR == "function"){
        sIFR();
    };
	
	$('body').observe('mousemove', PUPS);
}

function callResizeFunctions() {
//	callOnLoad();
	//alert($('maincontent').style.paddingTop + " - " + $('maincontent').style.paddingBottom + " - " + $('maincontent').style.height);
	var arrayPageSize = getPageSize();
	if(ie) abzug = 147;
	else abzug = 147;
	
	if(ie) abzug2 = 173;
	else abzug2 = 187;
	
	
	
	var screenBreite = arrayPageSize[0];
	var screenHoehe = (arrayPageSize[3]-abzug);
	
	sizeToSession(screenBreite,screenHoehe);

	if(activeFotoLeiste == true) {
		$('maincontent').style.height=(screenHoehe-abzug2)+'px';	
		if($('productlist')) $('productlist').style.height=screenHoehe-198+'px';
	
	} else {
		$('maincontent').style.height=screenHoehe+'px';	
		if($('productlist') && ie) $('productlist').style.height=(screenHoehe-24)+'px';
		else if($('productlist')) $('productlist').style.height=(screenHoehe-11)+'px';
	}
	$('hiddenNavi').setStyle({display:'block',position:'absolute',top:'22px',left:((screenBreite-900)/2)+'px'});
	if($('userdata')){
	var user_pos=$('user_pos').cumulativeOffset();
	
	$('userdata').style.left=Math.floor(user_pos[0]+598)+"px";
	}
	$('weltkarte_link').style.left = ((screenBreite-900)/2 +707)+"px";
	//alert($('maincontent').style.paddingTop + " - " + $('maincontent').style.paddingBottom + " - " + $('maincontent').style.height);
	//alert(newOverflow);
	//$('maincontent').style.overflow=newOverflow;
	//alert($('productlist').style.height);
	
	//alert($('productlist').style.height);
}

// Login / WK

function logout(){
	userdata("&logout=true");
}

function userdata(){
	
	var typus = "";
	if($('userdata')){
		if(userdata.arguments.length>0){
			var pBody="&message="+userdata.arguments[0];
		}
		else if($('loginform')){
			var pBody=$('loginform').serialize();
			typus = "login";
		}	else if(userdata.arguments[0]) {
			var pBody="highlight="+userdata.arguments[0];
		}
		
		else var pBody="";
		
		new Ajax.Request('ajax/userdata.php',
		{
			method: 'post',
			postBody: pBody,
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {
				$('userdata').update(t.responseText);
				if(typus == "login"){					
					//reloadNavigation();	
				}
			},
			onFailure: function(t) {
				$('userdata').update('Error '+t.status+' -- '+t.statusText);
			}
		}
		);	
	}
}
var udatatimeout;
function userdata_message(msg){
	//alert(msg);				
	if(udatatimeout) window.clearTimeout(udatatimeout);
	var ud_pos=$('userdata').cumulativeOffset();
	//alert(ud_pos);
	$('userdata_message').style.top=Math.floor(ud_pos[1]+21)+"px";
	$('userdata_message').style.left=ud_pos[0]+"px";
	//$('userdata_message').style.width=$('userdata').getWidth()+"px";o
	//$('userdata_message').clonePosition($('userdata'), true, true, false, 21);
	//alert($('userdata_message').cumulativeOffset());
	
	//$('userdata_message').show();
	//var or_pos=$('wkimg'+art).cumulativeOffset();
	//$('wkbox'+art).style.left=(or_pos[0]-158)+"px";
	
	//
	// effect slide funzt nicht...position TOP ok...
	//
	
	//$('userdata_message').show();
	//alert($('userdata_message') + '\n' + $('userdata_message').style.display)
	$('userdata_message').update("<table border='0' cellspacing='0' cellpadding='0' width='100%'><tr><td align='left'><div>"+Base64.decode(msg)+"</div></td></tr></table>");
	//Effect.toggle('userdata_message');
	Effect.SlideDown('userdata_message',{
		duration:1,
		afterFinish: function(){ 
			udatatimeout=window.setTimeout("userdata_messageUP()",5000); 
		}
	});
}
function userdata_messageUP(){
	//Effect.toggle('userdata_message');
	Effect.SlideUp('userdata_message');
}


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 MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_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 updateProfil(){
	if($('profilform')){
		var pBody=$('profilform').serialize();
		new Ajax.Request('ajax/profil.php',
			{
				method: 'post',
				postBody: pBody,
				asynchronous: true,
				evalScript: true,
				onComplete: function(t) {
					$('profil_status').update(t.responseText);
				},
				onFailure: function(t) {
					$('profil_status').update('Error '+t.status+' -- '+t.statusText);
				}
			}
		);	
	}
}
function updateRabatt(){
	var pBody="&rabatt1="+$('rabatt1').value;
	new Ajax.Request('ajax/profil.php',
		{
			method: 'post',
			postBody: pBody,
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {
				$('profil_status').update(t.responseText);
			},
			onFailure: function(t) {
				$('profil_status').update('Error '+t.status+' -- '+t.statusText);
			}
		}
	);	
}

function openSucheLayer() {
	showSuche();
}

function searchSite(offset) {
	new Ajax.Request('ajax/searchToSession.php?search='+Base64.encode($('search').value),
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   	//loadModule(10, '&offset='+offset);
			
			if(offset == -1) {
				Effect.toggle('suche_inner','slide', {duration: 0.5, afterFinish: hideSuche});
				sucheAktiv = false;
			}
			//location.href="search.html?offset="+offset;
			//loadModule(10, "&offset="+offset);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);	
	
}

var sucheAktiv = false;
var sucheTimeout;

function showSuche() {	
	if(sucheAktiv == false) {
		window.clearTimeout(sucheTimeout);
		$('suche_layer').show();
		Effect.toggle('suche_inner','slide', {duration: 0.5});
		sucheTimeout=window.setTimeout("sucheAktiv = true;",500);
	} else {
		window.clearTimeout(sucheTimeout);
		Effect.toggle('suche_inner','slide', {duration: 0.5, afterFinish: hideSuche});
		sucheTimeout=window.setTimeout("sucheAktiv = false;",500);
	}
}

function hideSuche() {
	$('suche_layer').hide();
}

function downloadlist() {
	if($('downloadform') && $('downloadform')){
	$('downloadlist').update("<br><br><br><center><img src='images/loading/maincontent.gif'></center>");
	new Ajax.Request('ajax/downloadlist.php?',
		{
			postBody: $('downloadform').serialize(),
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {
				
			   $('downloadlist').update(t.responseText);
			   //center('gray_box');
			},
			// Handle other errors
			onFailure: function(t) {
				$('downloadlist').update('Error ' + t.status + ' -- ' + t.statusText);
			}		
		}
		);	
	}
	
	
	//loadModule(10, $('downloadform').value+'&offset='+offset);
	//if(offset == 0) Effect.toggle('suche_inner','slide', {duration: 0.5});
}
function download(file){
	if($('hiddenframe')){
		$('hiddenframe').src="download.php?"+file;	
	}
}


function empfehlen(kat,img,ext,send){
	showGrayBox();
	if(empfehlen.arguments.length>3) {
		new Ajax.Request('ajax/empfehlen.php?kat='+kat+'&img='+img+'&ext='+escape(unescape(ext)),
		{
			postBody: $('form_mailPage').serialize(),
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {
			   $('gray_box_content').update(t.responseText);
			   center('gray_box');
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}		
		}
		);			
	}else{
		new Ajax.Request('ajax/empfehlen.php?kat='+kat+'&img='+img+'&ext='+escape(unescape(ext)),
		{
			method: 'get',
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {	
			   $('gray_box_content').update(t.responseText);
			   center('gray_box');
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}		
		}
		); 
	}
}

function mailPage(kat,img,id){
	empfehlen(kat,img,escape('&swf_startPage='+id));
}

function op(element,opacity){
	element.style.MozOpacity=opacity/100;
	element.style.filter="Alpha(opacity="+opacity+")";
}

function UnCryptMailto(s) { //
var n=0;
var r="";
for(var i=0; i < s.length; i++) {
n=s.charCodeAt(i);
if (n>=8364) {n = 128;}
r += String.fromCharCode(n-(1));
}
return r;
}
// JS function for uncrypting spam-protected emails:
function linkTo_UnCryptMailto(s) { //
location.href=UnCryptMailto(s);
}

function pwVergessen() {
	showGrayBox();
	$('gray_box_content').update("<img src='images/loading/sw.gif' width='73' height='12' hspace='20' vspace='20' /><br />");
	new Ajax.Request('module/lostpw.php',
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}
function checkLostPw() {
	$('lostpw_loading').show();
	new Ajax.Request('ajax/lostpw.php',
	{
		method: 'post',
		postBody: $('lostpw_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('lostpw_loading').hide();	
		   $('lostpw_result').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function loadPageFlip() {
	if(loadPageFlip.arguments.length>0) var get=loadPageFlip.arguments[0];
	else var get="";
	$('maincontent').innerHTML = loadingMainContent;
	new Ajax.Request('ajax/pageflip.php?'+get,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('pageflip').update(t.responseText);
		   $('pageflip').show();
		   $('pageflip').style.height = "510px";
			$('maincontent').hide();
			$('maincontent').update("");
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

  ////////////////////////////////
 //  Mauspos				   //
////////////////////////////////

var mouse_xpos = 0;
var mouse_ypos = 0;

function PUPS(e){
	mouse_xpos = e.pointerX();
	mouse_ypos = e.pointerY();
}

  ////////////////////////////////
 //  Slidenavigation		   //
////////////////////////////////
	

function gNW(vv){
	return $("nav_bottom_link_"+vv).getDimensions().width;
}
function zeroOrMore(zahl){
	if(zahl<0) return 0;
	else return zahl;
}
function hundredOrLess(zahl){
	if(zahl>100) return 100;
	else return zahl;
}
function getRelativeMousePosToNavigation(){
	var x = $("body").getWidth()/2-450;
	return mouse_xpos-x;
}
function isMouseInYBereich(y1,y2){
	if(mouse_ypos > y1 && mouse_ypos < y2)
		return true;
	else
		return false;
}