var isCSS, isW3C, isIE4, isOpera, isMac;

var activeLevel;
// constants
var activeLevelButtonPrfeix = "levelbutt";
var levButDnSrc;
var levButUpSrc;
var enlarButExSrc;
var enlarButSrc;
var reducButExSrc;
var reducButSrc;
var ActiveHotSpot;
var enlarged;
var firstMove = true;
var oldX, oldY;
var pathImgsSource='./lowres/';
var levelType = 0;
var curLevel;
var nHotSpots = 0;
var SlideShowCurrentStat = 0;
var SlideShowStatus = new Array();
var VisStatus = new Array();
var levels = new Array();
var HotSpot = new Array();
var originalLeft, originalTop;
var panEnabled = 0;
var zoomInEnabled = 1;
var zoomOutEnabled = 0;
var fitScreenEnabled = 0;
var newpref;
var vispref; 
var activepef;
var loading = "loading.gif";
var virtualPhotoId = "VirtualPhoto"
var counter = -1;
var levelChange = 0;
var deltaHSActive=72, deltaHS=8; // 1/2 of hotspot gifs width - init() should detect automatically
var slideTimeoutID = 0;
var currentZoomin;
var curLevelTransformValid, curLevelRXScale, curLevelRYScale, curLevelRX0, curLevelRY0;
var  curLevelEXScale, curLevelEYScale, curLevelEX0, curLevelEY0;
var firstTime = true;
var floorplanSlideLeft = 0;
var mapString = new RegExp("map","gi");
var infoString = new RegExp("info","gi");
var	mapIsActive = false;
var	infoIsActive = false; 
var levelTabFontColorUp = "white";
var levelTabFontColorDown = "black";
var OldPhotoH = 210;
var map;
var marker;
var smallPhotoH = 210;
var largePhotoH = 420;
var photosOpen=0;
var enlargements=0;
var googlehelp=0;
var oldPhotosOpen=0; 
var timeSpent=0;
var photoSeq='0,';
var floorplanner =0;
var slideshow =0;
var styleclass;
SlideShowStatus[0] = "play";
SlideShowStatus[1] = "stop";

var PrintVisEnabled = 0;
var C_DELETED = 1;
var C_ICONINVISIBLE = 2;
var C_PHOTOINVISIBLE = 4;
var C_NOENLARGEMENT= 8;
var C_GENERICIMAGE = 16;
VisStatus[0] = "none";
VisStatus[1] = "block";

function sniffBrowser()
{
	
	isCSS =  false;
	isW3C =  false;
	isIE4 =  false;
	isOpera = false; 
	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false; 
   if (navigator.appName == "Opera")
    	isOpera = true;
	if (document.images){
		if (document.body && document.body.style)
			isCSS =  true;
		if (isCSS && document.getElementById)
			isW3C = true;
		if (isCSS && document.all)
			isIE4 =  true;
	}
	return (isCSS || isIE4);
}
function getClipBottom(elem)
{
	var retval;
	var pix, bottom;
	if (isIE4 && !isOpera){
		bottom = getStyleValue(elem, 'clipBottom');
		pix = bottom.indexOf('p');
	} else {
		var vw = document.defaultView;
		var cStyle = vw.getComputedStyle(elem,"");
		var style = cStyle.getPropertyValue('clip');
		var firstComma = style.indexOf(',');
		var right = style.substring(firstComma + 2);
		pix = right.indexOf('p');
		bottom = right.substring(pix+3);
		pix = bottom.indexOf('p');
	}
	retval = bottom.substring(0, pix);
	return retval;
}
function getClipRight(elem)
{
	var retval;
	var pix, right;
	if (isIE4 && !isOpera){
		right = getStyleValue(elem, 'clipRight');
		pix = right.indexOf('p');
	} else {
		var vw = document.defaultView;
		var cStyle = vw.getComputedStyle(elem,"");
		var style = cStyle.getPropertyValue('clip');
		var firstComma = style.indexOf(',');
	 	right = style.substring(firstComma + 2);
		pix = right.indexOf('p');
	}
	retval = right.substring(0, pix);
	return retval;

}
function setStyleValue(elem, property, newval)
{
	if (isIE4 && !isOpera){
		elem.currentStyle[property]=newval;
	} else {
		var vw = document.defaultView;
		var cStyle = vw.getComputedStyle(elem,"");
		cStyle.setProperty(property, newval, "");
	}
}
function getStyleValue(elem, property)
{
	var retval;
	if (isIE4 && !isOpera){
		retval = elem.currentStyle[property];
	} else {
		var vw = document.defaultView;
		var cStyle = vw.getComputedStyle(elem,"");
		retval = cStyle.getPropertyValue(property);

	}
	return retval;
}

function moveElem(elem, dir, value)
{
	var curValue = getStyleValue(elem, dir);
	var pix = curValue.indexOf('p');
	var coord = parseInt(curValue.substring(0, pix), 10);
	coord += parseInt(value);
	coord += "px";
	if(dir == "top")
		elem.style.top = coord;
	else
		elem.style.left = coord;

}

function setPrefixes(newprefix, visprefix, activepefix, enlargeprefix)
{
	newpref = newprefix;
	vispref = visprefix; 
	actpref = activepefix;
	enlpref = enlargeprefix;
}


function ScrollLv(where)
{
	alert("scroll " +where);
}

