function loadImg(obj){if(!obj.complete) setTimeout("loadImg("+obj+")",300);}
function enlarge(){
enlargements++;
if (LockCam){return;}  if (enlarged){return;}
var photo=document.getElementById("cam");
if (photo){
oldwidth=photo.style.width;
oldheight=photo.style.height;
photo.style.width=HotSpot[ActiveHotSpot].W + "px";
photo.style.height=HotSpot[ActiveHotSpot].H + "px";
photo.style.left=(lowresW - HotSpot[ActiveHotSpot].W)+"px";
photo.style.zIndex=300;
if (nHotSpots)
	photo.src=pathHiRes+HotSpot[ActiveHotSpot].OrigSrc;enlarged = true;}
}
function shrink(){
if(!enlarged) {return;}
if (LockCam){return;}
var photo = document.getElementById("cam");
if (photo){
photo.style.width=oldwidth;
photo.style.height=oldheight ;
photo.style.left=(lowresW-HotSpot[ActiveHotSpot].W2)+"px";
photo.src=pathImgsSource+HotSpot[ActiveHotSpot].OrigSrc;enlarged=false;}}
function toggle(){if(LockCam) LockCam = false; else LockCam = true;}
function LowLoaded(){LowCount++;}
var errorHappened = 0;
function LowLoadError(){errorHappened=1;LowLoad();}
function HiLoadError(){errorHappened=1;HiLoad();}
function LowLoad(){
	Proces = false;
}
function HiLoad(){
cnt='<img src="'+pathImgsSource+Limg[nowLoad]+'" id="Low'+nowLoad+'" onload="LowLoad();" onerror="LowLoadError();" idx="'+nowLoad+'"/>';
document.getElementById('c'+nowLoad).innerHTML = cnt;
}
function CheckLoad(){
	if(!Proces){
		if(Actualy < nHotSpots){
			if(Finished){
				if(Stack[ActiveHotSpot]!='complete'){nowLoad = ActiveHotSpot;} 
			else{	
				for(zz=0;zz<nHotSpots;zz++){if(Stack[zz] != 'complete') break;}
		nowLoad = zz;}
		cnt='<img src="'+pathHiRes+Limg[nowLoad]+'" id="Hi'+nowLoad+'" onload="HiLoad();"  onerror="HiLoadError();" idx="'+nowLoad+'"/>';
		document.getElementById('c' + nowLoad).innerHTML = cnt;
		Proces = true;
		Finished = false;}
	else{
		if(errorHappened || document.getElementById('Low' + nowLoad).complete){ //we do not stop loading after error happened
			errorHappened = 0;
			Finished = true;
			if(ActiveHotSpot==nowLoad) 
				document.getElementById('cam').src=document.getElementById('Low'+nowLoad).src;
			Stack[nowLoad]='complete';
			document.getElementById('cam'+ nowLoad).src=document.getElementById('Low'+nowLoad).src;
			Actualy++;
			}
		}
	}else clearTimeout(t);
	}
	if(Actualy<nHotSpots){
		t=setTimeout("CheckLoad()",50);
	}else {
	clearTimeout(t);
	}
}
function CheckImage(){LIcounter++;}
function changeLevel(newLevel){	
	var nl = new String(newLevel);
	var nlev = nl.indexOf("L");
	if (nlev == 0)
		newLevel=nl.charAt(1);
	document.getElementById('L' + ActiveLevel).style.display = 'none';

	window.status = 'cam' + Level[newLevel].First,'v' + Level[newLevel].First, Level[newLevel].First;
	if(nHotSpots) 
		OpenCam('cam' + Level[newLevel].First,'v' + Level[newLevel].First, Level[newLevel].First);
	newLevelObj=document.getElementById('L' + newLevel);
	if (newLevelObj){
		newLevelObj.style.display = '';
	newLevelObj.style.visibility = 'visible';}  
	activeLevelObj=document.getElementById('but_L' + ActiveLevel)
	if (activeLevelObj)
		activeLevelObj.src = Level[ActiveLevel].ButtImgs[0].src; 
	newLevelObj =   document.getElementById('but_L' + ActiveLevel);
	if (newLevelObj)
		newLevelObj.src = Level[ActiveLevel].ButtImgs[0].src;
	activeLevelObj =   document.getElementById('but_L' + newLevel)
	if (activeLevelObj)
		activeLevelObj.src =  Level[newLevel].ButtImgs[1].src; 
	ActiveLevel = newLevel;
	if (map) 
		map.checkResize();
	return newLevel;
}
function OpenCam(whyCam, NotInuse, NUMspot){
	photosOpen++;	
	if(!nHotSpots) 
		return;
	if(blinkTimeout) 
		clearTimeout(blinkTimeout);	
	document.getElementById('v' + ActiveHotSpot).style.visibility = 'visible'; 
	document.getElementById('v' + ActiveHotSpot).src = document.getElementById('vis'+ HotSpot[ActiveHotSpot].Dir).src;	
	ActiveHotSpot = NUMspot;
	document.getElementById('imgText').innerHTML = HotSpot[ActiveHotSpot].Note;
	vact = document.getElementById('v'+ActiveHotSpot);
	arrow = document.getElementById('act'+ HotSpot[ActiveHotSpot].Dir);
	vact.src = arrow.src;
	blinkTimeout = setTimeout("blinkoff('v" + ActiveHotSpot +"')", 400);	
	actCam = document.getElementById('cam');	
	if(isIE) 
		actCam.filters[0].Apply();
	if(enlarged){
		actCam.style.width=HotSpot[ActiveHotSpot].W + "px";	
		actCam.style.height=HotSpot[ActiveHotSpot].H + "px";		
		actCam.style.left=(lowresW - HotSpot[ActiveHotSpot].W)+"px";		
		actCam.src = pathHiRes+HotSpot[ActiveHotSpot].OrigSrc;
	  	
	}else{	
		actCam.style.left = (lowresW - HotSpot[ActiveHotSpot].W2)+"px";
		actCam.style.width = HotSpot[ActiveHotSpot].W2+"px";
		actCam.style.height = HotSpot[ActiveHotSpot].H2+"px";
		actCam.src = document.getElementById(whyCam).src;
		window.status = actCam.src+' show hotspot v' + NUMspot;
	}
	if(isIE) 
		actCam.filters[0].Play();
}
function blinkon(viewname){
var currentElement = document.getElementById(viewname);
if (currentElement) currentElement.style.visibility = 'visible';
clearTimeout(blinkTimeout);
blinkTimeout = setTimeout("blinkoff('" + viewname +"')", 400);
}
function blinkoff(viewname){
var currentElement = document.getElementById(viewname);
if (currentElement) currentElement.style.visibility = 'hidden';
clearTimeout(blinkTimeout);
blinkTimeout = setTimeout("blinkon('" + viewname +"')", 300);
}
function startslideshow(){
document.getElementById('CONTROLS').style.display = 'none';
document.getElementById('SHCONTROLS').style.display = '';
SlideShowAction = 'play';
SlideShowTimer = setTimeout("slideshow()", SlideTime);
}
function showplay(){
if(SlideShowAction == 'play'){
	clearTimeout(SlideShowTimer);
	SlideShowAction = 'pause';
	document.getElementById('showplay').src = 'http://www.pictureplan.info/g/player_support/showplay_on.gif';
}else{
	document.getElementById('showplay').src = 'http://www.pictureplan.info/g/player_support/showplay.gif';
	SlideShowAction = 'play';
	SlideShowTimer = setTimeout("slideshow()", SlideTime);}
}
function nextlevel( al)
{
		if (++al == Level.length)	
			al = 0;
		if (Level[al].ArrayLevel.length == 2 && Level[al].ArrayLevel[1] == 0)//skip map or other empty level
			return nextlevel(al);
		return al;	
}
function nextphoto(){
	var currentLevel = HotSpot[ActiveHotSpot].Level;
	var ii;
	for (ii = 0; ii < Level[currentLevel].ArrayLevel.length; ii++){
		if(HotSpot[Level[currentLevel].ArrayLevel[ii]].Name== HotSpot[ActiveHotSpot].Name)
		break;
	}
	if (++ii < Level[currentLevel].ArrayLevel.length){
		var nextID = Level[currentLevel].ArrayLevel[ii];
		OpenCam('cam' + nextID,'notinuse', nextID);
	} else {
		changeLevel('L'+nextlevel(ActiveLevel));
	}
}
function slideshow(){
clearTimeout(SlideShowTimer);
nextphoto();
SlideShowTimer = setTimeout("slideshow()", SlideTime);
}
function stopslideshow(){
clearTimeout(SlideShowTimer);
SlideShowAction = 'stop';
document.getElementById('SHCONTROLS').style.display = 'none';
document.getElementById('CONTROLS').style.display = '';
}
function recordSessionStart(){
var frequency = 5000;
loadtime = new Date();
var params = "code=START&start="+loadtime.getTime();
params = params + "&photosOpen="+photosOpen;
params = params + "&enlargements="+enlargements;
params = params + "&folder="+folder;
setInterval("recordStats("+frequency+")",frequency);
plcl = document.getElementById('perlcall');
plcl.src="http://www.pictureplan.info/orders/bin/recordstat.pl?"+params;
}
function recordStats(interval){
timeSpent += interval;
if (photosOpen > oldPhotosOpen){
oldPhotosOpen = photosOpen;
var params = "code=INT&duration="+timeSpent;
params = params + "&photosOpen="+photosOpen;
params = params + "&enlargements="+enlargements;
params = params + "&folder="+folder;
plcl = document.getElementById('perlcall');
plcl.src="http://www.pictureplan.info/orders/bin/recordstat.pl?"+params;}
}
function exitplayer(){
var now = new Date();
timeSpent = now.getTime()-loadtime.getTime();
var params = "code=END";
params = params + "&duration="+timeSpent;
params = params + "&photosOpen="+photosOpen;
params = params + "&enlargements="+enlargements;
params = params + "&folder="+folder;
plcl = document.getElementById('perlcall');
plcl.src="http://www.pictureplan.info/orders/bin/recordstat.pl?"+params;
}
function HotSpotObj(name,dir,note,num,level,x,y,w,h,imgsrc){
this.Name = name;
this.Dir = dir;
this.Note = note;
this.MyNum = num;
this.Level = level;
this.X = x;
this.Y = y;
this.W = w;
this.H = h;
this.W2 = w/2.238;
this.H2 = h/2.222;
this.ImgSrc = pathImgsSource + imgsrc;
this.OrigSrc = imgsrc;
nHotSpots++;
}
function LevelObj(name,arr,imgsrc,buttsrc){
this.Name = name;
this.First = arr[0];
this.ArrayLevel = arr;
this.ImgSrc = pathImgsSource + imgsrc;
this.ButtSrc = pathImgsSupport + buttsrc;
this.ButtImgs = new Array();
this.ButtImgs[0] = new Image();
this.ButtImgs[0].src = this.ButtSrc + 'off.gif';
this.ButtImgs[1] = new Image();
this.ButtImgs[1].src = this.ButtSrc + 'on.gif';
}
function tooltipoff(){
var tiptable = document.getElementById("tip");
if (tiptable ){tiptable.style.visibility ="hidden";}
}
function tooltipon(tip, xx, yy){
var tiptable = document.getElementById("tip");
if (tiptable){
tiptable.style.visibility ="visible";
tiptable.style.left = xx;
tiptable.style.top = yy;
tiptable.style.zIndex = 200;
tiptable.innerHTML = "<font face='Arial' size='2'>" + tip + "</font>";}
}
function customize(){
normalizeFonts();
var brokerlogo=document.getElementById('brokerlogo');
if(brokerlogo){brokerlogo.style.visibility="visible";}
var addr1=document.getElementById('address1');
if(addr1){addr1.style.visibility="visible";}
var email=document.getElementById('email');
if(email){email.style.visibility="visible";}
var email2=document.getElementById('email2');
if(email2)email2.style.visibility="visible";
}
function normalizeDescriptionFont(){
var desc = document.getElementById('agentform');
if(desc){
h=parseInt(desc.clientHeight);
if(h>descheight){
var pct=Math.round(descheight*100/h)+"%";
desc.style.fontSize=pct;
desc.style.visibility="visible";}}
}
function normalizeFonts(){
var agtnm1=document.getElementById('agentname1');
if(agtnm1){
agtnm1.style.visibility="visible";
w=parseInt(agtnm1.clientWidth);
var agtnm2=document.getElementById('agentname2');
if(agtnm2){
agtnm2.style.visibility="visible";
w2=parseInt(agtnm2.clientWidth);if(w2>w) w=w2;}
if(w>agentxtwidth){
pct=Math.round(agentxtwidth*100/w)+"%";
agtnm1.style.fontSize=pct;
if(agtnm2)agtnm2.style.fontSize=pct;}
}else{
var agtnm=document.getElementById('agentname');
if(agtnm){
w=parseInt(agtnm.clientWidth);
if(w>agentxtwidth){
pct=Math.round(agentxtwidth*100/w)+"%";
agtnm.style.fontSize=pct;}
agtnm.style.visibility="visible";}}
}
var cnt;
var loadtime;
var hireslocked;
var oldheight;
var oldwidth;
var nHotSpots=0;
var photosOpen=0;
var enlargements=0;
var oldPhotosOpen=0;
var timeSpent=0;
var lowresW=286;
var loadtime;
var ip;
var map;
Limg=new Array();
LowResLoaded=new Array();
HiResLoaded=new Array();
var ChckCount=0;
var LowCount=0;
var Actualy=0;
var Proces=false;
var Finished=true;
var LIcounter=0;
var ImportantHi=false;
var HotSpot=new Array();
var Level=new Array();
var SlideShowTimer='';
var SlideShowAction='stop';
var SlideTime=4000;
var LockCam=false;
var agentxtwidth=160;
var descheight = 190;
var blinkTimeout=0;
var enlarged=false;
var isIE=(navigator.appName=="Microsoft Internet Explorer");

