// JavaScript Document
// definitions and initalizations of global variables stored in TOP frame
//

var ie5=document.all&&document.getElementById;
var ns6=document.getElementById&&!document.all;

var styleName = "style.css";
var aLWMwindow = null;

// ******** variables storing info about actual data
var actualMarkerID = -1;
var actualContentID = -1;
var actualContentType = "none"; // "PHOTO", "PANORAMA", "3DMODEL"
var actualContentFilename = "empty.gif";
var actualContentPath = "";
var actualContentFilepath = " ";
var actualContentThumbnailFilename = "tn_empty.gif";
var actualContentTitle = "empty Title";
var actualContentCopyrights = "Martin Zeman &copy; 2003";  
var actualContentLoaded = false;
var actualContentWidth = 10;
var actualContentHeight = 20;

var actualContentFloating = "";
var actualContentFixed = "";
var actualContentMaximized = "";
var actualContentVisible = false;

var actualLayeredWindowFloating = true;
var actualLayeredWindowMaximized = false;
var actualLayeredWindowFixed = false;

var actualLayeredWindowFloatingPosition = "topright";
var actualLayeredWindowIcons = "pos_switch maximize close ";

var b_info = false;
var b_user = true;

// ************************************* FUNCTIONS

var mapframe = null;
var menuframe = null;

function getStyleName(){
	return styleName;
}

function HideElement(ElementID,frame) {
	frame.document.getElementById(ElementID).style.display="none";
}

function ShowElement(ElementID,frame){
	frame.document.getElementById(ElementID).style.display="";
}

// application dependent
function OpenWindowWithActualContent(relPath) {
	//alert("OpenWindowWithActualContent " + relPath + " - " + actualContentType);
//	alert(relPath + " - " + actualContentType + " - " + actualContentFilepath + " - " + actualContentFilename + " - " + actualContentTitle + " - " + actualContentCopyrights);// + " - " + 'Virtual 3D Bratislava - VrBA 3D' + " - " + styleName + " - " + actualContentWidth + " - " + actualContentHeight);
	aLWMwindow = OpenWindowWithMedia2(relPath,actualContentType,actualContentFilepath+actualContentFilename,actualContentTitle,actualContentCopyrights,'Virtual 3D Bratislava - VrBA 3D',styleName,false,actualContentWidth,actualContentHeight);
/*	if (actualContentType == 'PHOTO') {
		aLWMwindow = OpenWindowWithCopyrightedImage(relPath,actualContentFilepath+actualContentFilename,actualContentTitle,actualContentCopyrights,'Virtual 3D Bratislava - VrBA 3D',styleName,false);
	}
	if (actualContentType == 'PANORAMA') {
		aLWMwindow = OpenWindowWithCopyrightedPanorama(relPath,actualContentFilepath+actualContentFilename,actualContentTitle,actualContentCopyrights,'Virtual 3D Bratislava - VrBA 3D',styleName,false,actualContentWidth,actualContentHeight);		
	}
	if (actualContentType == '3DMODEL') {
		aLWMwindow = OpenWindowWithCopyrightedVRML(relPath,actualContentFilepath+actualContentFilename,actualContentTitle,actualContentCopyrights,'Virtual 3D Bratislava - VrBA 3D',styleName,false,actualContentWidth,actualContentHeight);				
	}
	if (actualContentType == 'MOVIE') {
		aLWMwindow = OpenWindowWithCopyrightedMovie(relPath,actualContentFilepath+actualContentFilename,actualContentTitle,actualContentCopyrights,'Virtual 3D Bratislava - VrBA 3D',styleName,false,actualContentWidth,actualContentHeight);		
	}
	*/
}

function SetLayeredWindowSize(ElementID,frame,width,height){
	
	frame.document.getElementById(ElementID).style.width = width;
	frame.document.getElementById(ElementID).style.height = height;
}

