var objektnr;
var hs;
var activespin = curr_spin;
var spinplayer = "applet";
var flashfilm;
var xpsp2 = false;

onerror = stopError;
function stopError() {
	return true;
}

function init () {

	xpsp2 = (window.navigator.userAgent.indexOf("SV1") != -1);

	
	if (anzahl_spins>1) {
		hs = new Array(anzahl_spins+1); 
		for (var a=1; a<=anzahl_spins; a++) {
			hs[a] = new Array(2);
		}

		setSpinPos();
	
		mhs1 = new Layer('hs1',false);
		mhs1.moveTo(hs[curr_spin][0],hs[curr_spin][1]);
		mhs1.setVis(true);

		for (h=1; h<=anzahl_spins; h++) {
			eval("mshs" + h +" = new Layer('shs" + h +"',false)");
			eval("mshs" + h + ".moveTo(hs[" + h + "][0],hs[" + h + "][1])");
			eval("mshs" + h + ".setVis(true)");
		}
	}

	checkApplet();
}
	
function checkApplet() {
	var re = /ptviewer/i;
	var text, showFlash;

	if (navigator.appName.indexOf("Netscape") != -1) {
		showFlash = (spin[0]['flash'] != "1" && navigator.javaEnabled()) ? false : true;
	} else {
		text = (spin[0]['flash'] != "1") ? document.getElementById('ptviewer').toString() : "";
		showFlash = (text.search(re) == -1) ? true : false;
	}

	if (showFlash) { 
		spinplayer = "flash";
		document.getElementById('spinDiv').innerHTML=writeFlashCode();
		flashfilm = document.getElementById('flashspin');
	}
}	


function getPano(s) {

	stopPanning ();
	if (is.macie) {
		parent.curr_spin = s;
		location.reload();		// lädt die Seite neu im Falle von MacIE
	} else {
		loaded = false;
		activespin = s;
		mhs1.moveTo(hs[s][0],hs[s][1]);
		
		if (spinplayer == "applet") {
			window.document.ptviewer.newPanoFromList(s-1);
		} else {
			curr_spin = s;
			document.getElementById('spinDiv').innerHTML=writeFlashCode();
		}
	}
	showHotspots(s);
}


function getPage(s) {

	stopPanning ();
	
	activespin = s;
	eval('document.location.href = "spin' + (s) + '.html";');
}


function mousehs(n) {
	if (navigator.appName.indexOf("Netscape") != -1) {
      		window.document.ptviewer.toggleHS();
      	}
}

var loaded = false;
var popupopen = false;
var popupwindow;
var target;

function hotspot(hsnr) {
	if (loaded || is.macie || spinplayer != "applet") {
		var panangle = Math.round(spin[activespin-1]['hotspot'][hsnr-1]['pos_x']  * 3.6 - 180);
		var tilt = Math.round(spin[activespin-1]['hotspot'][hsnr-1]['pos_y'] * -1.8 + 90);
		target = spin[activespin-1]['hotspot'][hsnr-1]['target'];
	
		if (spinplayer == "applet") {
		        if (document.ptviewer && !is.macie) {
				var curr_pan = document.ptviewer.pan();
				var diffangle = Math.abs(Math.round(curr_pan)-panangle);
				if (diffangle > 2) {
					if (navigator.appVersion.indexOf("Win") == -1 && document.all) {
					} else {
						document.ptviewer.moveTo(panangle,tilt,fov,30);
						document.ptviewer.waitWhilePanning();
					}
				}
		        }
		        eval(target);
		} else {
			eval(target);
/*			
			if (navigator.appName.indexOf("Netscape") == -1) {
				document.getElementById('flashspin').setVariable("angle",panangle);
				document.getElementById('flashspin').setVariable("hs",hsnr-1);
				document.getElementById('flashspin').GotoFrame(1);
			} else {
				eval(target);
			}
*/			
		}
	}
}

function callFromFlash() {
	eval(target);
}
	

function extLink(link) {
	 stopPanning();
	 var re = new RegExp ("mailto:", "i");
	 if (re.test(link)) {
	 	document.location.href = link;
	 } else {
	 	window.open(link, 'newWindow');
	 }
}


function stopPanning () {
       if (spinplayer == "applet" && document.ptviewer) {
		if (!is.macie) {
			document.ptviewer.stopAutoPan();
		}
	}
}


function anleitung() {
	stopPanning ();
	var popup = window.open('','Anleitung','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=300,height=300,');
	if (popup !=null) {
		var d = popup.document;
		d.write('<!doctype html public -//W3C//DTD HTML 4.0 Transitional//EN" http://www.w3.org/TR/REC-html40/loose.dtd><HTML><HEAD>');
		d.write('<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <TITLE>spin-Anleitung</TITLE> </HEAD> <BODY bgcolor="#FFFFFF" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">');
		d.write('<MAP name="control">');
		d.write('<AREA shape=rect coords="52,267,244,292"  alt="schliessen/close" href="javascript:window.close()">');
		d.write('</MAP>');
		d.write('<img src="images/anleitung.gif" width="300" height="300" border="0" usemap="#control">');
		d.write('</BODY></HTML>');
		d.close();
	}
}


function Is() {
	agent = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.mac = (agent.indexOf("mac")!=-1);
	this.ie = ((agent.indexOf("msie") != -1)&& (agent.indexOf('opera')==-1));
	this.macie = (this.mac && this.ie);
	this.firefox = (agent.indexOf("firefox")!=-1);
}

var is = new Is();

