//----------------------------------------------------------------	
function plugin_ImageMessage(id,isShow)
	{
	var isVizible="hidden";
//	objcontainer=document.getElementById("pluginImageMessage_container"+id);
	
	if(isShow==1)
		{
		isVizible="visible";
		}
	document.getElementById("pluginImageMessage_header"+id).style.visibility=isVizible;
	document.getElementById("pluginImageMessage_footer"+id).style.visibility=isVizible;
	}
//----------------------------------------------------------------	
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}
//----------------------------------------------------------------	
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}	
//----------------------------------------------------------------	

function plugin_ImageMessageInit()
	{
	if (!document.getElementsByTagName){ return; }
	var imgs = document.getElementsByTagName('img'); 
	var ImgCntr=1;
	var LastTitle="";
	var LastUrl="";
	for (var i=0; i<imgs.length; i++)
		{
		var img = imgs[i];
		
		var relAttribute = String(img.getAttribute('rel'));
		var isActive=false;

		if (relAttribute.toLowerCase().match('imagemessage'))
			{
			Title=img.parentNode.title;
			TrgUrl=img.parentNode.href;
			if(typeof(TrgUrl)!="undefined")
				LastUrl=TrgUrl;
			else
				TrgUrl=LastUrl;
			if(Title!=img.title) Title=img.title;
			if(Title!=img.alt) Title=img.alt;
			img.style.border="0px";
			img.style.margin="0px";
			img.style.padding="0px";
			img.parentNode.title="";
			img.title="";
			ImgCode=img.outerHTML;

//			alert(img.parentNode.outerHTML);
			
			if(LastTitle!=Title)
				{
				LastTitle = Title;
				ImgCntr=0;
				}
			if( img.width>=120 && img.height>=90 ) 					
				{
				ImgCntr++;
				isActive=true;
				}
			
			outCode="<div style='display:inline-table;border:0;margin:0;padding:0;' id=pluginImageMessage_"+i+">";
			outCode+="<div id=pluginImageMessage_container"+i+" ";
			outCode+=" style='width:"+img.width+"px;height:"+img.height+"px;' class=pluginImageMessage_container ";
			if(isActive) 	outCode+=" onmouseover='plugin_ImageMessage("+i+",1);' onmouseout='plugin_ImageMessage("+i+",0);' ";
			outCode+=">";
			outCode+="<a href='"+TrgUrl+"' target=_blank>";
			outCode+=ImgCode;
			outCode+="<font id=pluginImageMessage_header"+i+" class=pluginImageMessage_header><b>"+ImgCntr+":</b> "+Title+"</font>";
			outCode+="<font id=pluginImageMessage_footer"+i+" class=pluginImageMessage_footer>Click to view<br>full gallery</font>";
			if(isActive) 	outCode+="<div class=pluginImageMessage_curl></div>";
			outCode+="</a></div></div>";

			img.parentNode.outerHTML = img.parentNode.outerHTML.replace(ImgCode, outCode);
			} 
		}
	}

if(navigator.userAgent.indexOf("Firefox")!=-1)
	{
	Node.prototype.getAttributes = function(){
		var attStr = "";
		if(this && this.attributes.length > 0){
			for(a = 0; a < this.attributes.length; a ++){
				attStr += " " + this.attributes.item(a).nodeName + "=\"";
				attStr += this.attributes.item(a).nodeValue + "\"";
			}
		}
		return attStr;
	}

	Node.prototype.getInsideNodes = function(){
		if(this){
			var cNodesStr = "", i = 0;
			var iEmpty = /^(img|embed|input|br|hr)$/i;
			var cNodes = this.childNodes;
			for(i = 0; i < cNodes.length; i ++){
				switch(cNodes.item(i).nodeType){
					case 1 :
						cNodesStr += "<" + cNodes.item(i).nodeName.toLowerCase();
						if(cNodes.item(i).attributes.length > 0){
							cNodesStr += cNodes.item(i).getAttributes();
						}
						cNodesStr += (cNodes.item(i).nodeName.match(iEmpty))? "" : ">";
						if(cNodes.item(i).childNodes.length > 0){
							cNodesStr += cNodes.item(i).getInsideNodes();
						}
						if(cNodes.item(i).nodeName.match(iEmpty)){
							cNodesStr += " />";
						} else {
							cNodesStr += "</" + cNodes.item(i).nodeName.toLowerCase() + ">";
						}
						break;
					case 3 :
						cNodesStr += cNodes.item(i).nodeValue;
						break;
					case 8 :
						cNodesStr += "<!--" + cNodes.item(i).nodeValue + "-->";
						break;
				}
			}
			return cNodesStr;
		}
	}

	HTMLElement.prototype.__defineGetter__("outerHTML", function() {
		var strOuter = "";
		var iEmpty = /^(img|embed|input|br|hr)$/i;
		switch(this.nodeType){
			case 1 :
				strOuter += "<" + this.nodeName.toLowerCase();
				strOuter += this.getAttributes();
				if(this.nodeName.match(iEmpty)){
					strOuter += " />";
				} else {
					strOuter += ">" + this.getInsideNodes();
					strOuter += "</" + this.nodeName.toLowerCase() + ">";
				}
				break;
			case 3 :
				strOuter += this.nodeValue;
				break;
			case 8 :
				cNodesStr += "<!--" + this.nodeValue + "-->";
				break;
		}
		return strOuter;
	});

	HTMLElement.prototype.__defineSetter__("outerHTML", function(str) {
		var iRange = document.createRange();

		iRange.setStartBefore(this);

		var strFragment = iRange.createContextualFragment(str);
		var sRangeNode = iRange.startContainer;

		iRange.insertNode(strFragment);
		sRangeNode.removeChild(this);
	});
	}
	
plugin_ImageMessageInit();
	