//Определяем браузер : browser=1 (IE), browser=2 (Opera,Netscape,Mozilla)
var     browser=0;
if        (navigator.appName=='Microsoft Internet Explorer') {
	browser=1;
} else if (navigator.appName=='Opera' || navigator.appName=='Netscape' ||  navigator.appName=='Mozilla') {
	browser=2;
}

var isIE4=(navigator.appVersion.indexOf("MSIE")!=-1 && parseFloat(navigator.appVersion)>=4)?true:false;


function image_on(x,ch2) {
//	if (browser!=1) return;
//	x.childNodes[0].filters[0].Opacity=60;
}
function image_off(x,ch2) {
//	if (browser!=1) return;
//	x.childNodes[0].filters[0].Opacity=100;
}

function i_on(x,ch2) {
x.children[0].src=ch2;
}
function i_off(x,ch2) {
x.children[0].src=ch2;
}

//Проверяет установлен ли PlugIn axIpx32.exe
function pluginDetected() {
    if ( browser == 1 ) { 
		document.writeln('<SCRIPT LANGUAGE="VBScript"\>');
		document.writeln('on error resume next');
		document.writeln('ipix1 = IsObject(CreateObject("IPIX.Viewers.5"))');
		document.writeln('ipix2 = IsObject(CreateObject("IPIX.ActiveXCtrl.2"))');
		document.writeln('ipix3 = IsObject(CreateObject("IPIX.ActiveXCtrl.5"))');
		document.writeln('If ipix1 = True or ipix2 = True or ipix3 = True Then');
		document.writeln('ipixmode = 1');
		document.writeln('Else');
		document.writeln('ipixmode = 0');
		document.writeln('End if');
		document.writeln('</SCRIPT\>');
		return ipixmode;
    } else if ( browser == 2 ) { 
		navigator.plugins.refresh(true);
		numPlugins = navigator.plugins.length;
		if (numPlugins > 0) {
			for (k = 0; k < numPlugins; k++) {
				plugin = navigator.plugins[k];
				if (plugin.description.indexOf("IPIX") != -1) {
					numTypes = plugin.length;
					for (j = 0; j < numTypes; j++) {
						mimetype = plugin[j];
						if (mimetype)       {
							if (mimetype.enabledPlugin && (mimetype.suffixes.indexOf("ipx") != -1)) {
							  return 1;
							}
						}
					}
				}
			}
		}
		return 0;
    }
}

//проверяет установлена ли Java
function IfJavaInstalled() {
   var str, oClientCaps;
   if (browser==2) return true;
   oClientCaps = document.body;
   oClientCaps.style.behavior = "url(#default#clientCaps)";
   bMSvmAvailable = oClientCaps.isComponentInstalled("{08B0E5C0-4FCB-11CF-AAA5-00401C608500}","componentid");
   return (bMSvmAvailable) ? true : false;
}

//выводит сообщение если не установлены средства просмотра ipix
function PutInstall(width,height) {
	var str;
	str = '   <div width="' + width + '" height="' + height + '" align=left valign=top style="padding:10px;">';
	str += ipx_install_msg;
	str += '   </div>';
	document.write(str);
}   

//Выводит сообщение если браузер не удовлетворяет требованиям для просмотра ipix
function PutNoBrowser(width,height) {
	var str;
	str = '   <div width="' + width + '" height="' + height + '" align=left valign=top style="padding:10px;">';
	str += ipx_browser_msg;
	str += '   </div>';
	document.write(str);
}   

//Вставляем ipix на экран для просмотра с помощью axIpx32.exe
function PutByPlugIn (file,width,height) {
	var str;
	str =  ' 	<OBJECT ID="IpixX1" WIDTH='+width+' HEIGHT='+height;
	str += '    CLASSID="CLSID:11260943-421B-11D0-8EAC-0000C07D88CF"';
 	str += '    CODEBASE="http://www.ipix.com/download/ipixx.cab#version=6,2,0,5">';
	if ( browser == 1 ) {
		str += '<PARAM NAME="IPXFILENAME" VALUE="'+file+'">';
	} else {
		str += '	<embed src="'+file+'" border=0 width='+width+' height='+height+' ';
		str += '	palette="foreground" type="application/x-ipix" ';
		str += '	pluginsPage="http://www.ipix.com/cgi-bin/download.cgi">';
		str += '	</embed>';
	}
	str += '	</OBJECT>';
	document.writeln(str);
}
 
