//<!--
// DYNAMIC IMAGE SCRIPT
// (c) Copyright by RICS (Ralf Isau Creative Software) 2001 - 2010
// Version: 2.01.00 (09.04.2010)
// Last revised: 20.04.2010
// Note:	Anchor elements corresponding to images must be named
//			with the suffix "_a".
// Dependencies:	1. The script 'browsercheck.js' has to be loaded before!
//					2. The function 'od_setTagBackground' of the script 'opacity.js' has to be
//					   executed for all relating background-enabled elements before. 
//					2. In 'diLoad' all variants of 'strImgFileName' have to be
//					   in the same path as the image referenced by 'strImgName'!
//					3. For Internet Explorer: A file 'pixel.gif' with all transparent pixels
//						has to be put into the same path as the original image file!²

// GLOBAL VARIABLES:
	
// Check browser type:
var blnModernBrowser=false;
blnModernBrowser = (browser.versionGeneration >= 4);
intLastImage=-1;
objActualImage=new Object();
// if IE5.5+ on win32 PNGs will be displayed with AlphaImageLoader
if ((browser.isIE55 || browser.isIE6up) && !browser.isIE9up && browser.isWin32) {
	var blnPngAlpha = true;
	var strDefaultExtension=".png";
// else, if the browser ist PNG-enabled, then use that feature.
} else if ((browser.isGecko) || (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 blnPngNormal = true;
	var strDefaultExtension=".png";
	// Otherwise, we use plain old GIFs
} else {
	var strDefaultExtension=".gif";
}

// PROTOTYPE:
function DynImgObject(objImg, strImgFileName, strExtension) {
	if (blnModernBrowser) {
		if (objImg != null) {
			var strJustFileName = new String(strImgFileName);
			this.id = (objImg.id) ? objImg.id : objImg.name;
			this.Parent = objImg;

			//get original file name including path
			switch(objImg.tagName.toLowerCase()) { 
				case "img":
					this.srcOriginalFile = objImg.src;//IMG-tag
					this.on = priv_diImgOn;
					this.off = priv_diImgOff;
					this.deselect = priv_diImgDeselect;
					this.switchImage = priv_diSwitch;
					break;
				case "li":
					// break; firstable take the default calse for LI-tags.
					this.on = priv_diLIOn;
					this.off = priv_diLIOff;
					this.deselect = priv_diLISDeselect;
					this.switchImage = priv_diSwitch;
					if (objImg.OpacityBackground) {
						this.srcOriginalFile = objImg.OpacityBackground.bgOriginalFile;//MSIE5+, filter already intalled by "opacity.js"
					}
					else {// for non-IE-browsers without "style" object use default:
						try {
							this.srcOriginalFile = objImg.style.getPropertyValue('list-style-image');
						  } catch (e) {
							this.srcOriginalFile = "";
						}
						if (! this.srcOriginalFile) {
							var p = document.location.pathname.lastIndexOf("/");
							var rp = strImgFileName.lastIndexOf("/");
							p = (p == -1) ? "/" : document.location.pathname.substr(0,p) + "/";
							rp = (rp == -1) ? "" : strImgFileName.substr(0,rp) + "/";
							this.srcOriginalFile = (rp == -1) ?
									((document.location.protocol) ? document.location.protocol + "//" : "") 
									+ ((document.location.hostname) ? document.location.hostname + ":" : "")
									+ p + strImgFileName+"_n"+strExtension
								  : strImgFileName +"_n"+strExtension;
						}
					}
					break;
				default:
					this.on = priv_diBgOn;
					this.off = priv_diBgOff;
					this.deselect = priv_diBgDeselect;
					this.switchImage = priv_diSwitch;
					if (objImg.OpacityBackground) {
						this.srcOriginalFile = objImg.OpacityBackground.bgOriginalFile;//MSIE5+, filter already intalled by "opacity.js"
					}
					else {// for non-IE-browsers without "style" object use default:
						var p = document.location.pathname.lastIndexOf("/");
						p = (p == -1) ? "/" : document.location.pathname.substr(0,p) + "/";
						try {
							this.srcOriginalFile = objImg.style.getPropertyValue('background-image');
						  } catch (e) {
							this.srcOriginalFile = "";
						  }
						if (! this.srcOriginalFile) { 
							this.srcOriginalFile = ((document.location.protocol) ? document.location.protocol + "//" : "") 
												+ ((document.location.hostname) ? document.location.hostname + ":" : "")
												+ p + strImgFileName+"_n"+strExtension;
						}
					}
					break;
			}

			strJustFileName = strJustFileName.split("/");
			strJustFileName = strJustFileName[strJustFileName.length-1];

			this.srcPath = this.srcOriginalFile.split("/");// only the path
			this.srcFileName = this.srcPath[this.srcPath.length-1];//only the file name
			this.srcExtension = this.srcFileName.split(".");
			this.srcPath = this.srcOriginalFile.substr(0, this.srcOriginalFile.length-this.srcPath[this.srcPath.length-1].length);
			this.srcExtension = "." + this.srcExtension[this.srcExtension.length-1];
			this.srcNormal = this.srcFileName;
			//Additional file variants have to be into the same path
			this.srcHover = strJustFileName+"_h"+strExtension;
			this.srcSelected = strJustFileName+"_s"+strExtension;
			this.srcOpened = strJustFileName+"_o"+strExtension;
			if (blnPngAlpha) {
				this.srcCamouflage = "pixel.gif";
				this.objAnchor = GetObjectByIdOrName(this.id+"_a");
			}
		}
	}
}

// FUNCTIONS:
function diLoad(strImgName,strImgFileName,argExtension)
{
	var strExtension = strDefaultExtension;
	var objImg = GetObjectByIdOrName(strImgName);
	if (blnModernBrowser) {
		if (diLoad.arguments.length > 2) {
			//	Arg. 3 (optional): File extension (without leading dot) overrides default
			strExtension = argExtension;
		}
		if (objImg != null) {
			if ( objImg.DynImg == null ) { // Create new Dynamic Image if it don't already exits.
				objImg.DynImg = new DynImgObject(objImg, strImgFileName, strExtension);
			}
			if (blnPngAlpha) {
				objImg.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+objImg.DynImg.srcPath+objImg.DynImg.srcNormal+"', sizingMethod='crop')";
				objImg.src = objImg.DynImg.srcPath + objImg.DynImg.srcCamouflage;
			}
		}
	}
}

function diOn(strCurrentImage)
{
	objActualImage = GetObjectByIdOrName(strCurrentImage);
	if (objActualImage && objActualImage.DynImg) { objActualImage.DynImg.on(); }
}

/* private */ function priv_diImgOn()
{
	if (blnPngNormal) {
		this.Parent.src = this.srcPath + this.srcHover;
	}
	else {
		this.Parent.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.srcPath + this.srcHover+"', sizingMethod='crop')";
	}
}


/* private */ function priv_diBgOn()
{
	if (blnPngNormal) {
		this.Parent.style.setProperty('background-image', 'url("'+this.srcPath + this.srcHover + '")', '');
	}
	else {
		this.Parent.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.srcPath + this.srcHover+"', sizingMethod='crop')";
	}
}
/* private */ function priv_diLIOn()
{
	if (blnPngNormal) {
		// this.Parent.style.setProperty('list-style-image', 'url("'+this.srcPath + this.srcHover + '")', '');
	}
	else {
		this.Parent.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.srcPath + this.srcHover+"', sizingMethod='crop')";
	}
}

// diOff: Reset image to default status.
// - arg1 (optional): images's name or id
function diOff()
{
	if (diOff.arguments.length > 0) { objActualImage = GetObjectByIdOrName(diOff.arguments[0]); }
	if (objActualImage && objActualImage.DynImg) { objActualImage.DynImg.off(); }
}

/* private */ function priv_diImgOff()
{
	if (blnPngNormal) {
		this.Parent.src = this.srcPath + this.srcNormal;
	}
	else {
		this.Parent.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.srcPath + this.srcNormal+"', sizingMethod='crop')";
	}
}

/* private */ function priv_diBgOff()
{
	if (blnPngNormal) {
		this.Parent.style.setProperty('background-image', 'url("'+this.srcPath + this.srcNormal + '")', '');
	}
	else {
		this.Parent.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.srcPath + this.srcNormal+"', sizingMethod='crop')";
	}
}

/* private */ function priv_diLIOff()
{
	if (blnPngNormal) {
		if (this.srcNormal == this.srcFileName) {
			this.Parent.style.removeProperty('list-stile-image');
		} else {
			this.Parent.style.setProperty('list-stile-image', 'url("'+this.srcPath + this.srcNormal + '")', '!important');
		}
	}
	else {
		this.Parent.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.srcPath + this.srcNormal+"', sizingMethod='crop')";
	}
}

function diDeselect(strCurrentImage)
{
	objActualImage = GetObjectByIdOrName(strCurrentImage);
	if (objActualImage && objActualImage.DynImg) { objActualImage.DynImg.deselect(); }
}

/* private */ function priv_diImgDeselect()
{
	if (blnPngNormal) {
		this.Parent.src = this.srcPath + this.srcSelected;
	}
	else {
		this.Parent.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.srcPath + this.srcSelected+"', sizingMethod='crop')";
		if (this.objAnchor) { this.objAnchor.blur(); }
	}
}

/* private */ function priv_diBgDeselect()
{
	if (blnPngNormal) {
		this.Parent.style.setProperty('background-image', 'url("'+this.srcPath + this.srcSelected + '")', '');
	}
	else {
		this.Parent.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.srcPath + this.srcSelected+"', sizingMethod='crop')";
		if (this.objAnchor) { this.objAnchor.blur(); }
	}
}

/* private */ function priv_diLISDeselect()
{
	if (blnPngNormal) {
		this.Parent.style.setProperty('list-stile-image', 'url("'+this.srcPath + this.srcSelected + '")', '');
	}
	else {
		this.Parent.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.srcPath + this.srcSelected+"', sizingMethod='crop')";
		if (this.objAnchor) { this.objAnchor.blur(); }
	}
}

function diSwitch(strCurrentImage, strStatus)
{
	if (blnModernBrowser)
	{
		objActualImage = GetObjectByIdOrName(strCurrentImage);
		if (objActualImage) { objActualImage.DynImg.switchImage(strStatus); }
	} 
}

/* private */ function priv_diSwitch(strStatus)
{
	with (this) {
		switch(strStatus) {
			case "o":
				srcNormal = srcOpened;
				break;
			case "h":
				srcNormal = srcHover;
				break;
			case "s":
				srcNormal = srcSelected;
			default:
				srcNormal = srcFileName;
				break;
		}
		off();
	}
}
//-->