// application dependent
function ShowHideLayeredWindows(relPath){
	//alert("ShowHideLayeredWindows " + relPath + " " + actualContentLoaded + " - " + actualContentVisible);
	if (actualContentLoaded && actualContentVisible) {
		if (actualLayeredWindowFloating) {
			ShowElement("layeredWindow",top.main.pages.cframe);
			top.main.pages.cframe.PositionCheckTimer2();
		} else {
			HideElement("layeredWindow",top.main.pages.cframe);			
		}

		if (actualLayeredWindowFixed) {
			ShowElement("layeredWindow",top.main.menu);
		} else {
			HideElement("layeredWindow",top.main.menu);			
		}

		if (aLWMwindow) {
			//alert("closing maximized");
			aLWMwindow.close();
		}
		
		if (actualLayeredWindowMaximized) {
			//if (aLWMwindow.opener) aLWMwindow.close();
			//alert("OpenMAXIMIZED");			
			OpenWindowWithActualContent(relPath);
			//alert(top.actualContentVisible);
			//alert(top.actualLayeredWindowMaximized);
			//top.actualContentVisible = true;
			//top.actualLayeredWindowMaximized = true;	
	//		alert(top.actualContentVisible);
	//		alert(top.actualLayeredWindowMaximized);
		}

	} else {
		if (actualContentLoaded) {
			HideElement("layeredWindow",top.main.pages.cframe);
			//actualLayeredWindowFloating = false;
			HideElement("layeredWindow",top.main.menu);
			//actualLayeredWindowFixed = false;		
			
			if (aLWMwindow) aLWMwindow.close();
			//actualLayeredWindowMaximized = false;		
			
		}			
	}

}

function ShowLayeredWindow(){
	actualContentVisible = true;
	ShowHideLayeredWindows();
}

function HideLayeredWindow(){
	actualContentVisible = false;
	ShowHideLayeredWindows();
}

function fun_close(LayeredWindowID,frameString){
	HideLayeredWindow();
}

function fun_open(LayeredWindowID,frameString){
	ShowLayeredWindow();
}

function fun_pos_switch(LayeredWindowID,frameString){
	if (actualLayeredWindowFloating) {
		//alert("big->small " + frameString + actualContentVisible);
		actualLayeredWindowFloating = false;
		UnLoadContentFromLayeredWindow("layeredWindow","top.main.pages.cframe");
		actualLayeredWindowFixed = true;
	}
	else {
		//alert("small->big " + frameString);
		actualLayeredWindowFloating = true;
		UnLoadContentFromLayeredWindow("layeredWindow","top.main.menu");
		actualLayeredWindowFixed = false;
	}
	frame = eval(frameString);
	LoadActualContent();
	ShowHideLayeredWindows(frame.relativePath);	
}

function fun_maximize(LayeredWindowID,frameString){
	/*if (actualContentType == 1) {
		frame = eval(frameString);
		OpenWindowWithActualContent(frame.relativePath);
	}*/
	//alert('maximize');
	frame = eval(frameString);
	//HideLayeredWindow();
	actualLayeredWindowFloating = false;
	actualLayeredWindowFixed = false;	
	actualLayeredWindowMaximized = true;
	ShowHideLayeredWindows(frame.relativePath);	
//	OpenWindowWithActualContent(frame.relativePath);
}

function fun_minimize(){
	actualLayeredWindowMaximized = false;
	actualLayereeWindowFloating = true;
	actualLayeredWindowFixed = false;
	//actualContentVisible = true;
	LoadActualContent();
	ShowActualContent(mapframe.relativePath);
}

/*function fun_position_switch(LayeredWindowID,frameString){
	frame = eval(frameString);
	if (actualLayeredWindowFloatingPosition == "top_left") {
		actualLayeredWindowFloatingPosition = "topright";
		frame.document.getElementById("position_switch").src = frame.relativePath+ "images/wintools/to_left.gif";
	}
	else {
		actualLayeredWindowFloatingPosition = "topleft";
		frame.document.getElementById("position").src = frame.relativePath + "images/wintools/to_right.gif";
	}
}*/

function fun_position_switch(LayeredWindowID,frameString){
	//frame = eval(frameString);
	if (actualLayeredWindowFloatingPosition == "topleft") {
		actualLayeredWindowFloatingPosition = "topright";		
		//frame.document.getElementById("position_switch").src = frame.relativePath + "images/wintools/to_left.gif";
	}
	else {
		actualLayeredWindowFloatingPosition = "topleft";
		//frame.document.getElementById("position_switch").src = frame.relativePath + "images/wintools/to_right.gif";
	}
}

function getIcons(LayeredWindowID,frameString,relPath,icons){

	tmpString = icons;
	outputString = "";
	separatorPosition = tmpString.indexOf(' ');
	while (separatorPosition > 0) {
		iconString = tmpString.substring(0,separatorPosition);
		outputString = outputString + '<img src="'+relPath+'images/wintools/'+iconString+'.gif" id="'+iconString+'" onClick="top.fun_'+iconString+'('+"'"+LayeredWindowID+"','"+frameString+"'"+')" height="9" width="9">&nbsp;';
		tmpString = tmpString.substring(separatorPosition+1,tmpString.length);		
		separatorPosition = tmpString.indexOf(' ');
		//alert(tmpString);
	}
//	alert(outputString);
	return outputString;	
}