//Вставляем ipix на экран для просмотра с помощью Java IPIX(R) Java(R) Viewer5.0.1
function PutByJavaApplet (file,width,height) {
	var str;
	str =  '<APPLET name="IpixViewer"';
	str += 'code="IpixViewer.class"';
	str += 'codebase="/ipx/"';
	str += 'archive="IpixViewer.jar"';
	str += 'width="'+width+'" height="'+height+'">';
	str += '<PARAM NAME="url" VALUE="'+file+'">';
	str += '<PARAM NAME="toolbar" VALUE="off">';
	str += '<PARAM NAME="splash" VALUE="/ipx/ipix_bg_logo.gif">';
	str += '<PARAM NAME="splashbg" VALUE="FFFFFF">';
	str += '<PARAM NAME="initfov" VALUE="0">';
	str += '<PARAM NAME="spinspeed" VALUE="6">';
	str += '<PARAM NAME="spinstyle" VALUE="flat">';
	str += '</APPLET>';
	document.writeln(str);
}

//основная функция по отображению ipix
function PutIPX(file,width,height) {
	if (!browser) {
		PutNoBrowser(width,height);
		return;
	}
	if (IfJavaInstalled() && navigator.javaEnabled()) {
		//если установлен JAVA и JAVA Разрешена в настройках параметров безопасности IE
		PutByJavaApplet (file,width,height);
	} else if (pluginDetected()) {
		//если в IE установлен PLUGIN
		PutByPlugIn (file,width,height);
	} else {
		//в других случаях показать сообщение установить средства просмотра IPIX
		PutInstall(width,height);
	} 
}

function opa(image) {
	var w = screen.availWidth-10;
	var h = screen.availHeight-40;
	window.open(image, "panoimage", "left=0, top=0, scrollbars=0, resizable=1, width="+w+", height="+h).focus();
}

function opa1(image) {
	var w = screen.availWidth-10;
	var h = screen.availHeight-40;
	window.open(image, "panoimage", "left=0, top=0, scrollbars=1, resizable=1, width="+w+", height="+h).focus();
}

function openmov(image,lang) {
	var w = screen.availWidth-10;
	var h = screen.availHeight-40;
	if (image.match(/\.(ipx)$/) != null) {
		url="/ipix_popup/?img="+image;
		if (lang) url = "/"+lang+url;
		window.open(url,"popupimage", "scrollbars=0, resizable=0, status=0, titlebar=0, width=400, height=300").focus();
	} else if (image.match(/\.((mov)|(swf))$/) != null) {
		window.open('/view.php?p='+image, "panoimage", "left=0, top=0, scrollbars=0, resizable=1, width="+w+", height="+h).focus();
	}
}

function openmov2(image,lang) {
	w = 540;
	h = 340;
	l=Math.ceil((screen.width-w)/2);
	t=Math.ceil((screen.height-h)/2)-10;

	if (image.match(/\.(ipx)$/) != null) {
		url="/ipix_popup/?img="+image;
		if (lang) url = "/"+lang+url;
		window.open(url,"popupimage", "scrollbars=0, resizable=0, status=0, titlebar=0, width=500, height=300").focus();
	} else if (image.match(/\.((mov)|(swf))$/) != null) {
		window.open('/view.php?p='+image, "panoimage", "left="+l+", top="+t+", scrollbars=0, resizable=1, width="+w+", height="+h).focus();
	}
}

function openswf(image,lang) {
	var w = screen.availWidth-10;
	var h = screen.availHeight-40;
	if (image.match(/\.(ipx)$/) != null) {
		url="/ipix_popup/?img="+image;
		if (lang) url = "/"+lang+url;
		window.open(url,"popupimage", "scrollbars=0, resizable=0, status=0, titlebar=0, width=400, height=300").focus();
	} else if (image.match(/\.((mov)|(swf))$/) != null) {
		window.open('/viewswf.php?p='+image, "panoimage", "left=0, top=0, scrollbars=0, resizable=1, width="+w+", height="+h).focus();
	}
}

