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

/////////////////////////
 // Graybox Stuff Start //
/////////////////////////
function showGrayBox() {
	center('gray_box');
	$('gray_overlay').show();
	hideSelect();
    return false;
}

function linkTo_UnCryptMailto(s) { //
	location.href=UnCryptMailto(s);
}

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;
}

function hideGrayBox(){
    $('gray_box').hide();
    $('gray_overlay').hide();
	showSelect();
	 $('gray_box_content').innerHTML = '<img src="images/loading_small2.gif" /><img src="images/loading_font.gif" />';
    return false;
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	//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(window.document.body.offsetHeight + " - " + document.body.clientHeight + " - " + document.documentElement.clientHeight + " - " + window.innerHeight + " - " + document.documentElement.scrollTop);

	element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var elementDimensions = Element.getDimensions(element);

	//alert(elementDimensions.width + " " + element +" " + elementDimensions.height);

	element.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - elementDimensions.height) / 2) + 'px');
	element.style.left = (((arrayPageSize[0] - 20 - elementDimensions.width) / 2) + 'px');

    element.style.display  = 'block';

	//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;
}
/*
\\\\\\\\\\\\\\\\\\\\\\\\
 \\ Graybox Stuff ENDE \\
  \\\\\\\\\\\\\\\\\\\\\\\\
*/

function hideSelect() {
	selects = parent.document.getElementsByTagName( 'select' );
   	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';
	}
}

Xoffset=10;   // modify these values to ...
Yoffset=10;    // change the popup position.
document.onmousemove=get_mouse;

function popup(headline,text) {
	if(text != '') {
				var content= "<table border='0' width='240' cellspacing='0' cellpadding='2' style='border: solid 1px #eb0000;'><tr><td style='background-color: #eb0000; color: white; font-weight:bold;'>"+headline+"</td></tr><tr><td style='background-color: white;'>"+text+"</td></tr></table>";
				$('hoverdiv').innerHTML=content;
				$('hoverdiv').style.left=(x+Xoffset)+"px";
				$('hoverdiv').style.top=(y+Yoffset)+"px";
				$('hoverdiv').show();
	}
}

function get_mouse(e){
		if(!e) e = window.event;
		x = e.clientX+document.documentElement.scrollLeft;
		//	if (document.documentElement.scrollTop!=0) alert(document.documentElement.scrollTop );
    	y = e.clientY+document.documentElement.scrollTop ;
}
function kill(){
	$('hoverdiv').hide();
}

function startseite_changepic(pic){
	$('startseitenbild').replace("<img id='startseitenbild' width='568' height='300' src='"+pic+"' />");
}

function volltextsuche(start) {
	$('loadingmini').show();
	//$('volltext_result').innerHTML= '<img src="images/loading_small2.gif" /><img src="images/loading_font.gif" alt="" />';

	new Ajax.Request('ajax/volltextsuche.php?start='+start,	{
		method: 'post',
		parameters: $('volltext_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('volltext_result').update(t.responseText);
		   $('loadingmini').hide();
		},
		onFailure: function(t) {
			$('volltext_result').update('Error ' + t.status + ' -- ' + t.statusText);
			$('loadingmini').hide();
		}
	});
}

function dlLoad(offset) {
	$('downloads').innerHTML= '<img src="images/loading_small2.gif" /><img src="images/loading_font.gif" alt="" />';

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

var lastflashqs;

function reloadFlashBox(qs) {

	// Hide on thumbnailuebersicht.php?
	if (qs.indexOf('=-1')!=-1) {
		$('flashbox') && $('flashbox').hide();
		document.getElementById('vertikale_trennlinie').style.visibility='hidden';
	}
	else {
		document.getElementById('vertikale_trennlinie').style.visibility='visible';
		if($('flashbox')) {
			$('flashbox').hide();
			height = $('mainTable').getHeight();
			height-= 125;
			$('flashbox').show();

			new Ajax.Request('ajax/slidemenu.php?'+qs+'&minc=true&boxheight='+height,
			{
				method: 'get',
				asynchronous: true,
				evalScript: true,
				onComplete: function(t) {
				   	$('flashbox').update(t.responseText);
					$('slidemenu_frame').style.height = height+'px';
				   //window.setTimeout("resizeFlash();",100);
				   //window.setTimeout("resizeFlash();",500);
				   //window.setTimeout("resizeFlash();",1000);
				},
				// Handle other errors
				onFailure: function(t) {
					alert('Error ' + t.status + ' -- ' + t.statusText);
				}
			}
			);
		}
	}

	lastflashqs = qs;

	/*
	PageSize = getPageSize();
	$('slidemenu_frame').style.height = (PageSize[3]-120)+'px';
	$('slidemenu_frame').src='slidemenu.php?'+qs+'&minc=true&boxheight='+(PageSize[3]-120);
	lastflashqs = qs;
	*/
}

function resizeFlash(){
	/*
	if($('flashslide')) {
		bheight = document.viewport.getHeight()-132;
		$('flashslide').SetVariable("pheight", bheight);
		bheight2 = bheight + "px";
		$('flashslide').setStyle({height: bheight2});
		return bheight;
	}
	*/
	reloadFlashBox(lastflashqs);

}

function switchProduktfinder(ident) {
	$('produktfinder').src = 'images/produktfinder/'+ident+'.gif';
}

function produktFinderAjax(ebene,kat) {
	if(ebene == '1') {
		$('produktfinder_2').innerHTML = '';
	}
	$('produktfinder_'+ebene).innerHTML= '<center><img src="images/loading_small2.gif" /><img src="images/loading_font.gif" alt="" /></center>';

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

function thumb_hover(e, inout)
{
	if (inout) {
		e.kfOldWidth = e.width;
		e.kfOldHeight = e.height;
		e.width = Math.ceil(e.kfOldWidth/0.8);
		e.height = Math.ceil(e.kfOldHeight/0.8);
		e.style.marginLeft = '-'+(e.width-e.kfOldWidth)+'px';
		e.style.marginTop = '-'+(e.height-e.kfOldHeight)+'px';
		e.style.left = Math.round((e.width-e.kfOldWidth)/2.0)+'px';
		e.style.top = Math.round((e.height-e.kfOldHeight)/2.0)+'px';
	}
	else {
		e.width = e.kfOldWidth;
		e.height = e.kfOldHeight;
		e.style.marginLeft = '0';
		e.style.marginTop = '0';
		e.style.top = '0';
		e.style.left = '0';
	}
}

