var undefined;
//var siteUrl="http://localhost/issue/200605/suleymaniye/";
//alert(document.URL);
var siteUrl="http://www.saudiaramcoworld.com/",
	tourUri = "/issue/200605/suleymaniye/";
//-------Overview Items-----------
function SelectOverview(overview, subArea){
	SetCookie('activeArea', 'streetcorner');
	window.location="tour.htm";	
}
function SetCookie(cookieName,cookieValue) {
	document.cookie = cookieName+"="+escape(cookieValue) + ";path=/;";
}
function ReadCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
//------------------------------------------
function ChangeMovie(type, changeTo){

if(!(changeTo in tourLocations)){
	return;
}
	activeArea = changeTo;
	SetCookie("activeArea",changeTo);
	
	var narrationPath = "mp3/narration/"+changeTo+".mp3",
		ambientPath = "mp3/ambient/"+changeTo+".mp3";	
	
	//document.getElementById("audioswf").SetVariable("activeArea", changeTo);
	document.getElementById("audioswf").SetVariable("narrationPath", narrationPath);
	document.getElementById("audioswf").SetVariable("ambientPath", ambientPath);
	document.getElementById("audioswf").SetVariable("changeSound", 1);
	
	WriteMovie();
	
//alert(type+" - "+changeTo);
	if(ThisWindow=="normal" && type=="normal"){
		
		document.getElementById('menuswf').SetVariable("myMovie", changeTo);
		document.getElementById('iframeDesc').src = tourUri+"desc/"+changeTo+".htm";
		
		
	}else if(ThisWindow=="fullscreen" && type=="fullscreen"){
		
		
		
	}else if(type=="popup"){
		SetCookie("ActiveDetail",changeTo);
		window.open(tourUri+"detail.htm","SuleymaniyeDetailImage",'width=' + 600 + ',height=' + 600 + ',scrollbars=no,status=no,toolbar=no,directories=no,menubar=no,location=no' );
	}
}


function WriteDetailMovie(){
	document.getElementById('detailMovie').innerHTML='<embed name="qtdetailmovie" id="qtdetailmovie" moviename="qtdetailmovie" src="mov/'+ShowMovieName+'.mov" width=720 height=480 alt="" cache="TRUE" kioskmode="true" controller="true" scale="toFit" PLUGINSPAGE="http://www.apple.com/quicktime/download/"></embed>';
}


function WriteMovie(){
	
	try{
		var area = tourLocations[activeArea],
			pano = area.pano;
	
	}catch(err){
		return;		
	}
	//console.log(pano);
	//alert(pano);
	
	var height = (ThisWindow === "fullscreen") ? "100%" : 400,
		width = (ThisWindow === "fullscreen") ? "100%" : 500;
	
	var swf = createswf("flash_panos/global/krpano.swf", "krpano", width, height);
	swf.addVariable("license", "flash_panos/global/krpano-license.xml");
	swf.addVariable("xml", pano);
	swf.embed("movDisplay");
	
	//document.getElementById('movDisplay').innerHTML='<embed name="qtmovie" id="qtmovie" moviename="qtmovie" src="mov/'+activeArea+'.mov" width=500 height=400 alt="" cache="TRUE" kioskmode="true" controller="false" scale="toFit" PLUGINSPAGE="http://www.apple.com/quicktime/download/"></embed>';
}


function WriteIFrame(){
	document.getElementById('iframeDiv').innerHTML='<iframe id="iframeDesc" align="top" frameborder="0" height="146" width="500" marginheight="0" marginwidth="0" name="iframeDesc" scrolling="auto" src="desc/alcazaba/alcazaba01.htm"></iframe> '
}
function OpenDetailMovie(movieName){
		//document.getElementById("audioswf").SetVariable("pauseAudio", true);
		//document.getElementById("audioswf").SetVariable("changeSound", 0);
		SetCookie("ShowMovieName",movieName);
		window.open(tourUri+"movie.htm","DetailMovieWindow",'width=' + 770 + ',height=' + 530 + ',scrollbars=no,status=no,toolbar=no,directories=no,menubar=no,location=no' );
}
function FullScreenVersion(){
   //alert("This will show the full screen version of '"+ReadCookie("activeArea"));
		//SetCookie("activeArea",activeArea+"hi");
		document.getElementById("audioswf").SetVariable("pauseAudio", true);
		document.getElementById("audioswf").SetVariable("changeSound", 0);
		var fsWin = window.open("fullscreen.htm","FullScreenPanorama",'fullscreen=yes,scrollbars=no,status=no,toolbar=no,directories=no,menubar=no,location=no' );
		fsWin.resizeTo(screen.availWidth, screen.availHeight);
		fsWin.moveTo(0,0);
}
function SmallScreenResize(){
	if(screen.width<1000){
		window.resizeTo(800,600);
		window.scrollbars.visible=true;
	}
}







var tourLocations = {
	"streetcorner":{
		pano: "flash_panos/01/420EOS1DstreetCorner.xml"	
	},
	"gate":{
		pano: "flash_panos/02/486EOS1DextGate.xml"	
	},
	"exteriorcorner":{
		pano: "flash_panos/03/484EOS1D.xml"	
	},
	"courtyard":{
		pano: "flash_panos/04/courtyard.xml"	
	},
	"minareta":{
		pano: "flash_panos/05/505EOS1Dminaret1b.xml"	
	},
	"minaretb":{
		pano: "flash_panos/06/minaret1.xml"	
	},
	"floorrear":{
		pano: "flash_panos/07/422EOS1D.xml"	
	},
	"centerfloor":{
		pano: "flash_panos/08/CenterFloor.xml"	
	},
	"mihrab":{
		pano: "flash_panos/09/mihrab.xml"	
	},
	"muezzinmahfili":{
		pano: "flash_panos/10/MuezzinMahfili.xml"	
	},
	"side":{
		pano: "flash_panos/11/500EOS1Dside.xml"	
	},
	"catwalk":{
		pano: "flash_panos/12/507EOS1Dcatwalk1.xml"	
	},
	"dome":{
		pano: "flash_panos/13/dome.xml"	
	},
	"exterior":{
		pano: "flash_panos/14/exterior02sphP2.xml"	
	},
	
	getPrev:function(pivot){
		if(pivot==null) pivot = activeArea;
		var prev = null;
		for(var key in this){
			if(pivot == key){
				break;
			}
			if(typeof(this[key]) !== "function"){
				prev = key;
			}
		}
		console.log("prev: "+prev + " from "+ activeArea);
		return prev;
	},
	
	getNext:function(pivot){
		if(pivot==null) pivot = activeArea;
		var flag = false,
			next = null;
		for(var key in this){
	
			if(flag && typeof(this[key]) !== "function"){
				next = key;
				break;	
			}else if(pivot == key){
				flag = true;
			}
		}
		console.log("next: "+next + " from "+ activeArea);
		return next;
	}
	
};


function setTourLocationFirst(){
	ChangeMovie(ThisWindow, "streetcorner");
}

function setTourLocationNext(){
	var next = tourLocations.getNext();
	if(next != null){
		ChangeMovie(ThisWindow, next);
	}
}

function setTourLocationPrev(){
	var prev = tourLocations.getPrev();
	if(prev != null){
		ChangeMovie(ThisWindow, prev);
	}
}



function showFullScreen(){
	FullScreenVersion();
}

function exitFullScreen(){
	window.close();
	//opener.setTourLocationByIndex(getTourLocationCookie());
	opener.ChangeMovie("normal", ReadCookie('activeArea'));
}
