﻿//<!--
//---------------------------------------------------------------
// Opacity Displayer, Version 1.0
// Copyright Michael Lovitt, 6/2002.
// Distribute freely, but please leave this notice intact.
//---------------------------------------------------------------

// Note: Script to help the buggy IE for correct display of PNGs with opacity.
// New functions added and developed further by Ralf Isau, 7/2004.
// Last revised: 10.04.2010 by Ralf Isau (Rev. 1.1)

// OPACITY OBJECT
//
// PROTOTYPE Instantiates the object, defines the properties and methods.
function OpacityObject(divId, strPath) {
	this.id = divId;
	this.path = strPath;
	if (ns){
		if (browser.versionGeneration>=5) {
			this.layerObject = document.getElementById(divId).style;
		} else { 
			this.layerObject = eval("document."+divId);
		}
	} else {
		this.layerObject = eval(divId + ".style");
	}
	this.setBackground = od_object_setBackground;
}
// Uses AlphaImageLoader filter, or the css background property,
// as appropriate, to apply a PNG or GIF as the background of the layerObject.
function od_object_setBackground() {	
	if (pngAlpha) {
		this.layerObject.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.path+".png', sizingMethod='crop')";
	} else if (pngNormal) {
		this.layerObject.backgroundImage = 'url('+this.path+'.png)';
	} else {
		this.layerObject.backgroundImage = 'url('+this.path+'.gif)';
	}
}

// OPACITY DISPLAY FUNCTION
// Outputs the image as a div with the AlphaImageLoader, or with
// a standard image tag.
function od_displayImage(strId, strPath, intWidth, intHeight, strClass, strAlt) {	
	if (pngAlpha) {
		// document.write('<div style="height:'+intHeight+'px;width:'+intWidth+'px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+strPath+'.png\', sizingMethod=\'crop\')" id="'+strId+'" class="'+strClass+'"></div>'); 
		var strFilter = '<div style="height:'+intHeight+'px; width:'+intWidth+'px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+strPath+'.png\', sizingMethod=\'crop\')"';
		if (strId != null && strId != "" ) { strFilter = strFilter  + ' id="'+strId+'"'; }
		if (strClass != null && strClass != "") { strFilter = strFilter + ' class="'+strClass+'"'; }
		strFilter = strFilter + "></div>";
		document.write(strFilter);
	} else if (pngNormal) {
		document.write('<img src="'+strPath+'.png" width="'+intWidth+'" height="'+intHeight+'" name="'+strId+'" border="0" class="'+strClass+'" alt="'+strAlt+'" />');
	} else {
		document.write('<img src="'+strPath+'.gif" width="'+intWidth+'" height="'+intHeight+'" name="'+strId+'" border="0" class="'+strClass+'" alt="'+strAlt+'" title="'+ strAlt+'" />');
	}
}

// PROTOTYPE 'OpacityBackgroundObject' only used by MSIE 5+ Win:
function OpacityBackgroundObject(objBg) {
	if (objBg != null) {
		this.Parent = objBg;
		this.bgOriginalFile = (pngAlpha) ? objBg.currentStyle.backgroundImage :  objBg.style.backgroundImage;//original file name including path and url
		// remove 'url()' from path
		var regExp = /(url\(\s?["']?)([^"')]*)/i;
		var xx = regExp.exec(this.bgOriginalFile);
		this.bgPath = (xx) ? xx[2] : this.bgOriginalFile;
		xx = this.bgPath;
		this.bgPath = this.bgPath.split("/");// only the path
		this.bgFileName = this.bgPath[this.bgPath.length-1];//only the original file name
		this.bgPath = xx.substr(0, xx.length-this.bgPath[this.bgPath.length-1].length);
	}
}

// Replaces a 'background-image' by a child DIV-tag which uses
// AlphaImageLoader filter to apply a PNG or GIF with opacity.
// - arg1: Object add opacity with
// - arg2: CSS style to be associated with newly created DIV-tag containing the image (optional)
// - arg3: CSS style to be associated with the container (parent) tag (optional)
// - arg4: unique id forthe  newly created DIV-tag containing the image (optional)
// Returns: "auto"
function od_setTagBackground(objTag,strChildCSStext,strContainerCSStext,strId) {	
if (pngAlpha && !objTag.OpacityBackground) {
		if (objTag.currentStyle.backgroundImage) {
			objTag.OpacityBackground = new OpacityBackgroundObject(objTag);
			objTag.style.backgroundImage = "none";
			objTag.runtimeStyle.backgroundImage = "none";
			var ChildNode = document.createElement("DIV");
			if (objTag.childNodes.length > 0) {
				ChildNode = objTag.insertBefore(ChildNode, objTag.childNodes(0));
			}
			else {
				ChildNode = objTag.insertBefore(ChildNode);
			} 
			if (od_setTagBackground.arguments.length > 1 && strChildCSStext) ChildNode.style.cssText = strChildCSStext;
			if (od_setTagBackground.arguments.length > 2 && strContainerCSStext) objTag.runtimeStyle.cssText = strContainerCSStext;
			if (od_setTagBackground.arguments.length > 3 && strId) ChildNode.id = strId;
			ChildNode.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + objTag.OpacityBackground.bgPath + objTag.OpacityBackground.bgFileName + "', sizingMethod='image')";
			return("auto");
		}
	}
	return("auto");
}

// GLOBAL VARIABLES
// if IE >= 5.5 and < 7.0 on win32, then display PNGs with AlphaImageLoader
if ((browser.isIE55 || browser.isIE6up) && !browser.isIE7up && browser.isWin32) {
	var pngAlpha = true;
	var strExt = ".png";
// else, if the browser can display PNGs normally, then do that. that list includes:
	//     -Gecko Engine: Netscape 6 or Mozilla, Mac or PC
	//     -IE5+ Mac (OpacityObject applies the background image at 100% opacity)
	//     -IE7+ Win
	//     -Opera 6+ PC
	//     -Opera 5+ Mac (Doesn't support dynamically-set background images)
	//     -Opera 6+ Linux
	//	   -Safari 
	//     -Omniweb 3.1+ 
	//     -Icab 1.9+ 
	//     -WebTV 
	//     -Sega Dreamcast
} else if ((browser.isGecko) || (browser.isIE7up) || (browser.isIE5upMac) || (browser.isOpera && browser.isWin && browser.versionMajor >= 6) || (browser.isOpera && browser.isUnix && browser.versionMajor >= 6) || (browser.isOpera && browser.isMac && browser.versionMajor >= 5) || (browser.isSafari) || (browser.isOmniweb && browser.versionMinor >= 3.1) || (browser.isIcab && browser.versionMinor >= 1.9) || (browser.isWebtv) || (browser.isDreamcast)) {
	var pngNormal = true;
	var strExt = ".png";
	// otherwise, we use plain old GIFs
} else {
	var strExt = ".gif";
}

var ns = (document.all)?false:true;
//-->