function ShowInfo()
{
	// disable navigation
	var nvig = document.getElementById("navigation");
	if (nvig)
		nvig.style.display = "none";
	document.getElementById("info_tab").style.display="block";
	infoIsActive = true;

	// show main photo
   levels[activeLevel].HideHotSpots();
	OpenCam(0);
    levels[activeLevel].HideHotSpots();
	return true;
}
function HideInfo()
{	
   	document.getElementById("info_tab").style.display="none";
	var nvig = document.getElementById("navigation");
	if (nvig && !MapActive()){
		nvig.style.display = "block";
		updateNavigation();
	}
	infoIsActive = false;
	
}
function InfoOpen()
{
	return infoIsActive;
}

function ShowMap()
{
	// disable navigation
	var nvig = document.getElementById("navigation");
	if (nvig)
		nvig.style.display = "none";
	document.getElementById("mapcage").style.visibility="visible";
map.enableGoogleBar();
	// hide hotspots
   levels[activeLevel].HideHotSpots();
	// show main photo
	OpenCam(0);
   levels[activeLevel].HideHotSpots();
	mapIsActive = true;
	ShowGoogeHelp();
	return true;
}
function HideMap()
{	
   	document.getElementById("mapcage").style.visibility="hidden";
	var nvig = document.getElementById("navigation");
	if (nvig){
		nvig.style.display = "block";
		updateNavigation();
	}
	mapIsActive = false;
	HideGoogeHelp();

	
}
function MapActive()
{
	return mapIsActive;
}

function ShowBird( cage )
{
	// disable navigation
	var nvig = document.getElementById("navigation");
	if (nvig)
		nvig.style.display = "none";
	document.getElementById("birdcage").style.visibility="visible";
	// hide hotspots
   levels[activeLevel].HideHotSpots();
	// show main photo 
	OpenCam(0);
   levels[activeLevel].HideHotSpots();
	birdIsActive = true;
	return true;
}
function HideBird()
{	
   	document.getElementById("birdcage").style.visibility="hidden";
	var nvig = document.getElementById("navigation");
	if (nvig && !MapActive() && !InfoOpen()){
		nvig.style.display = "block";
		updateNavigation();
	}
	birdIsActive = false;
	HideGoogeHelp();

	
}

function BirdActive()
{
	return birdIsActive;
}

function GetMap(latitude, longitude)
         {
var map = null;

var LA = new VELatLong(latitude, longitude);

var pinPoint = null;
var pinPixel = null;
            mapb = new VEMap('birdcage');
            mapb.LoadMap(LA, 14, VEMapStyle.Birdseye, false, VEMapMode.Mode2D, true, 1);
            if(mapb.IsBirdseyeAvailable())
           		 mapb.LoadMap(LA, 14, VEMapStyle.Birdseye, false, VEMapMode.Mode2D, true, 1);
           	pinPoint = mapb.GetCenter();
            pinPixel = mapb.LatLongToPixel(pinPoint);
            mapb.AddPushpin(pinPoint);

			addLevel("mapb", "", "", 0, 0, 1.0, 1.0, 0, 0);
         }



function ShowNavigation(newlevel)
{
		if (levels[newlevel].enlargeable)
		document.getElementById('navigation').style.display="block";
	else 
		document.getElementById('navigation').style.display="none";

}
function ChangeLevel(newActive)
{
if ( newActive != activeLevel){
	var done = 0;
	var tab=document.getElementById("tab"+newActive);
	tab.src = supportPath+"/tabs_dn.gif";
	zIndexToStore = tab.style.zIndex;
	tab.style.zIndex = 600;
	tab = document.getElementById("tab"+activeLevel);
	tab.src = supportPath+"/tabs_up.gif";
	tab.style.zIndex = zIndexToStore ; 
	tab = document.getElementById("lab"+newActive);
	var oldHTML = tab.innerHTML;
	var re = new RegExp("black","gi");
	var newHTML = oldHTML.replace(re, "white");
	tab.innerHTML = newHTML;
	tab = document.getElementById("lab"+activeLevel);
	oldHTML = tab.innerHTML;
	re = new RegExp("white","gi");
	newHTML = oldHTML.replace(re, "black");
	tab.innerHTML = newHTML;
	oldZindex = zIndexToStore;
	levelChange = 1;
	if(mapString.length){
		if (document.getElementById("lab"+newActive).innerHTML.indexOf(mapString) != -1)
			ShowMap();
		else if (MapActive())
			HideMap();
		if (MapActive()){
			activeLevel = newActive;
			done=1;
		}
	}
		if(birdString.length){
		if (document.getElementById("lab"+newActive).innerHTML.indexOf(birdString) != -1)
			ShowBird();
		else if (BirdActive())
			HideBird();
		if (BirdActive()){
			activeLevel = newActive;
			done=1;
		}
	}

	if(infoString.length){
		if (document.getElementById("lab"+newActive).innerHTML.indexOf(infoString) != -1){
			ShowInfo();
		}
		else if (InfoOpen())
			HideInfo();
		if (InfoOpen()){
			activeLevel = newActive;
			done=1;
		}
	}
	if (done)
		return false;
	ShowNavigation(newActive);	 
	
	zoom_out()
	
	
	if (activeLevel < levels.length){
		window.status="active "+newActive;
 	   levels[activeLevel].HideHotSpots();
 	   levels[newActive].ShowHotSpots();
    }
		activeLevel = newActive;

	var planImg = document.getElementById("plan");
	planImg.src = levels[activeLevel].image.src;
	OpenCam(levels[activeLevel].hotspots[0].id);
	if(enlarged)
		setTimeout("moveElementsForSizeToggle("+enlarged+", "+0+")", 500);

}
return false;

}


