﻿var debug=false;

function GetQuest3DPlayer () {
	return document.getElementById("Quest3DObject");
}
	
function DetectQuest3DPlayer () {
	var detected = false;
	if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.toLowerCase().indexOf("win") != -1) {
			detected = DetectQuest3DPlayerActiveX();
	}else {
		if (navigator.mimeTypes && navigator.mimeTypes["application/quest"]) {
			if (navigator.mimeTypes["application/quest"].enabledPlugin && navigator.plugins && navigator.plugins["Quest3D Player"]) {
				detected = true;	
			}
		}	
	}
	return detected;	
}

function CreateQuest3DPLayer(URL, width, height, containerElement){
	width = (width==null ? 640 : width);
	height = (height==null ? 480 : height);
	URL = (URL==null ? "no 3d specified in html" : URL);
	var sHTML="";
	
	if(debug)alert("detecting browser");
	
	if (DetectQuest3DPlayer()) {	
		if (navigator.appVersion.indexOf("MSIE") != -1){
			sHTML += '<SCRIPT LANGUAGE="javascript" FOR=Quest3DObject Event="OnEvent">\n';
			sHTML += 'onEvent();\n';
			sHTML += '</SCRIPT>\n';
			sHTML += '<object id="Quest3DObject" classid="clsid:12D81C14-0878-4EA2-8E12-618A9867818A" width="'+width+'" height="'+height+'" CODEBASE="http://www.quest3d.com/webplugin/download/quest3dactivex41.cab"> \n';
			sHTML += '  <param name="URL" value="'+URL+'" /> \n';
			sHTML += '  <param name=name="BackColor" value="16777215" /> \n';
			sHTML += '  <param name="CheckUpdate" value=1 /> \n';
			sHTML += '</object>';
		}else{		
			sHTML += '<embed id="Quest3DObject" documentURL ="'+ document.URL +'" src="'+URL+'" type="application/quest" width=' + width + ' height=' + height + ' checkUpdate=1>\n';
		}
		
		if(debug)alert(sHTML);
		
		if(containerElement!=null){
		    document.getElementById(containerElement).innerHTML = sHTML;
		}else{
		    document.write(sHTML);
		}
		
	}else{
	    if(debug)alert("No quest");
		
		installerURL = "http://quest3d.com/webplugin/quest3dplayer_4_1_t_install.exe";
		
		/*
		sHTML += '<div align="center" width="'+width+'" height="'+height+'"> \n';
		sHTML += '<table border="0" width="'+width+'" height="'+height+'" style="border-collapse: collapse" bgcolor="#FFFFFF"><tr><td align="center">';
		sHTML += '<a href= ' + installerURL + '><img src="http://www.quest3d.com/webplugin/getquest3dplayer.png" border="0"/></a>\n';
		sHTML += '</td></tr></table></div> \n';
		*/
		
		sHTML += "<p>Du skal have installeret den gratis Quest3D plugin for at se vores 3D modeller.</p>";
		sHTML += "<p><a href='" + installerURL + "'>Klik her</a> for at downloade plugin.</p>";
		
		if(debug)alert(sHTML);
		
		if(containerElement!=null){
		    document.getElementById(containerElement).innerHTML = sHTML;
		}else{
		    document.write(sHTML);
		}
			
		AutomaticReload();
	}	
}

function AutomaticReload () {
	navigator.plugins.refresh();
	if (DetectQuest3DPlayer())
		window.location.reload();
	setTimeout('AutomaticReload()', 500)
}

function QSetValue(group, channelname, value){
	GetQuest3DPlayer().SetChannelValue(group, channelname, value);
}
function QSetText(group, channelname, text){
	GetQuest3DPlayer().SetChannelText(group, channelname, text);
		
}

function QGetValue(group, channelname, value){
	return GetQuest3DPlayer().ChannelValue(group, channelname);
}
function QGetText(group, channelname, text){
	return GetQuest3DPlayer().ChannelText(group, channelname);
}



function donealready() {
    
  if(debug)alert("checkpoint");
    
  var done;
  var q = GetQuest3DPlayer();
  
  if(q){
	  if(QGetValue("loader", "ready", null)==1){
		  document.getElementById("quest3dloader").style.display="none";
		  document.getElementById("quest3dcontainer").style.width="539px";
		  document.getElementById("quest3dcontainer").style.height="400px";
		  document.getElementById("quest3dcontainer").style.visibility="visible";
		  done=true;
	  }
  }
  if(!done)setTimeout("donealready()",100);
}

if(document.addEventListener){ // FF, NS 
    document.addEventListener("DOMContentLoaded", donealready, false); 
} else { // IE
    window.attachEvent("onload", donealready); 
}
