// PhotoWarp AutoViewer 2.0
// © 2005-7 by EyeSee360, Inc.
// Written by Michael Rondinelli


/* Taken from prototype.js */
Object.extend = function (destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
	return destination;
};

function createCookie(name,value,days) {
	var date, expires;
	if (days) {
		date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	} else {
		expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	var c;
	for(var i=0;i < ca.length;i++) {
		c = ca[i];
		while (c.charAt(0) === ' ') {
			c = c.substring(1,c.length);
		}
		if (c.indexOf(nameEQ) === 0) {
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/* PluginDetect v0.1.6 by Eric Gerds */ 
var PluginDetect={minIEver:5.5,getNum:function(A){if(!A){return null}var m=/[\d][\d\.\_,-]*/.exec(A);return m?m[0].replace(/[\.\_-]/g,","):null},hasMimeType:function(_3){var s,t,z,M=_3.constructor==String?[_3]:_3;for(z=0;z<M.length;z++){s=navigator.mimeTypes[M[z]];if(s&&s.enabledPlugin){t=s.enabledPlugin;if(t.name||t.description){return s}}}return null},findNavPlugin:function(N,_6){var _7=N.constructor==String?N:N.join(".*"),numS=_6===false?"":"\\d";var i,re=new RegExp(_7+".*"+numS+"|"+numS+".*"+_7,"i");var _9=navigator.plugins;for(i=0;i<_9.length;i++){if(re.test(_9[i].description)||re.test(_9[i].name)){return _9[i]}}return null},getAXO:function(_a){var _b,e;try{_b=new ActiveXObject(_a);return _b}catch(e){}return null},num:function(A){return (typeof A!="string"?false:(/\d/).test(A))},compareNums:function(_d,_e){if(!this.num(_d)||!this.num(_e)){return 0}var m1=_d.split(","),m2=_e.split(","),x,p=parseInt;for(x=0;x<m1.length;x++){if(p(m1[x],10)>p(m2[x],10)){return 1}if(p(m1[x],10)<p(m2[x],10)){return -1}}return 0},formatNum:function(num){if(!this.num(num)){return null}var n=num.replace(/[\.\_]/g,","),i;n=n.split(",").concat(["0","0","0","0"]);return n.slice(0,4).join(",")},initScript:function(){var $=this,IE;$.reload=1;$.isIE=(/*@cc_on!@*/false);$.IEver=-1;if($.isIE){var IE=(/msie\s*\d\.{0,1}\d*/i).exec(navigator.userAgent),progid,x;if(IE){$.IEver=parseFloat((/\d.{0,1}\d*/i).exec(IE[0]),10)}progid=["ShockwaveFlash.ShockwaveFlash","Msxml2.XMLHTTP","Microsoft.XMLDOM","Msxml2.DOMDocument","TDCCtl.TDCCtl","Shell.UIHelper","Scripting.Dictionary"];$.ActiveXEnabled=false;for(x=0;x<progid.length;x++){if($.getAXO(progid[x])){$.ActiveXEnabled=true;break}}};if($.ActiveXEnabled&&$.IEver>=$.minIEver){$.head=document.getElementsByTagName("head")[0];var T=document.createElement("script");T.setAttribute("type","text/vbscript");var Y=["<!"+"--","function PluginDetect1(c)","on error resume next","PluginDetect1=false","dim head, r","set head=PluginDetect.head","set r=head.firstChild","if TypeName(r)=\"HTMLObjectElement\" then","r.setAttribute \"classid\", c","if not TypeName(r.getAttribute(\"object\")) = \"Nothing\" then","PluginDetect1=true","if r.getAttribute(\"readyState\")<4 then","r.clearAttributes()","head.removeChild(r)","end if","else r.clearAttributes()","head.removeChild(r)","end if","end if","r=\"Nothing\"","head=\"Nothing\"","end function","--"+">"];T.setAttribute("text",Y.join("\n"));if($.head.firstChild){$.head.insertBefore(T,$.head.firstChild)}else{$.head.appendChild(T)}$.vbscript=false;var e;$.head.insertBefore(document.createElement("object"),$.head.firstChild);try{if(PluginDetect1("")===false){$.vbscript=true}}catch(e){}}},init:function(_17){var $=this,IE,p;_17=_17.toLowerCase().replace(/\s/g,"");p=$.plugin=$[_17];if(!p){return -3}if(typeof p.minversion=="undefined"){p.minversion={}}if(typeof p.version=="undefined"){p.version=null}if(typeof p.installed=="undefined"){p.installed=null}$.garbage=false;if($.isIE&&!$.ActiveXEnabled){return -2}return 1},isMinVersion:function(_19,_1a){var $=PluginDetect,i=$.init(_19);if(i<0){return i}if(!$.num(_1a)){return -3}var p=$.plugin,m=p.minversion;_1a=$.formatNum(_1a);if(typeof m["a"+_1a]=="undefined"){if(p.installed==null&&p.getCodeBaseVersion&&$.IEver>=p.minIEver){var tmp,x;for(x in m){tmp=$.compareNums(_1a,x.substring(1,x.length));if(m[x]==1&&tmp<=0){return 1}if(m[x]==-1&&tmp>=0){return -1}}m["a"+_1a]=$.isActiveXObject(_1a)?1:-1}else{if(p.installed==null){p.getVersion()}if(p.installed==-1){m["a"+_1a]=-1}else{if(p.version==null){m["a"+_1a]=0}else{m["a"+_1a]=($.compareNums(p.version,_1a)>=0?1:-1)}}}}$.cleanup();return m["a"+_1a];return -3},getVersion:function(_1e){return null},cleanup:function(){var $=this;if($.garbage&&typeof window.CollectGarbage!="undefined"){window.CollectGarbage()}},isActiveXObject:function(_22){var $=this,result,s="<object width=\"1\" height=\"1\" "+"style=\"display:none\" "+$.plugin.getCodeBaseVersion(_22)+">"+$.plugin.HTML+"</object>";$.head.insertBefore(document.createElement("object"),$.head.firstChild);$.head.firstChild.outerHTML=s;result=$.vbscript?PluginDetect1($.plugin.classID):$.detect($.plugin.classID);return result},detect:function(_24){var $=this,result;$.head.firstChild.setAttribute("classid",_24);result=$.head.firstChild.getAttribute("object")?true:false;if(!result||$.head.firstChild.getAttribute("readyState")<4){$.head.firstChild.clearAttributes();$.head.removeChild($.head.firstChild);$.garbage=true}return result},search:function(){},dummy1:0};PluginDetect.initScript();PluginDetect.quicktime={mimeType:["video/quicktime","application/x-quicktimeplayer","image/x-macpaint","image/x-quicktime"],progID:"QuickTimeCheckObject.QuickTimeCheck.1",progID0:"QuickTime.QuickTime",classID:"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B",minIEver:7,HTML:"<param name=\"src\" value=\"A14999.mov\" /><param name=\"controller\" value=\"false\" />",getCodeBaseVersion:function(v){return "codebase=\"#version="+v+"\""},digits:[16,16,16,0],getVersion:function(){var _2e=null,p,$=PluginDetect;if(!$.isIE){p=$.findNavPlugin(["QuickTime","(Plug-in|Plugin)"]);if(p&&p.name&&$.hasMimeType(this.mimeType)){_2e=$.getNum(p.name)}this.installed=_2e?1:-1}else{var obj;if($.IEver<this.minIEver){obj=$.getAXO(this.progID);if(obj&&obj.QuickTimeVersion){_2e=obj.QuickTimeVersion.toString(16);_2e=_2e.charAt(0)+"."+_2e.charAt(1)+"."+_2e.charAt(2)}}else{_2e=$.search()}this.installed=_2e?1:($.getAXO(this.progID0)?0:-1)}this.version=$.formatNum(_2e)}};PluginDetect.java={mimeType:"application/x-java-applet",classID:"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93",JavaVersions:["1.7.0.15","1.6.0.15","1.5.0.12","1.4.2.13","1.3.1.18"],searchJava:function(M){if(!M){return null}var G,e,x3,x4;var AXO=ActiveXObject;var T=M.split("."),J="JavaPlugin."+T[0]+T[1],v=T[0]+"."+T[1]+".";for(x3=T[2];x3>=0;x3--){for(x4=T[3];x4>=0;x4--){G=x4<10?"0"+x4:x4;try{new AXO(J+x3+"_"+G);return v+x3+"_"+G}catch(e){}}if(J+x3=="JavaPlugin.131"){return null}try{new AXO(J+x3);return v+x3}catch(e){}}return null},minIEver:5.5,HTML:"<param name=\"code\" value=\"A14999.class\" />",getCodeBaseVersion:function(v){var r=this.getDigits(v),$=PluginDetect;if($.compareNums(v,"1,4,1,02")<0){v=r[0]+","+r[1]+","+r[2]+","+r[3]}else{if($.compareNums(v,"1,5,0,02")<0){v=r[0]+","+r[1]+","+r[2]+","+r[3]+"0"}else{v=Math.round((parseFloat(r[0]+"."+r[1],10)-1.5)*10+5)+","+r[2]+","+r[3]+"0"+",0"}}return "codebase=\"#version="+v+"\""},digits:[1,9,32,32],getDigits:function(n){/([\d]+)[,_\.]([\d]+)[,_\.]([\d]+)[,_\.]([\d]+)/.test(n);return [RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4]},queryJava:function(){var $=PluginDetect,nav=navigator.userAgent,j=window.java,e;if(!/firefox/i.test(nav)||($.hasMimeType("application/x-java-vm")&&navigator.javaEnabled())){if(!/PluginDetect=reload/.test(window.location.search)&&typeof j!="undefined"&&typeof j.lang!="undefined"){if($.reload==1&&/mac/i.test(nav)&&/ppc/i.test(nav)&&/firefox/i.test(nav)){setTimeout("if(PluginDetect.reload==1)window.location.replace(window.location.href+(/\\?/.test(window.location.search)?\"\":\"?\")+\"PluginDetect=reload&\")",100)}if(typeof j.lang.System!="undefined"){$.reload=0;return (j.lang.System.getProperty("java.version")+" ")}$.reload=0}}return null},getVersion:function(){var _38=null,$=PluginDetect;if(!$.isIE){var p1,p,mt;p=$.findNavPlugin(["Java","Plug-in"]);mt=$.hasMimeType(this.mimeType);if(p){p1=$.getNum(p.description)}if(p1&&mt&&navigator.javaEnabled()){_38=p1}if(!_38){p=this.queryJava();if(p){_38=p}}this.installed=-1;if(_38){this.installed=1}else{if(/macintosh/i.test(navigator.userAgent)&&/safari/i.test(navigator.userAgent)&&mt&&navigator.javaEnabled()){this.installed=0}}}else{var x,tmp=null;if($.IEver>=this.minIEver){_38=$.search();this.installed=_38?1:-1}else{for(x=0;x<this.JavaVersions.length;x++){tmp=this.searchJava(this.JavaVersions[x]);if(tmp){_38=tmp;break}}this.installed=_38?1:($.getAXO("JavaPlugin")?0:-1)}}this.version=$.formatNum($.getNum(_38))}};PluginDetect.flash={mimeType:["application/x-shockwave-flash","application/futuresplash"],progID:"ShockwaveFlash.ShockwaveFlash",classID:"clsid:D27CDB6E-AE6D-11CF-96B8-444553540000",getVersion:function(){var _3d=function(A){if(!A){return null}var m=/[\d][\d\,\.\s]*[rRdD]{0,1}[\d\,]*/.exec(A);return m?m[0].replace(/[rRdD\.]/g,",").replace(/\s/g,""):null};var p,$=PluginDetect,e,i,version=AXO=majV=null;if(!$.isIE){p=$.findNavPlugin("Flash");if(p&&p.description&&$.hasMimeType(this.mimeType)){version=_3d(p.description)}}else{for(i=15;i>2;i--){AXO=$.getAXO(this.progID+"."+i);if(AXO){majV=i.toString();break}}if(majV=="6"){try{AXO.AllowScriptAccess="always"}catch(e){return "6,0,21,0"}}try{version=_3d(AXO.GetVariable("$version"))}catch(e){}if(!version&&majV){version=majV}}this.installed=version?1:-1;this.version=$.formatNum(version)}};


/* Pano Viewers */
function PanoViewer()
{
	this.params = {};
	this.assocElements = [];
}

PanoViewer.prototype.initViewer = function(width, height, params) 
{
	this.width = width;
	this.height = height;
	Object.extend(this.params, params);
	this.viewerCode = this.MakeObjectEmbedCode();
};

PanoViewer.prototype.canShow = function() 
{ 
	// Subclasses should replace with the proper test
	return true; 
};

PanoViewer.prototype.fetch = function() 
{
	if (this.canShow() != -1) {
		return this.viewerCode;
	} else {
		return false;
	}
};

/*
PanoViewer.prototype.write = function()
{
	var code = this.fetch();
	if (!code) {
		return false;
	} else {
		document.writeln(code);
		return true;
	}
};
*/

PanoViewer.prototype.updateElement = function(displayElement)
{
	var code = this.fetch();
	if (!code) {
		return false;
	} else {
		displayElement.innerHTML = code;
		return true;
	}
};

PanoViewer.prototype.associateElement = function(element)
{
	this.assocElements.push(element);
};

PanoViewer.prototype.showAssocElements = function()
{
	for (var i in this.assocElements) {
		this.assocElements[i].style.display = "block";
	}
};

PanoViewer.prototype.hideAssocElements = function()
{
	for (var i in this.assocElements) {
		this.assocElements[i].style.display = "none";
	}
};

PanoViewer.prototype.MakeObjectEmbedCode = function()
{
	return PanoViewer.MakeObjectEmbedCode(this.classid, this.codebase, this.mimetype, this.pluginspage, this.width, this.height, this.params, this.noembed);
};

/* Object/Embed tag generators */
PanoViewer.MakeObjectEmbedCode = function(classid, codebase, type, pluginspage, width, height, params, noembed)
{
	var param, embedParams = '';
	for (param in params) {
		embedParams += param + '="' + params[param] + '" ';
	}
	var embedTag = '<embed ' +
				   'width="' + width + '" height="' + height + '" ' +
				   'type="' + type + '" ' +
				   'pluginspage="' + pluginspage + '" ' +
				   embedParams + '>\n' + 
				   '<noembed>' + noembed + '</noembed>\n' + 
				   '</embed>\n';
	
	var objectParams = '';
	for (param in params) {
		objectParams += '<param name="' + param + '" value="' + params[param] + '" />\n';
	}
	var objectTag = '<object classid="' + classid + '" ' + 
					'codebase="' + codebase + '" ' +
				    'width="' + width + '" height="' + height + '">\n' +
					objectParams + 
					'<comment>' + embedTag + '<comment>' +
					'</object>\n';

	return objectTag;
};


function PV_ImageViewer(width, height, params)
{
	this.width = width;
	this.height = height;
	this.viewerCode = this.MakeImageCode();
}

PV_ImageViewer.prototype = new PanoViewer();
PV_ImageViewer.prototype.viewerCode = "Image";
PV_ImageViewer.prototype.format = "image";
PV_ImageViewer.prototype.requiredParams = ["src"];
PV_ImageViewer.prototype.canShow = function() { return true; };
PV_ImageViewer.prototype.MakeImageCode = function()
{
	var imgTag = '<img width="' + this.width + '" height="' + this.height + '"';
	for (param in this.params) {
		imgTag += param + '="' + this.params[param] + '" ';
	}
	imgTag += '>';
	return imgTag;
};


function PV_QuickTimeViewer(width, height, params)
{
	this.initViewer(width, height, params);
}

PV_QuickTimeViewer.prototype = new PanoViewer();
PV_QuickTimeViewer.prototype.viewerName = "QuickTime";
PV_QuickTimeViewer.prototype.format = "qtvr";
PV_QuickTimeViewer.prototype.params = {controller: 'true'};
PV_QuickTimeViewer.prototype.requiredParams = ["src"];
PV_QuickTimeViewer.prototype.classid = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
PV_QuickTimeViewer.prototype.codebase = "http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0";
PV_QuickTimeViewer.prototype.mimetype = "video/quicktime";
PV_QuickTimeViewer.prototype.pluginspage = "http://www.apple.com/quicktime/download/";
PV_QuickTimeViewer.prototype.canShow = function() { return PluginDetect.isMinVersion('QuickTime','6,0,2,0'); };


function PV_Java4Viewer()
{
//	this.MakeObjectEmbedCode = this.MakeAppletEmbedCode;
}

PV_Java4Viewer.prototype = new PanoViewer();
PV_Java4Viewer.prototype.viewerName = "Java";
PV_Java4Viewer.prototype.format = "java";
PV_Java4Viewer.prototype.params = {};
PV_Java4Viewer.prototype.classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
PV_Java4Viewer.prototype.codebase = "http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab#Version=1,4,0,0";
PV_Java4Viewer.prototype.mimetype = "application/x-java-applet";
PV_Java4Viewer.prototype.pluginspage = "http://java.sun.com/j2se/1.4/download.html";
PV_Java4Viewer.prototype.canShow = function() { return PluginDetect.isMinVersion('Java','1,4,0,0'); };
PV_Java4Viewer.prototype.MakeAppletEmbedCode = function()
{
	var appletTag, appletParams, param;
	
	if (PluginDetect.isIE) {
		return PanoViewer.MakeObjectEmbedCode();
	} else {
		appletTag = '<applet width="' + this.width + '" height="' + this.height + '" ';
		if ('code' in this.params) { appletTag += 'code="' + this.params.code + '" '; }
		if (this.params.archive) { appletTag += 'archive="' + this.params.archive + '" '; }
		if (this.params.codebase) { appletTag += 'codebase="' + this.params.codebase + '" '; }
		appletTag += '>\n';
	
		appletParams = '';
		for (param in this.params) {
			appletParams += '<param name="' + param + '" value="' + this.params[param] + '" />\n';
		}
		appletTag += appletParams + '</applet>';
		return appletTag;
	}
};


function PV_ZoomViewer(width, height, params)
{
	this.initViewer(width, height, params);
}

PV_ZoomViewer.prototype = new PV_Java4Viewer();
PV_ZoomViewer.prototype.viewerName = "Zoom Viewer";
PV_ZoomViewer.prototype.format = "zoom";
PV_ZoomViewer.prototype.params = {	
	code: "panoapplet", 
	archive: "panoapplet.jar",
	initialview: "0 0 70",
	autospin: 0 };
PV_ZoomViewer.prototype.requiredParams = ["file"];


function PV_PTViewer(width, height, params)
{
	this.initViewer(width, height, params);
}

PV_PTViewer.prototype = new PV_Java4Viewer();
PV_PTViewer.prototype.viewerName = "PTViewer";
PV_PTViewer.prototype.format = "ptviewer";
PV_PTViewer.prototype.params = {	
	code: "ptviewer.class", 
	archive: "ptviewer.jar",
	pan: 0,
	tilt: 0,
	fov: 70,
	autospin: 0,
	quality: 5,
	showToolbar: 'true' };
PV_PTViewer.prototype.requiredParams = ["file", "tiltmin", "tiltmax"];


function PV_FlashViewer()
{
}

PV_FlashViewer.prototype = new PanoViewer();
PV_FlashViewer.prototype.viewerName = 'Flash';
PV_FlashViewer.prototype.format = 'flash';
PV_FlashViewer.prototype.params = {};
PV_FlashViewer.prototype.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
PV_FlashViewer.prototype.codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0";
PV_FlashViewer.prototype.mimetype = "application/x-shockwave-flash";
PV_FlashViewer.prototype.pluginspage = "http://www.macromedia.com/go/getflashplayer";
PV_FlashViewer.prototype.canShow = function() { return PluginDetect.isMinVersion('Flash','6,0,0,0'); };


function PV_FlashVRViewer(width, height, params)
{
	this.initViewer(width, height, params);
}

PV_FlashVRViewer.prototype = new PV_FlashViewer();
PV_FlashVRViewer.prototype.viewerName = 'FlashVR';
PV_FlashVRViewer.prototype.format = 'flashvr';
PV_FlashVRViewer.prototype.params = {bgcolor: '#ffffff', quality: 'MEDIUM', src: 'flashvr.swf'};
PV_FlashVRViewer.prototype.requiredParams = ['flashvars'];


/* AutoViewer */
function AutoViewer(elid)
{
	this.elid = elid;
	this.element = 0;
	this.viewers = [];
	this.currentViewer = 0;
}

AutoViewer.prototype.getElement = function()
{
	if (!this.element && this.elid) {
		this.element = document.getElementById(this.elid);
	}
	return this.element;
};

AutoViewer.prototype.setElement = function(el)
{
	this.element = el;
	this.update();
};

AutoViewer.prototype.getElementId = function()
{
	return this.elid;
};

AutoViewer.prototype.setElementId = function(elid)
{
	this.elid = elid;
	this.setElement(document.getElementById(this.elid));
};

AutoViewer.prototype.addViewer = function(viewer)
{
	this.viewers.push(viewer);
};

AutoViewer.prototype.setViewers = function(viewers)
{
	this.viewers = viewers;
};

AutoViewer.prototype.getViewers = function()
{
	return this.viewers;
};

AutoViewer.prototype.getFormats = function()
{
	var formats = [];
	for (var viewer in this.viewers) {
		formats.push(this.viewers[viewer].format);
	}
	return formats;
};

AutoViewer.prototype.getDimensions = function()
{
	if (this.currentViewer) {
		return [this.currentViewer.width, this.currentViewer.height];
	} else {
		return [this.viewers[0].width, this.viewers[0].height];
	}
}

/*
AutoViewer.prototype.write = function()
{
	var i = 0;
	document.writeln('<div id="' + this.elid + '">');
	while( i < this.viewers.length && !this.viewers[i].write() ) { i++; }
	document.writeln('</div>');
};
*/

AutoViewer.prototype.showSwitcher = function()
{
	var element = this.getElement();
	if (element) {
		var switcher = '<div class="AutoViewerSwitcher">';
		switcher += 'Please choose a viewer for your panorama:<br>';
		for (var viewer in this.viewers) {
			switcher += '<a href="javascript:AllViewers.switchAllToFormat(\'' + 
				this.viewers[viewer].format + '\');">' + 
				this.viewers[viewer].viewerName + '</a><br>'
		}
		element.innerHTML = switcher;
		element.children[0].style.border = '2px solid red';
		element.children[0].style.margin = '1em';
		element.children[0].style.textAlign = 'center';
	}
};

AutoViewer.prototype.update = function()
{
	var cantDetect = false;

	var preferredFormat = readCookie('AV_preferredPanoFormat');
	if (preferredFormat) {
		var preferredViewer = this.viewerWithFormat(preferredFormat);
		if (preferredViewer && (preferredViewer.canShow() != -1)) {
			this.switchTo(preferredViewer);
			return true;
		} else {
			// Format doesn't work
			eraseCookie('AV_preferredPanoFormat');
		}
	}

	for(var i = 0; i < this.viewers.length; i++) {
		var canShow = this.viewers[i].canShow();
		if (canShow >= 0) {
			if (this.switchTo(this.viewers[i])) {
				return true;
			}
		} else if (canShow == -2) {
			cantDetect = true;
		}
	}
	if (cantDetect) {
		this.showSwitcher();
	}
	return false;
};

AutoViewer.prototype.switchTo = function(viewer)
{
	var element = this.getElement();
	if (element && viewer.updateElement(element)) {
	    if (this.currentViewer) {
   			this.currentViewer.hideAssocElements();
   		}
		viewer.showAssocElements();
		this.currentViewer = viewer;
		return true;
	}
	return false;
};

AutoViewer.prototype.switchToFormat = function(format)
{
	return this.switchTo( this.viewerWithFormat(format) );
};

AutoViewer.prototype.viewerWithFormat = function(format)
{
	for(var i in this.viewers) {
		if (this.viewers[i].format === format) {
			return this.viewers[i];
		}
	}
};

var AllViewers = {
	viewers: [],
	assocElements: [],
	
	newViewer: function(e) {
		var nv = new AutoViewer(e);
		this.viewers.push(nv);
		return nv;
	},
	
	updateAll: function (e) {
		for (var thisav in this.viewers) {
			this.viewers[thisav].update();
		}
	},

	switchAllToFormat: function (format) {
//		createCookie('AV_preferredPanoFormat', format, 0);
		for (var thisav in this.viewers) {
			this.viewers[thisav].switchToFormat(format);
		}
		this.switchAssocElementsToFormat(format);
	},

	assocElementWithFormat: function (element, format) {
		this.assocElements[format].push(element);
	},

	switchAssocElementsToFormat: function (format) {
		var display, elements, e;
		for (var f in AutoViewer.assocElements) {
			display = "none";
			if (f === format) { 
				display = "block";
			} else {
				display = "none";
			} 

			elements = this.assocElements[format];
			for (e in elements) {
				elements[e].style.display = display;
			}
		}
	}
};