function BgLoadingLow()
{ 
	if (counter >= 0 && counter < nHotSpots)
	{
		while (counter < nHotSpots && HotSpot[counter] == undefined)
			counter++;
		HotSpot[counter].Loaded = 1;
	}
	counter++;
	while (counter < nHotSpots && HotSpot[counter] != undefined && HotSpot[counter].Loaded) // it may be already loaded, skip until unloaded is found or reach the limit
		counter++;
	var el = document.getElementById(virtualPhotoId);
	if (counter < nHotSpots && HotSpot[counter] != undefined){
		cnt='<img  id="VirtualPhotograph" src="'+HotSpot[counter].ImgSrc+'" onload="BgLoadingHi();"  onerror="BgLoadingHi();">';
		el.innerHTML = cnt;
	}
}
function BgLoadingHi()
{ 
	cnt='<img  id="VirtualPhotograph" src="'+HotSpot[counter].OrigSrc+'" onload="BgLoadingLow();"  onerror="BgLoadingLow();"/>';
	document.getElementById(virtualPhotoId).innerHTML = cnt;
	
}


function LoadActivePhotoLow(id)
{
	cnt='<img id="'+id+'" src="'+HotSpot[ActiveHotSpot].ImgSrc+'" onload="BgLoadingLow();"  onerror="BgLoadingLow();"/>';
	document.getElementById(virtualPhotoId).innerHTML = cnt;
	document.getElementById("Photocell").innerHTML = cnt;
}
 
function LoadActivePhotoHi(id)
{
	cnt='<img id="'+id+'" src="'+HotSpot[ActiveHotSpot].OrigSrc+'" onload="BgLoadingLow();"  onerror="BgLoadingLow();"/>';
	document.getElementById(virtualPhotoId).innerHTML = cnt;
	document.getElementById("Photocell").innerHTML = cnt;
}


function BlinkOn(IDspot)
{
	if (document.getElementById(enlpref + IDspot))
		document.getElementById(enlpref + IDspot).style.display = 'block';
}
function BlinkOff(IDspot)
{
	if (document.getElementById(enlpref + IDspot))
		document.getElementById(enlpref + IDspot).style.display = 'none';
}
function HideEnlargementPrompt()
{
	if (document.getElementById('prompt_enlarge'))
		document.getElementById('prompt_enlarge').style.display='none';
}
function ShowEnlargementPrompt()
{
	if (document.getElementById('prompt_enlarge'))
		document.getElementById('prompt_enlarge').style.display='block';
}
function HideGoogeHelp()
{
	if (document.getElementById('google_help'))
		document.getElementById('google_help').style.display='none';
}
function ShowGoogeHelp()
{
	if (!googlehelp && document.getElementById('google_help'))
		document.getElementById('google_help').style.display='block';
	googlehelp = 1;
}
function OpenCam(IDspot){
helpPage = document.getElementById('helppage');
if (helpPage)
	helpPage.style.display = 'none'; 
if(editor == 0 && HotSpot[IDspot].visflag & C_DELETED){
	return;
}
	photosOpen++;	
	HideEnlargementPrompt();
	if (photosOpen == 4 && enlargements == 0 && nHotSpots > 4){
		ShowEnlargementPrompt();
	}
	photoSeq = photoSeq + IDspot +',';
// hide old actvive and new green or red
	document.getElementById(newpref + IDspot).style.display = 'none'; 
	document.getElementById(vispref+ IDspot).style.display = 'none'; 
	document.getElementById(actpref + ActiveHotSpot).style.display = 'none';
	BlinkOff(IDspot);
	
// show new active
if((HotSpot[IDspot].visflag & C_ICONINVISIBLE) == 0){
	if(!InfoOpen()){
		window.status=actpref+" opencam "+IDspot;
		document.getElementById(actpref + IDspot).style.display = 'block';	
	}
}

// show old active	
	if (levelChange == 0 )
		document.getElementById(vispref + ActiveHotSpot).style.display = 'block';
	if(!slideTimeoutID)
		levelChange = 0;
	ActiveHotSpot = IDspot;
	document.getElementById('DescriptionHeader').innerHTML = HotSpot[ActiveHotSpot].Note;
	document.getElementById('DescriptionBody').innerHTML = HotSpot[ActiveHotSpot].LongDescr;
	
	OldPhotoH =  document.getElementById('Photograph').height;
	changePhoto('PhotographTmp');
	Fade ('PhotographTmp', 0.05, 0, 1, 40, "changePhoto('Photograph')");

	var SizeButton = document.getElementById("PhotoSizeButton");
	if (SizeButton){
	if(HotSpot[IDspot].visflag & C_NOENLARGEMENT)
		SizeButton.style.visibility="hidden";
	else
		SizeButton.style.visibility="visible";
		}
if (editor){
	var inHtml = document.getElementById('PhotoButtonPrintable').innerHTML;
	var photoNameRegex= new RegExp("\\w+.jp\\w+");
	document.getElementById('PhotoButtonPrintable').innerHTML = inHtml.replace(photoNameRegex, photoNameRegex.exec(HotSpot[ActiveHotSpot].OrigSrc));;
}
	return;
	
}


