/**************************************************
CheckPlugin.js

Coded by
Noel del Rosario
del.freeshell.org
del@freeshell.org

Description
Basic Plugin Detection Script
**************************************************/
// constructor function CheckPlugin
function CheckPlugin(sPluginName, sActiveXControlName, sVersion)
{
   // JavaScript hook
   function detectPlugin(sPluginName, sVersion)
   {
      var blnPluginFound = false;
      
      if (navigator.plugins && navigator.plugins.length > 0) 
      {
         for (var intPluginCount=0; intPluginCount<navigator.plugins.length; intPluginCount++)
         {
            // check to see if the plugin name exists
            if ( (navigator.plugins[intPluginCount].name.indexOf(sPluginName) >= 0) || (navigator.plugins[intPluginCount].description.indexOf(sPluginName) >= 0) )
            {
               // the plugin name has been found
               blnPluginFound = true;
               
               // check for the right version if one is provided
               if ( (sVersion != null) && (sVersion != '') )
               {
                  // version is string literal
                  if ( isNaN(sVersion) )
                  {
                     // check that the version is invalid
                     if (navigator.plugins[intPluginCount].description.indexOf(sPluginName) == -1)
                     {
                        blnPluginFound = false;
                     }
                  }
                  else
                  {
                     // set blnPluginFound to false
                     blnPluginFound = false;
                     sVersion = parseFloat(sVersion);
                     var sDescription = navigator.plugins[intPluginCount].description.split(" ");
                     for (var intDescriptionCount=0; intDescriptionCount<sDescription.length; intDescriptionCount++)
                     {
                        if ( (!isNaN(sDescription[intDescriptionCount])) && (parseFloat(sDescription[intDescriptionCount]) >= sVersion) )
                        {
                           blnPluginFound = true;
                           break;
                        }
                     }
                  }
               }
               // the plugin has been found, get out of the for loop
               break;
            }
         }
      }
      return blnPluginFound;
   }
   // VBScript hook
   if ( (navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('Opera') == -1) )
   {
      document.writeln('<script language="VBscript">');

      document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
      document.writeln('blnDetectableWithVB = False');
      document.writeln('If ScriptEngineMajorVersion >= 2 then');
      document.writeln('  blnDetectableWithVB = True');
      document.writeln('End If');
      
      document.writeln('\'this next function will detect most plugins');
      document.writeln('Function detectActiveXControl(activeXControlName)');
      document.writeln('  on error resume next');
      document.writeln('  detectActiveXControl = False');
      document.writeln('  If blnDetectableWithVB Then');
      document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
      document.writeln('  End If');
      document.writeln('End Function');
      
      document.writeln('</script>');
   }
   this.check = function()
   {
      if ( ((this.pluginName == null) || (this.pluginName == '')) && ((this.activeXControlName == null) || (this.activeXControlName == '')) )
      {
         alert("ERROR:\nPlease set the Plugin's Name or the ActiveX Control's Name.\n\nUSAGE:\nobj.pluginName = \"The Plugin's Name\"\nor\nobj.activeXControlName = \"The ActiveX Control's Name\"");

      }
      else
      {
         // plugin check
         if ( (this.pluginName !=null) && (this.pluginName != '') )
         {
            // check using JavaScript
            this.found = detectPlugin(this.pluginName, this.version);
         }
         // object check
         if ( (this.activeXControlName != null) && (this.activeXControlName != '') )
         {
            if ( (!this.found) && (navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('Opera') == -1) )
            {
               //check using VBScript
               this.found = detectActiveXControl(this.activeXControlName);
            }
         }
      }
   }
   this.reset = function()
   {
      this.pluginName = '';
      this.activeXControlName = '';
      this.version = '';
      this.found = false;
   }
   this.pluginName = sPluginName;
   this.activeXControlName = sActiveXControlName;
   this.version = sVersion;
   this.found = false;
}

/**************************************************
Image Overlay
**************************************************/
var imageDB2LargeImageOverlay
var imageDB2LargeExist = new Array();
function AddImageDB2Overlay()
{
	if (!(document.getElementById && document.getElementsByTagName)) return

	imageDB2LargeImageOverlay = document.createElement('div');
	imageDB2LargeImageOverlay.setAttribute('id', 'imageDB2LargeImageOverlay');
	imageDB2LargeImageOverlay.style.position = 'absolute';
	imageDB2LargeImageOverlay.style.visibility = 'hidden';
	imageDB2LargeImageOverlay.style.width = '300';
	imageDB2LargeImageOverlay.style.height = '225';
	imageDB2LargeImageOverlay.style.top = '0';
	imageDB2LargeImageOverlay.style.left = '0';
	imageDB2LargeImageOverlay.style.border = '1px solid #000000';
	imageDB2LargeImageOverlay.style.background = '#000000';
	imageDB2LargeImageOverlay.style.zindex = '1000000';

	var imageDB2LargeImage = document.createElement('img');
	imageDB2LargeImage.setAttribute('id', 'imageDB2LargeImage');
	imageDB2LargeImageOverlay.appendChild(imageDB2LargeImage);

	document.getElementsByTagName('body').item(0).appendChild(imageDB2LargeImageOverlay);

	var imgarr = document.body.getElementsByTagName('img');
	var imgTemp = new Array();
	var current_img;
	var nil_img;
	
	for (var i = 0; i < imgarr.length-1; i++)
	{
		if ( imgarr[i].getAttribute('src').toLowerCase().indexOf('imagedb2') != -1 && ( imgarr[i].getAttribute('src').toLowerCase().indexOf('_m.') != -1 || imgarr[i].getAttribute('src').toLowerCase().indexOf('_s.') != -1) )
		{
			if (!nil_img)
			{
				nil_img = imgarr[i].getAttribute('src').substr(0, imgarr[i].getAttribute('src').toLowerCase().lastIndexOf('/')+1) + '../nil.gif';
			}
			imgarr[i].onmouseover = function()
			{
				current_img = this;
				imageDB2LargeImage.setAttribute('src', this.getAttribute('src').toLowerCase().replace('_m.', '_l.').replace('_s.', '_l.'));
				
				if (this.captureEvents) this.captureEvents(Event.MOUSEMOVE);
				this.onmousemove = MoveImageDB2Overlay;
			}
			
			imgarr[i].onmouseout = function()
			{
				current_img = null;
				imageDB2LargeImageOverlay.style.visibility = 'hidden'
				imageDB2LargeImage.setAttribute('src', nil_img);
				
				if (this.releaseEvents) this.releaseEvents(Event.MOUSEMOVE);
				this.onmousemove = null;
			}
		}
	}
	imageDB2LargeImage.onload = function()
	{
		if (imageDB2LargeImage.getAttribute('src').indexOf('nil.gif') == -1)
		{
			imageDB2LargeImageOverlay.style.visibility = 'visible';
		}
	}
	imageDB2LargeImage.onerror = function()
	{
		imageDB2LargeImageOverlay.style.visibility = 'hidden';
		this.setAttribute('src', nil_img);
		current_img.onmouseover = null;
		current_img.onmouseout = null;
		current_img.onmousemove = null;
	}
}
function MoveImageDB2Overlay(evt)
{
	imageDB2LargeImageOverlay.style.left = (evt ? evt.pageX: window.event.clientX + document.body.scrollLeft) + 15;
	imageDB2LargeImageOverlay.style.top = (evt ? evt.pageY: window.event.clientY + document.body.scrollTop);
}