function getContent(LayeredWindowID,frameString,relativePath,type,width,height,filename,filepath){
	var outputString = "";
	
	if (type == 'PHOTO') {
		outputString = '<a href="javascript:top.fun_maximize('+"'"+LayeredWindowID+"','"+frameString+"'"+');"><img style="cursor:help" src="'+relativePath+filepath+filename+'" id="imagecell" alt="" height="'+height.toString()+'" width="'+width.toString()+'" border="0"></a>';
	}

	if (type == 'PANORAMA') {
	 		outputString = '<object id="PANORAMA" CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" \
				style="position: relative; left: 0; top: 0; width: '+width.toString()+'; height: '+height.toString()+';">\
				<param name="SRC" VALUE="'+relativePath+filepath+filename+'">\
				<param name="AUTOPLAY" VALUE="true">\
				<param name="CONTROLLER" VALUE="true">\
				<param name="SCALE" VALUE="tofit">\
				<param name="autohref" value="true">\
				<param name="playeveryframe" value="true">\
				<param name="enablejavascript" value="true">\
				<param name="dontflattenwhensaving" value="false">\
				<param name="kioskmode" value="false">\
				<param name="cache" value="true">\
				<param name="loop" value="false">\
				<param name="correction" value="full">\
				<embed SRC="'+relativePath+filepath+filename+'" SCALE="tofit" WIDTH="'+width.toString()+'" HEIGHT="'+height.toString()+'" CONTROLLER="false" correction="full" PLUGINSPAGE="http://www.apple.com/quicktime/download/" type="video/quicktime" enablejavascript="true" playeveryframe="true" autohref="true" loop="false" cache="true" kioskmode="false" dontflattenwhensaving="false"></embed>\
			</object>';
	}
	
	if (type == '3DMODEL') {
			outputString = '<OBJECT CLASSID="CLSID:86A88967-7A20-11d2-8EDA-00600818EDB1" CODEBASE="http://www.parallelgraphics.com/bin/cortvrml.cab#Version=4,1,1,91"  \
				style="position: relative; left: 0; top: 0; width: '+width.toString()+'; height: '+height.toString()+';">\
				<PARAM NAME="SRC" VALUE="'+relativePath+filepath+filename+'">\
				<PARAM NAME="VRML_BACKGROUND_COLOR" VALUE="#000000">\
				<param name="vrml_splashscreen" value="1">\
				<param name="vrml_dashboard" value="false">\
				<param name="NavigationBar" value="false">\
				<param name="ColliderMode" value="0">\
				<param name="NavigationMode" value="nmExamine">\
				<param name="ShowProgress" value="False">\
				<param name="rendererhints" value="8192">\
				<param name="ShowFPS" value="False">\
				<param name="ShowLogo" value="True">\
				<param name="ContextMenu" value="True">\
				<param name="WaitForAllResources" value="True">\
			</OBJECT>\
			';			
	}
	
	if (type == "MOVIE") {
	 		outputString = '<object id="MOVIE" CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" \
				style="position: relative; left: 0; top: 0; width: '+width.toString()+'; height: '+height.toString()+';">\
				<param name="SRC" VALUE="'+relativePath+filepath+filename+'">\
				<param name="AUTOPLAY" VALUE="true">\
				<param name="bgcolor" value="#999999">\
				<param name="CONTROLLER" VALUE="true">\
				<param name="SCALE" VALUE="aspect">\
				<param name="autohref" value="true">\
				<param name="playeveryframe" value="true">\
				<param name="enablejavascript" value="true">\
				<param name="dontflattenwhensaving" value="false">\
				<param name="kioskmode" value="false">\
				<param name="cache" value="true">\
				<param name="loop" value="false">\
				<param name="correction" value="full">\
				<embed SRC="'+relativePath+filepath+filename+'" SCALE="aspect" WIDTH="'+width.toString()+'" HEIGHT="'+height.toString()+'" CONTROLLER="false" correction="full" PLUGINSPAGE="http://www.apple.com/quicktime/download/" type="video/quicktime" enablejavascript="true" playeveryframe="true" autohref="true" loop="false" cache="true" kioskmode="false" dontflattenwhensaving="false"></embed>\
			</object>';
	}
	
	if (type == "VIDEO") {
			outputString = '\
			<object id="VIDEO_AVI_MPEG" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" type="application/x-oleobject" standby="Loading Microsoft Windows Media Player components..." height="'+height.toString()+'" width="'+width.toString()+'">\
				<param name="mute" value="false">\
				<param name="invokeurls" value="false">\
				<param name="fullscreen" value="false">\
				<param name="stretchtofit" value="false">\
				<param name="enablecontextmenu" value="true">\
				<param name="enabled" value="true">\
				<param name="volume" value="75">\
				<param name="balance" value="0">\
				<param name="rate" value="1.0">\
				<param name="windowlessvideo" value="false">\
				<param name="url" value="'+filepath+filename+'">\
				<param name="autostart" value="false">\
				<param name="uimode" value="full">\
			</object>\
			';
	}
	
	
	//alert(outputString);
	return (outputString);
}