function changePhoto(phtg)
{
	var pht = document.getElementById(phtg);
	HotSpot[ActiveHotSpot].visited = true;
	if( HotSpot[ActiveHotSpot].Loaded || phtg == "PhotographTmp")
		if (enlarged)
			pht.src =  HotSpot[ActiveHotSpot].OrigSrc;
		else 
			pht.src =  HotSpot[ActiveHotSpot].ImgSrc;
	else{
		pht.src = supportPath+'/'+loading;
		if (enlarged)
			LoadActivePhotoHi(phtg);
		else
			LoadActivePhotoLow(phtg);
	}
}

function showlevel(){}

function hidehotspots(){}
function  hidelevel(){}

function  getEX(){}
function getEY(){}

function  getRX(){}
function  getRY(){}


function level(ordinal, levelName, imagesrc, imagesrcE, contentWidth, width, height)
{
	this.clipbottom = getClipBottom(document.getElementById('floorplan_clip'));
	this.clipright = getClipRight(document.getElementById('floorplan_clip'));
		
	this.ordinal = ordinal;
	this.levelname = levelName;
	this.image = new Image();
	this.image.src = imagesrc;
	this.imageE = new Image();
	if (!imagesrcE==""){
		this.imageE.src = imagesrcE;
		this.enlargeable = 1;
	}
	else 
		this.enlargeable = 0;
	this.imageE.width = width;
	this.imageE.height = height;
	this.hotspots = new Array();
	this.AddHotSpot = addhotspot;
	this.ShowHotSpots = showhotspots;
	this.ShowLevel = showlevel;
	this.HideHotSpots = hidehotspots;
	this.TransformHotSpots = transformhotspots;
	this.HideLevel = hidelevel;
	this.size = "normal";
	this.contentWidth = contentWidth;
}



function HotSpotObj(id, note, longDescr, ex, ey, ordinal, visflag, imgsrc, dir){
	this.id = id;
	this.ordinal = ordinal;
	this.Note = note;
	this.LongDescr = longDescr;
	this.Loaded = 0;

	var curLevel = levels[levels.length - 1];
	this.Level = curLevel;
	curLevel.AddHotSpot(this);

if ((visflag & C_DELETED) == 0){
	var left=document.getElementById("r"+id).style.left;
	var pix = left.indexOf('p');
	this.NX = left.substring(0, pix);

	var top= document.getElementById("r"+id).style.top;
	pix = top.indexOf('p');
	this.NY = top.substring(0, pix);
}
	this.EX = ex;
	this.EY = ey;

if (visflag & C_GENERICIMAGE ){
// non -enlargeable too
	this.ImgSrc =  supportPath + '/' + imgsrc;
	this.OrigSrc = supportPath + '/' + imgsrc;
} else {
	this.ImgSrc = pathImgsSourceLoRes +'/'+ imgsrc;
	this.OrigSrc = pathImgsSourceHiRes + '/'+imgsrc;
}
	this.visited = false;
	this.visflag = visflag;
	this.dir = dir;
	nHotSpots++;
}

function addhotspot(hSpot)
{
	var curIndex = this.hotspots.length;
	hSpot.ind = curIndex;
	this.hotspots[curIndex] = hSpot;
}

function showhotspots()
{
	var ii, nHSpots = this.hotspots.length;
	window.status="nHSpots = "+nHSpots;
	for (ii = 0; ii < nHSpots; ii ++)
	{
		if(editor || (this.hotspots[ii].visflag & C_DELETED) == 0){
			var prefix = (this.hotspots[ii].visited)?'g':'r';
			var iHSpot = document.getElementById(prefix+this.hotspots[ii].id);
			window.status="nHSpots = "+iHSpot.style;
			iHSpot.style.display = "block";
		}
	}
}
function hidehotspots()
{
	var ii, nHSpots = this.hotspots.length;
	for (ii = 0; ii < nHSpots; ii ++)
	{
			var iHSpot = document.getElementById("r"+this.hotspots[ii].id);
			if (iHSpot){
				iHSpot.style.display = "none";
			}
			iHSpot = document.getElementById("s"+this.hotspots[ii].id);
			if (iHSpot)
				iHSpot.style.display = "none";
			iHSpot = document.getElementById("g"+this.hotspots[ii].id);
			if (iHSpot)
				iHSpot.style.display = "none";
		}	
}


