// JavaScript Document
// Copyright 2008 Ladislav Brychta

function detectVideoPlugins(debug) {

  this.debug = debug;

  this.reset = function() {
    this.tabMime = "";
    this.isMoz = false;
    this.isIE = false;
    this.isMac = false;
    this.isWin = false;
    this.pQuicktime = 0;
    this.pWinMedia = 0;
    this.pReal = 0;
  };

  this.init = function() {
    this.reset();
    this.browserDetection();
    this.pluginDetection();
  };

  this.plugMoz = function(plug) {
  	var find = '0';
  	if (this.tabMime.indexOf(plug) != -1) {
      if (navigator.mimeTypes[plug].enabledPlugin != null) {
        find = '1';
      }
    }
  	return find;
  }

  this.plugIE = function(plug) {
  	self.find = false;
  	document.write('<SCR' + 'IPT LANGUAGE=VBScript>\n on error resume next \n find = IsObject(CreateObject("' + plug + '"))</SCR' + 'IPT>\n');
  	if (self.find) {
      return '1';
    } else {
      return '0';
    }
  }
  
  this.browserDetection = function() {
    var ua = navigator.userAgent.toLowerCase();
    this.isMoz  = (navigator.appName.indexOf("Netscape") != -1);
    this.isIE  = (ua.indexOf("msie") != -1);
    this.isMac = (ua.indexOf("mac")!=-1);
    this.isWin = ((ua.indexOf("win")!=-1) || (ua.indexOf("32bit")!=-1));
  }
  
  this.pluginDetection = function() {
    if (this.isWin && this.isIE) {
      this.pQuicktime = this.plugIE("QuickTimeCheckObject.QuickTimeCheck.1");
      this.pWinMedia = this.plugIE("MediaPlayer.MediaPlayer.1");
      this.pReal = this.plugIE("rmocx.RealPlayer G2 Control.1");
    }
    if (!this.isWin || this.isMoz) {
      for (var i=0; i < navigator.mimeTypes.length; i++) {
        this.tabMime += navigator.mimeTypes[i].type.toLowerCase();
      }
      this.pQuicktime = this.plugMoz("video/quicktime");
      this.pWinMedia = this.plugMoz("application/x-mplayer2");
      this.pReal = this.plugMoz("audio/x-pn-realaudio-plugin");
    }
  }
  
  this.init();
}

/*
var videoPlugins = new detectVideoPlugins(0);
alert(videoPlugins.pQuicktime+' '+videoPlugins.pWinMedia+' '+videoPlugins.pReal);
*/