function LoadActualContentToLayeredWindow(LayeredWindowID,frameString){
	
	frame = eval(frameString);
	
	e = frame.document.getElementById(LayeredWindowID+"Title");
	e.innerHTML = actualContentTitle;
	
	
	e = frame.document.getElementById(LayeredWindowID+"Content");
	e.innerHTML = "ppppp";
//	e.innerHTML = getContent(LayeredWindowID,frameString,frame.relativePath,actualContentType,actualContentWidth,actualContentHeight,actualContentFilename,actualContentFilepath);

	e = frame.document.getElementById(LayeredWindowID+"Icons");
	e.innerHTML = getIcons(LayeredWindowID,frameString,frame.relativePath,actualContentIcons);	

	actualContentLoaded = true;

}

function ShowActualContent(relPath){
	if (!actualLayeredWindowMaximized && !actualLayeredWindowFixed && !actualLayeredWindowFloating) actualLayeredWindowFloating = true;
	//if (!actualContentVisible) {

	actualContentVisible = true;
		//alert("showing");
	ShowHideLayeredWindows(relPath);	
	//}
}


//var bb = 1;
var globalContent;

function displayContent(){
	//alert('www');
	globalContent.style.visibility = "visible";
}

function UnLoadContentFromLayeredWindow(LayeredWindowID,frameString){
	frame = eval(frameString);
	var eContent = frame.document.getElementById(LayeredWindowID+"Content");	
	eContent.style.visibility = "hidden";
	eContent.style.display = "none";
	eContent.innerHTML = " ";
}