function transformhotspots(toSize)
{
	var ii, newX, newY, newXA;
	var  nHSpots = this.hotspots.length;
	if (this.size != toSize)
	{
		this.size = toSize;
	
			for (ii = 0; ii < nHSpots; ii ++)
		{
if	((this.hotspots[ii].visflag & C_DELETED) == 0){   
	 
			if (toSize == "enlarge"){

				document.getElementById("r"+this.hotspots[ii].id).style.left = this.hotspots[ii].EX-8+"px";
				document.getElementById("r"+this.hotspots[ii].id).style.top = this.hotspots[ii].EY-8+"px";
				document.getElementById("g"+this.hotspots[ii].id).style.left = this.hotspots[ii].EX-8+"px";
				document.getElementById("g"+this.hotspots[ii].id).style.top = this.hotspots[ii].EY-8+"px";
				document.getElementById("s"+this.hotspots[ii].id).style.left = this.hotspots[ii].EX-86+"px";
				document.getElementById("s"+this.hotspots[ii].id).style.top = this.hotspots[ii].EY-86+"px";
				document.getElementById("e"+this.hotspots[ii].id).style.left = this.hotspots[ii].EX-15+"px";
				document.getElementById("e"+this.hotspots[ii].id).style.top =  this.hotspots[ii].EY-15+"px";
				//Math.floor(this.hotspots[ii].EY-40*Math.sin(pi/8*this.hotspots[ii].dir) - 15)+"px";
				//Math.floor(parseFloat(this.hotspots[ii].EX)+40*Math.cos(pi/8*this.hotspots[ii].dir) - 15)+"px";

			
			} else if (toSize == "reduce"){
				document.getElementById("r"+this.hotspots[ii].id).style.left = this.hotspots[ii].RX-8+"px";
				document.getElementById("r"+this.hotspots[ii].id).style.top = this.hotspots[ii].RY-8+"px";
				document.getElementById("g"+this.hotspots[ii].id).style.left = this.hotspots[ii].RX-8+"px";
				document.getElementById("g"+this.hotspots[ii].id).style.top = this.hotspots[ii].RY-8+"px";
				document.getElementById("s"+this.hotspots[ii].id).style.left = this.hotspots[ii].RX-86+"px";
				document.getElementById("s"+this.hotspots[ii].id).style.top = this.hotspots[ii].RY-86+"px";

				
			}  else {
				document.getElementById("r"+this.hotspots[ii].id).style.left = this.hotspots[ii].NX-8+"px";
				document.getElementById("r"+this.hotspots[ii].id).style.top = this.hotspots[ii].NY-8+"px";
				document.getElementById("g"+this.hotspots[ii].id).style.left = this.hotspots[ii].NX-8+"px";
				document.getElementById("g"+this.hotspots[ii].id).style.top = this.hotspots[ii].NY-8+"px";
				document.getElementById("s"+this.hotspots[ii].id).style.left = this.hotspots[ii].NX-86+"px";
				document.getElementById("s"+this.hotspots[ii].id).style.top = this.hotspots[ii].NY-86+"px";
				document.getElementById("e"+this.hotspots[ii].id).style.left = this.hotspots[ii].NX-15+"px";
				document.getElementById("e"+this.hotspots[ii].id).style.top =  this.hotspots[ii].NY-15+"px";
			} 
		}
			}
	}
}





function addLevel(levelName, imagesrc, imagesrcE, contentWidth, width, height)
{
     var oldlen = levels.length;
 	 levels[oldlen]= new level(oldlen, levelName, imagesrc, imagesrcE, contentWidth, width, height);

}

function storePlanOffset()
{
	var floorplan = document.getElementById("floorplancage");
	if (floorplan ){
		originalLeft = floorplan.offsetLeft;
		originalTop = floorplan.offsetTop;
	}
}
function restorePlanOffset()
{
	var floorplan = document.getElementById("floorplancage");
	if (floorplan ){
    	floorplan.style.left = originalLeft + "px";
   		floorplan.style.top = originalTop + "px";
 	}
}


function panDelta(deltaX, deltaY, elemen)
{
	elem = document.getElementById(elemen);
	if (elem  && panEnabled){
		if (elem.offsetLeft > 0 && deltaX > 0)
			deltaX = 0;
		if (elem.offsetTop > 0 && deltaY > 0){
			deltaY = 0;
			}
		if (!enlarged){
		if (elem.offsetTop < (levels[activeLevel].clipbottom - levels[activeLevel].imageE.height) && deltaY < 0){
				deltaY = 0;
				}
			if (elem.offsetLeft < levels[activeLevel].clipright - levels[activeLevel].imageE.width && deltaX < 0)
				deltaX = 0;
		}
      	elem.style.left = (elem.offsetLeft + deltaX) + "px";
   		elem.style.top = (elem.offsetTop + deltaY) + "px";
   		window.status = "OffsetX = "+elem.offsetLeft+" OffsetY = " + elem.offsetTop + " DX=" + deltaX + " DY=" +deltaY;
 	}
}
function pan(evt)
{
evt = (evt) ? evt :((window.event) ? event : 0);;

   var newX = evt.clientX, newY = evt.clientY;
   if (firstMove){
	  oldX = newX;
	  oldY = newY;
	  firstMove = false;
	  evt.cancelBubble = true;
	  return false;
   }
   var deltaX = newX - oldX, deltaY = newY - oldY;
   panDelta(deltaX, deltaY, "floorplancage");


	  oldX = newX;
	  oldY = newY;
  	  evt.cancelBubble = true;
	  return false;	

}
function noPan(e)
{
return false;
}
function endPan()
{
	var floorplan = document.getElementById("floorplancage");
	if (floorplan ){
	floorplan.style.cursor = "auto";
		floorplan.onmousemove = null;
	}
}

function startPan()
{
	var floorplan = document.getElementById("floorplancage");
	if (floorplan){
	    floorplan.style.cursor = "move";

		firstMove = true;

		floorplan.onmousemove=pan;
		floorplan.onmouseup=endPan;
	//floorplan.addEventListener("onmouseout", outPan, true);
	}

}

function adjustForPhotoHeght(oldH)
{
	var Photograph = document.getElementById("Photograph");
	var newH = Photograph.height;
	window.status = newH;
//	moveElem(document.getElementById("slideshowpanel"), "top", newH-oldH);
	if(!enlarged) // enlarged photo covers the description
		moveElem(document.getElementById("description"), "top", newH-oldH);

}

