// browser check ///////////////////////////////////

// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
// is_nav checks for navs earlier than version 6 (negg)
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_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                      (agt.indexOf("; nav") != -1)) );
var is_nav6 = (is_nav && (is_major == 5));*/
var is_nav6up = ((is_nav && (is_major >= 5)) || (agt.indexOf('gecko') != -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 IE = navigator.appName.indexOf("Microsoft") != -1;
var NS = navigator.appName.indexOf("Netscape") != -1;
var MAC = navigator.platform.indexOf("Mac") != -1;


// global variables /////////////////////////////////

var visible = (is_nav)? 'show':'visible';
var hidden = (is_nav)? 'hide':'hidden';

var imgWin; // leere Variable für openWin

// scrollTo Variablen
var fmTop = 200;
var cT = 0;

// popDiv und Zubehör
var mX = 0;
var mY = 0;
var	dX; // default delta-x for popups
var	dY; // default delta-y for popups
var popST;
var moveObj = "";
document.onmousemove = mousePosition;


if (is_nav) {
	document.captureEvents(Event.MOUSEMOVE);
}

document.onmousemove = mousePosition;


// global functions /////////////////////////////////

// Netscape resize fix (4.05- and Flash-proof)
// for details go to: http://www.aspekt1.net/dev/a1

function init() {
	if (is_nav) {	
		a1clientX = this.innerWidth;
		a1clientY = this.innerHeight;
		a1resizeFix();

	}
}

function a1resizeFix() { 
	if (is_nav) {
//   		alert(a1clientX + ", " + this.innerWidth + " | " + a1clientY + ", " + this.innerHeight);
		if  (a1clientY != this.innerHeight || a1clientX != this.innerWidth) {
			location.reload();
			a1clientY = this.innerHeight;
   			a1clientX = this.innerWidth;
		}	
	setTimeout("a1resizeFix()", 1000);	
	} 
}




// special functions ////////////////////////////////



// Schaltet die Visibility eines DIVs ein
//                                       
// whCont: übergeordnetes DIV (für Netscape)
// whObj:  einzublenden
function popDiv(whCont,whObj) {	
	if (is_nav) {
		(whCont)? document.layers[whCont].document.layers[whObj].visibility = visible : document.layers[whObj].visibility = visible;
	} else if (is_ie) {
		document.all[whObj].style.visibility = visible;
		document.all[whObj].blur(); //weg mit dem ekligen IE.mac-focus-rectangle !
	} else {
		obj = document.getElementById(whObj);
		obj.style.visibility = visible;
	}
}

// Schaltet die Visibility der Einblendfenster (Suche, Quickfinder, Kategorienumschalter) aus
function hideDiv(whCont,whObj) {	
	if (is_nav) {
		(whCont)? document.layers[whCont].document.layers[whObj].visibility = hidden : document.layers[whObj].visibility = hidden;
	} else if (is_ie) {
		document.all[whObj].style.visibility = hidden;
		document.all[whObj].blur();
	} else {
		obj = document.getElementById(whObj);
		obj.style.visibility = hidden;
	}
	
	if (popST) {
		clearTimeout(popST);
		popST = "";
	}
}
		
// form-at (by negg@aspekt1.net)
// Funktion zum Verschieben und Neusetzen des clip-rects bei Formularen
// whObj: ID des Objekts (hier 'fmReg')
// step: wieviele Seiten soll in welche Richtung geblätter werden (z.B. "1" = eine Seite vor, "-2" = zwei Seiten zurück
// fmRegTop ist initial "250", weil das DIV per style um 250px nach unten verschoben ist
// dieses Problem müßte man per style-Abfrage lösen, wenn noch weitere DIVs verschoben werden sollten
// function mTo lagert das Bewegen des DIVs aus scrollTo aus, um das Flackern in NS zu beseitigen, das auftritt, weil
// NS alle Aenderungen (clippen und Bewegen) erst nach Beendigung der Funktion ausfuehrt, so dass bestimmte form-Elemente
// kurz zu sehen sind, die nicht zu sehen sein sollten.

function scrollTo(step) {
	
	if (is_nav) obj = document.layers.fm; // (NS) Hier ist das Objekt hardscripted, läßt sich aber auch als Objekt übergeben, falls mal noch mehr DIVs gescrollt werden sollen
	else if (is_ie && !is_ie55up) obj = document.all.fm.style; // (IE)
	else obj = document.getElementById("fm").style; // NS6up
	step=step*327; // Jeder Step verschiebt das DIV um einen festen Betrag (327px)
	fmTop -= step; // setzt top auf den neuen Wert
	cT = cT + step;
	cB=cT+327;

	if (is_nav) { 
		obj.clip.top = cT;
		obj.clip.bottom = cB;
		
	} else {
			obj.clip = "rect("+cT+"px 605px "+cB+"px 0px)";
	}
	obj.visibility = hidden;
	if (is_nav) setTimeout("mTo();",10);
	else mTo(obj);
}

function mTo(obj) {
	if (is_nav) obj = document.layers.fm; 
	obj.top = fmTop; // Verschieben des DIVs			
	obj.visibility = visible;
	if (is_ie && MAC) { // Verhindert den IE.Mac-Bug, daß nach dem Bewegen eines Divs  die <select> Inhalte nicht mehr angezeigt werden
		document.all('fm').style.width = 501;
		document.all('fm').style.width = 500;
	}
	if (is_ie)	document.all.fm.blur();
}

// end form-at



// reading the mouse position /////////////////////////////////////////////////////////

function mousePosition(e) {
	if (is_nav || is_nav6up) {
		mX = e.pageX;
		mY = e.pageY;
	} else if (is_ie) {
		mX = event.x+document.body.scrollLeft-1;
		mY = event.y+document.body.scrollTop-3;
	}
	//status = "x: "+mX+" y: "+mY;
	return true
}

// pop the pop-Wins and the popup-Wins ////////////////////////////////////////////////

function popPop (whObj) {
	popST = setTimeout ("popToMouse(\""+whObj+"\")",100);
}

function popToMouse (whObj,dX,dY) {
	if (!dX) dX = 12;
	if (!dY) dY = 22;
	if (is_nav) {
		document.layers[whObj].left = mX+dX;
		document.layers[whObj].top = mY+dY;
	} else if (is_ie) {
		document.all[whObj].style.left = mX +dX;
		document.all[whObj].style.top = mY+dY;
	} else  {
		obj = document.getElementById(whObj);
		obj.style.left = mX +dX;
		obj.style.top = mY+dY;
	}
	dX = 12;
	dY = 22;
	popDiv("",whObj);
}


// open new window //////////////////////////////////////////////////////////////////////////
// we cannot change the window width and heigth after opening the window for different images, 
// because NS on Unix removes all Window elements and eventually crashes! So we close the window
// and reopen it. SetTimeout, because NS on Mac sometimes doesn't manage to open the window directly
// after closing it...
function goOut(url,winName,opts) {


	if(!opts) opts = "toolbar=1,location=1,directories=0,status=1,menuBar=1,scrollBars=1,resizable=1";
	
	
	if (winName=='imgWin') {
		windowOpen = winName+" = window.open('"+url+"','"+winName+"','"+opts+"')";
		setTimeout( windowOpen+"; "+winName+".focus()",100);
		setTimeout("imgWin.close()",110);
	}
	
	windowOpen = winName+" = window.open('"+url+"','"+winName+"','"+opts+"')";
	setTimeout( windowOpen+"; "+winName+".focus()",120);
	

}	

function dragOnEnd(){
	history.go(-1);
}