function LoadActualContentToLayeredWindowWithSizeAndIcons(LayeredWindowID,frameString,width,height,icons){

	frame = eval(frameString);

	e = frame.document.getElementById(LayeredWindowID+"Title");
	e.innerHTML = actualContentTitle;

	var eContent = frame.document.getElementById(LayeredWindowID+"Content");	
	globalContent = frame.document.getElementById(LayeredWindowID+"Content");
	eContent.style.visibility = "hidden";
	eContent.style.display = "none";
	eContent.innerHTML = " ";
	eContent.style.display = "block";
	eContent.innerHTML = getContent(LayeredWindowID,frameString,frame.relativePath,actualContentType,width-2,height-16,actualContentFilename,actualContentFilepath);
	//eContent.style.visibility = "visible";
	setTimeout('displayContent()',10);
	
/*	var ePHOTO = frame.document.getElementById(LayeredWindowID+"ContentPHOTO");
	var ePANORAMA = frame.document.getElementById(LayeredWindowID+"ContentPANORAMA");
	var e3DMODEL = frame.document.getElementById(LayeredWindowID+"Content3DMODEL");
*/	
/*	var eIFRAME1 = frame.document.getElementById("layeredFrameID1"); //document.getElementById(LayeredWindowID+"Content3DMODEL");
	var eIFRAME2 = frame.document.getElementById("layeredFrameID2"); //document.getElementById(LayeredWindowID+"Content3DMODEL");
	if (bb == 1) {
		//alert(bb);
		eIFRAME2.style.visibility = "hidden";
		eIFRAME2.src = "../../empty1.html";
		frame.layeredFrameID1.document.write("<html><head></head><body>" + getContent(LayeredWindowID,frameString,frame.relativePath,actualContentType,width-2,height-16,actualContentFilename,actualContentFilepath)+"</body></html>");
		eIFRAME1.style.visibility = "visible";

		bb = 2;
	} else {
		//alert(bb);
		eIFRAME1.style.visibility = "hidden";		
		eIFRAME1.src = "../../empty2.html";
		frame.layeredFrameID2.document.write("<html><head></head><body>" + getContent(LayeredWindowID,frameString,frame.relativePath,actualContentType,width-2,height-16,actualContentFilename,actualContentFilepath)+"</body></html>");
		eIFRAME2.style.visibility = "visible";		
		bb = 1;
	}
*/
//	frame.layeredFrameID.src = "empty.html";

/*		ePANORAMA.style.visibility = "hidden";
		ePANORAMA.style.display = "none";
		ePANORAMA.innerHTML = "";
		e3DMODEL.style.visibility = "hidden";
		e3DMODEL.style.display = "none";
		e3DMODEL.innerHTML = "";
		ePHOTO.style.visibility = "hidden";
		ePHOTO.style.display = "none";
		ePHOTO.innerHTML = "";	

	if (actualContentType == "PHOTO") {

		ePHOTO.style.visibility = 'visible';
		ePHOTO.style.display = 'block';
		ePHOTO.innerHTML = getContent(LayeredWindowID,frameString,frame.relativePath,actualContentType,width-2,height-16,actualContentFilename,actualContentFilepath);
		//eIFRAME.document.write(getContent(LayeredWindowID,frameString,frame.relativePath,actualContentType,width-2,height-16,actualContentFilename,actualContentFilepath));
	}

	if (actualContentType == "PANORAMA") {

		ePANORAMA.style.visibility = 'visible';
		ePANORAMA.style.display = 'block';
		ePANORAMA.innerHTML = getContent(LayeredWindowID,frameString,frame.relativePath,actualContentType,width-2,height-16,actualContentFilename,actualContentFilepath);
		//eIFRAME.document.write(getContent(LayeredWindowID,frameString,frame.relativePath,actualContentType,width-2,height-16,actualContentFilename,actualContentFilepath));
		ePANORAMA.style.width = 300; 
		
	}

	if (actualContentType == "3DMODEL") {

		e3DMODEL.style.visibility = 'visible';
		e3DMODEL.style.display = 'block';
		e3DMODEL.innerHTML = getContent(LayeredWindowID,frameString,frame.relativePath,actualContentType,width-2,height-16,actualContentFilename,actualContentFilepath);
		//eIFRAME.document.write(getContent(LayeredWindowID,frameString,frame.relativePath,actualContentType,width-2,height-16,actualContentFilename,actualContentFilepath));
	}
*/
	e = frame.document.getElementById(LayeredWindowID+"Icons");
	e.innerHTML = getIcons(LayeredWindowID,frameString,frame.relativePath,icons);	
	
}

function LoadActualContent(){

	//SetLayeredWindowSize('layeredWindow',top.main.pages.cframe,actualContentWidth,actualContentHeight);
	//LoadActualContentToLayeredWindow('layeredWindow','top.main.pages.cframe');
	if (!actualLayeredWindowMaximized && !actualLayeredWindowFixed && !actualLayeredWindowFloating) actualLayeredWindowFloating = true;
	
	if (actualLayeredWindowFloating) {
		//alert("loading floating");
		SetLayeredWindowSize('layeredWindow',top.main.pages.cframe,200,160);	
		LoadActualContentToLayeredWindowWithSizeAndIcons('layeredWindow','top.main.pages.cframe',200,160,'position_switch pos_switch maximize close '); //
	}
	if (actualLayeredWindowFixed) {
		//alert("loading fixed");
		SetLayeredWindowSize('layeredWindow',top.main.menu,112,96);
		LoadActualContentToLayeredWindowWithSizeAndIcons('layeredWindow','top.main.menu',112,96,'pos_switch maximize close ');
	}
	
	actualContentLoaded = true;
/*
	if (actualLayeredWindowMaximized) {
		if (aLWMwindow) {
		if (aLWMwindow.opener)	ShowHideLayeredWindows('../../')
		else {
			actualLayeredWindowMaximized = false;
		}
	}*/
		
		
}

function SetActualContent(marker_id,media_type,media_filename,media_filepath,width,height,media_title,media_copyrights) {
	//alert("-1 1");
	actualContentLoaded = false;
	actualMarkerID = marker_id;
	actualContentType = media_type;
	actualContentFilename = media_filename;
	actualContentFilepath = media_filepath;
	actualContentWidth = width;
	actualContentHeight = height;
	actualContentTitle = media_title;
	actualContentThumbnailFilename = "tn_" + media_filename;	
	actualContentCopyrights = media_copyrights;
}