function moveElementsForSlideShow (enlarge, oldH)
{
	if(enlarge)
	{
		var Photograph = document.getElementById("Photograph");
		var base = document.getElementById("base");
		if ( levels[activeLevel].contentWidth >(base.width - Photograph.width))
			floorplanSlideLeftNew =  (base.width - Photograph.width)/2 - HotSpot[ActiveHotSpot].NX;
		else 
			floorplanSlideLeftNew =  (Photograph.width - base.width)/2;
		if (floorplanSlideLeftNew > 0)
			floorplanSlideLeftNew = 0;
		if (levelChange)
			floorplanSlideLeftNew = 0;
			
		moveElem(document.getElementById("floorplancage"), "left", floorplanSlideLeftNew - floorplanSlideLeft);
		floorplanSlideLeft = floorplanSlideLeftNew;
		var newH = Photograph.height;
//		moveElem(document.getElementById("slideshowpanel"), "top", newH-oldH);

	}
}
function moveElementsForSizeToggle( enlarge, oldH)
{	
	var Photograph = document.getElementById("Photograph");
	var base = document.getElementById("base");
	var newH = Photograph.height;
	if (enlarge){
		if ( levels[activeLevel].contentWidth >(base.width - Photograph.width))
			floorplanSlideLeft =  (base.width - Photograph.width)/2 - HotSpot[ActiveHotSpot].NX;
		else 
			floorplanSlideLeft =  (Photograph.width - base.width)/2;
			
		if (floorplanSlideLeft > 0)
			floorplanSlideLeft = 0;
		else {
			moveElem(document.getElementById("floorplancage"), "left", floorplanSlideLeft);
		}
	}
	else {
		floorplan = document.getElementById("floorplancage");
		moveElem(floorplan, "left",  - floorplan.offsetLeft);
		moveElem(floorplan, "top", - floorplan.offsetTop);
	}

}
function togglePhotoSize()
{
	var Photograph = document.getElementById("Photograph");
	var PhotographTmp = document.getElementById("PhotographTmp");
	var Photo = document.getElementById("Photo");
	var PhotoTmp = document.getElementById("PhotoTmp");
	var PhotoCage = document.getElementById("PhotoContainer");
	var SizeButton = document.getElementById("PhotoSizeButton");
	var plan = document.getElementById("plan");
	var base = document.getElementById("base");
 	var	oldH = Photograph.height;
	HideEnlargementPrompt();
	enlarged = 1 - enlarged;
	if (enlarged){
		enlargements++;
		Photograph.src = HotSpot[ActiveHotSpot].OrigSrc; 
		PhotographTmp.src =	HotSpot[ActiveHotSpot].OrigSrc;
	//	Photo.width = Photograph.width;
		SizeButton.className = "PhotoButtonReduce";
		Photo.className = "PhotoLarge";
		PhotoTmp.className = "PhotoLargeTmp";
		document.getElementById(actpref + ActiveHotSpot).style.display = 'block';
		zoom_out();
		panEnabled = 1;

	}
	else {
		Photograph.src = HotSpot[ActiveHotSpot].ImgSrc; 
		PhotographTmp.src =	HotSpot[ActiveHotSpot].ImgSrc;
		var newH = Photograph.height;
		SizeButton.className = "PhotoButtonEnlarge";	
		Photo.className = "PhotoSmall";
		PhotoTmp.className = "PhotoSmallTmp";
		document.getElementById(vispref + ActiveHotSpot).style.display = 'none';
		panEnabled = 0;

	}	  
	setTimeout("moveElementsForSizeToggle("+enlarged+", "+oldH+")", 500);

}

function addMap(lat, lng, scale, edit)
{
   document.getElementById("mapcage").style.visibility="hidden";
   //if (!GBrowserIsCompatible()){
   //	   alert("incompatible browser");
  // }
   var opts = {showOnLoad: true};
   
    map = new GMap2(document.getElementById("mapcage"), {googleBarOptions: opts});
	if (map){
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		var pt = new GLatLng(lat, lng);
		map.setCenter(pt, scale); 
//		map.enableGoogleBar();
		map.enableScrollWheelZoom();
		if (mapType == "Satellite")
			map.setMapType(G_SATELLITE_MAP);
		if (mapType == "Hybrid")
			map.setMapType(G_HYBRID_MAP);
		if (edit){
			marker = new GMarker(pt,{draggable: true})
			map.addOverlay(marker);
			marker.disableDragging();
			GEvent.addListener(map, 'singlerightclick', function(point,src,marker) { OpenMap4Edit(marker);} ); 
		} else {
			marker = new GMarker(pt)
			map.addOverlay(marker);
			GEvent.addListener(map, 'click', function(point,src,marker) { HideGoogeHelp();} ); 

		}
	}
	addLevel("map", "", "", 0, 0, 1.0, 1.0, 0, 0);
}
function addInfo()
{
	addLevel("info", "", "", 0, 0, 1.0, 1.0, 0, 0);

}
function GoTo(url)
{
	window.location.href = url;
}
function OverItem(id)
{
    var prt = document.getElementById(id);
    if(prt){
  	  	prt.className = "lineHiLite";
  	}
	
}
function OutItem(id)
{
    var prt = document.getElementById(id);
    if(prt){
  	  	prt.className = "lineRegular";
  	}
	
}

function TogglePrintable()
{
    var prt = document.getElementById('PrintTable');
    if(prt){
    	PrintVisEnabled = 1 - PrintVisEnabled;
  	  	prt.style.display = VisStatus[PrintVisEnabled];
 	}
}

function HidePrintable()
{
    var prt = document.getElementById('PrintTable');
    if(prt){
  	  prt.style.display = "none";
  	  PrintVisEnabled = 0;
  	}
}

function ToolTip(tip)
{
	window.status=tip;
}

var istooltipon = 0;
function tooltipoff()
{
 var tiptable = document.getElementById("tip");
 if (tiptable)
 	tiptable.style.visibility ="hidden";
}
function tooltipon(event, tip)
{
 var tiptable = document.getElementById("tip");
 var tiptext = document.getElementById("tiptext");
 if (tiptable && tiptext){
  	tiptable.style.left = event.clientX + 10;
 	tiptable.style.top = event.clientY - 5;
 		tiptable.style.zIndex = 800;
		tiptable.style.visibility ="visible";
 		tiptext.innerHTML= "<font face='Arial' size='2'>" + tip + "</font>";
 }
}


function SlideShowNext()
{
	window.status="Slide show next clicked";
	var newHS = (ActiveHotSpot+1)%nHotSpots;
	while (HotSpot[newHS].visflag & C_DELETED)
		newHS = (newHS+1)%nHotSpots;
	var phtg = document.getElementById('Photograph');
	if (HotSpot[newHS].Level.ordinal == activeLevel){
		OpenCam(newHS);	
		moveElementsForSlideShow (enlarged, phtg.height);
	}
	else {
		ChangeLevel(HotSpot[newHS].Level.ordinal);
		moveElementsForSlideShow (enlarged, phtg.height);
		levelChange = 0;
	}
	if (slideTimeoutID)
		clearTimeout (slideTimeoutID);
	slideTimeoutID = setTimeout("SlideShowNext()", 4000);
}
function SlideShowToggle()
{
	slideshow = 1;
	window.status="Slide show "+SlideShowStatus[SlideShowCurrentStat] + " clicked";
	SlideShowCurrentStat= 1 - SlideShowCurrentStat; 
	document.getElementById('showplay').src = supportPath + "/round_button_"+SlideShowStatus[SlideShowCurrentStat]+".gif";
	if (SlideShowCurrentStat)
		SlideShowNext();
	else
		clearTimeout(slideTimeoutID);
	
}
function SlideShowRewind()
{
	if (SlideShowCurrentStat){
		window.status="Slide show rewind clicked";
		OpenCam(0);	
		SlideShowNext();
	}
}

function EmailToFriend()
{
	window.status="Email clicked";
}
function ShowHelp()
{
	window.status="Help clicked";
}
function GoToCustomURL(url)
{
	window.status="Goto "+url;
}
function zoom_in()
{
	var planImg = document.getElementById("plan");
	planImg.src = levels[activeLevel].imageE.src;
	levels[activeLevel].TransformHotSpots("enlarge");
	panEnabled = 1;
	zoomInEnabled = 0;
	zoomOutEnabled = 1;
	fitScreenEnabled = 1;
	updateNavigation();

}
function zoom_out()
{
	restorePlanOffset();
	var planImg = document.getElementById("plan");
	planImg.src = levels[activeLevel].image.src;
	levels[activeLevel].TransformHotSpots("normal");
	panEnabled = 0;
	zoomInEnabled = 1;
	zoomOutEnabled = 0;
	fitScreenEnabled = 0;
	updateNavigation();
	floorplanSlideLeft = 0;
}
function fit_screen()
{
	window.status="Fit Screen clicked";
	zoom_out();
}
function printables()
{
	window.status="Printables clicked";
}
function getOpac(flag)
{	 
 var opacCoef=0.8;
 return (flag - 1.0)*opacCoef + 1.0;
}


function updateNavigation()
{
	  var pan_up = document.getElementById("pan_up");
	  var pan_lt = document.getElementById("pan_lt");
	  var pan_rt = document.getElementById("pan_rt");
	  var pan_dn = document.getElementById("pan_dn");
	  var zoom_in = document.getElementById("zoom_in");
	  var zoom_out = document.getElementById("zoom_out");
	  var fit_screen = document.getElementById("fit_screen");
	  if (pan_up && pan_lt && pan_rt && pan_dn && zoom_in && zoom_out && fit_screen){
	  if (isIE4){
	  	  panOpacity = getOpac(panEnabled) * 100 ;
	  	  var flt = "alpha(opacity="+panOpacity+")";
		  pan_up.style.filter = flt;
		  pan_lt.style.filter = flt;
		  pan_rt.style.filter = flt;
		  pan_dn.style.filter = flt;
		  zoomInOpacity = getOpac(zoomInEnabled) * 100 ;
		  zoomOutOpacity = getOpac(zoomOutEnabled) * 100 ;
		  fitScreenOpacity = getOpac(fitScreenEnabled) * 100;
		  zoom_in.style.filter = "alpha(opacity="+zoomInOpacity+")";
		  zoom_out.style.filter = "alpha(opacity="+zoomOutOpacity+")";
		  fit_screen.style.filter = "alpha(opacity="+fitScreenOpacity+")";
		  pan_up.style.opacity = getOpac(panEnabled);
		  pan_lt.style.opacity = getOpac(panEnabled);
		  pan_rt.style.opacity = getOpac(panEnabled);
		  pan_dn.style.opacity = getOpac(panEnabled);
		  zoom_in.style.opacity = getOpac(zoomInEnabled);
		  zoom_out.style.opacity = getOpac(zoomOutEnabled);
		  fit_screen.style.opacity = getOpac(fitScreenEnabled);

	  } else if (isCSS){
		  pan_up.style.MozOpacity = getOpac(panEnabled);
		  pan_lt.style.MozOpacity = getOpac(panEnabled);
		  pan_rt.style.MozOpacity = getOpac(panEnabled);
		  pan_dn.style.MozOpacity = getOpac(panEnabled);
		  zoom_in.style.MozOpacity = getOpac(zoomInEnabled);
		  zoom_out.style.MozOpacity = getOpac(zoomOutEnabled);
		  fit_screen.style.MozOpacity = getOpac(fitScreenEnabled);
	  	  
	  } else {
	  	  ;
	  }
	  }
}
function dissolve()
{
	if(!isMac)
		setTimeout("Fade('loadingpage', 0.05, 1.0, 0.0, 40, '')", 1500); 
}

function Fade(id, step, value, limit, timeout, executeString)
{
	var element = document.getElementById(id)
	//alert ("Fade('" + id+"', '" + step+"', '"+ value +"', '" + limit+"', '"+ timeout+"', \""+ executeString +"\")");
	if (isIE4){
		  newOpacity = value * 100 ;
		  element.style.filter = "alpha(opacity="+newOpacity+")";
	  } else if (isCSS){
		  element.style.opacity = value;
	  }
	 	  value = parseFloat(step) + parseFloat(value);
	  if (step > 0 && value < limit || step < 0 && value > limit)
	  	  setTimeout("Fade('" + id+"', '" + step+"', '"+ value +"', '" + limit+"', '"+ timeout+"', \""+ executeString +"\")", timeout);
	  
	  else {
	  	  if (executeString != "") {
	  			setTimeout(executeString,10);
	  		}
	  }
}

function getStyleFromSheets(styleId)
{
  var Styles = new Array();
  var sheets = new Array();
  sheets = document.styleSheets;
 var stringstyles = "";
  for (kk = 0 ; kk <sheets.length; kk++){
	if (isIE4)
		  Styles = document.styleSheets[kk].rules;
	  else{
		  Styles = document.styleSheets[kk].cssRules;
		}
	  for (i=0;i<Styles.length;i++){
	  	  var selText = Styles[i].selectorText;
 		if (selText.toLowerCase() == styleId.toLowerCase()){
			return Styles[i];
			} 
		  }
  }
 return 0;
}
var nextXStep =0, nextYStep=0;  

function ZoomIn(id, initScale)
{
var elem = document.getElementById(id)
var left = elem.offsetLeft;
var top = elem.offsetTop;
var width = elem.offsetWidth;
var height = elem.offsetHeight;
top = top - (height - 480)/2;
left = left - (width - 640)/2;
elem.style.top = top+"px";
elem.style.left = left+"px";
elem.style.zIndex = 1200;
elem.style.visibility = "visible";
Fade (id, 0.1, 0, 1, 40, "pauseSplash()");
}

function pauseSplash()
{
	setTimeout("fadeSplash()",2500);
}
function ZoomIn_(id, initScale)
{
var elem = document.getElementById(id)
var left = elem.offsetLeft;
var top = elem.offsetTop;
var width = elem.offsetWidth;
var height = elem.offsetHeight;
top = top - (height - 480)/2;
left = left + (640  - width)/2;
sniffBrowser();
elem.style.visibility = "visible";
elem.style.top = parseInt(top - (initScale-1)*height/2)+"px";;
elem.style.left = parseInt(left - (initScale-1)*width/2)+"px";

 ZoomDown (id,3, width*initScale, height*initScale, width, 10, "fadeSplash()");
}

function ZoomDown (id, step, width, height, limit, timeout, executeString)
{
	var element = document.getElementById(id);
	element.style.width = width;
	element.style.height= height;
	
	nextXStep += parseFloat(step / 2);
	nextYStep += parseFloat(step * parseFloat(height / (2 * width)));
	moveElem(element,"top", nextYStep  );
	moveElem(element,"left", nextXStep  );
	width -= 2*parseInt(nextXStep);
	height -= 2*parseInt(nextYStep);
	nextXStep -= parseInt(nextXStep);
	nextYStep -= parseInt(nextYStep);
	timeout = timeout*0.95;
	if (step < 0 && width < limit || step > 0 && width> limit)
	  	  setTimeout("ZoomDown ('" + id+"', '" + step+"', '"+ width +"', '"+ height +"', '" + limit+"', '"+ timeout+"', \""+ executeString +"\")", timeout);
	 else {
	  	 if (executeString != "") {
	  			setTimeout(executeString,4000);
	  		}
	  }

}

function hideSplash()
{
	document.getElementById("splash1").style.display="none";
}

function fadeSplash() 
{
	document.getElementById("loadingpage").style.display="none";
	staticTable = document.getElementById("agentNameTableStatic");
	staticTable.className="fadingSplash";
	staticTable = document.getElementById("addressTableStatic");
    styleclass = getStyleFromSheets(".fadingSplash"); 
	Fade('pctr', -0.05, 1.0, 0.0, 60, '');
	FadeClass(".fadingSplash", -0.05, 1.0, 0, 40, "hideSplash()");

//

}
function FadeClass(classid, step, value, limit, timeout, executeString)
{
	
	if (isIE4){
		  newOpacity = value * 100 ;
		  styleclass.style.filter = "alpha(opacity="+newOpacity+")";
	  } else{
		  styleclass.style.opacity = value;
	  }
	  value = parseFloat(step) + parseFloat(value);
	  if ((step > 0 && value < limit) || (step < 0 && value > limit)){
	  	  setTimeout("FadeClass('" + classid+"', '" + step+"', '"+ value +"', '" + limit+"', '"+ timeout+"', \""+ executeString +"\")", timeout);
	  	  }
	  
	  else {
	  	  if (executeString != "") {
	  			setTimeout(executeString,10);
	  		}
	  }
}

