// Image Thumbnail Viewer II - By Dynamic Drive
// http://www.dynamicdrive.com
// This notice must stay intact for legal use

var Viewer = {
    EnableTitle: true,
    EnableTransition: true,
    HideImgMouseOut: false,

    IEFilterString: 'progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0 Duration=0.7)',
    IEFilterEnabled: document.compatMode && window.createPopup? true : false,
    ImageArr:[],
    ImageLinks:[],
    Started: false,

    LoadImage:function(Obj) {
        var Path = Obj.getAttribute("href");
        var Container = document.getElementById(Obj.getAttribute("rev").split("::")[0]);
        var Dest = Obj.getAttribute("rev").split("::")[1];
        var Description = (Viewer.EnableTitle && Obj.getAttribute("title"))? Obj.getAttribute("title") : "";
        var ImageHtml = '<img src="' + Path + '" style="border-width: 1px" />';
        if (typeof Dest != "undefined") ImageHtml = '<a href="' + Dest + '">' + ImageHtml + '</a>';
        if (Description != "") ImageHtml += '<br /><br />' + Description;
        if (this.IEFilterEnabled) {
            Container.style.filter=this.IEFilterString;
            Container.filters[0].Apply();
        }
        Container.innerHTML = ImageHtml;
        //document.execCommand('Copy', true, ImageHtml);
        //alert(ImageHtml);
        this.CurrentImage = Container.getElementsByTagName("img")[0];
        this.CurrentImage.onload = function() {
            if (Viewer.IEFilterEnabled) Container.filters[0].Play();
        }
        this.CurrentImage.onerror=function() {
            if (Viewer.IEFilterEnabled) Container.filters[0].Stop();
        }
    },

    HideImage:function(Obj) {
        var Container = document.getElementById(Obj.getAttribute("rev").split("::")[0]);
        Container.innerHTML = "";
    },

    Clean:function() {
        if (this.CurrentImage) {
            this.CurrentImage.onload = null;
            this.CurrentImage.onerror = null;
            this.CurrentImage = null;
        }
        this.Container=null;
        for (var i=0; i<this.ImageLinks.length; i++){
            this.ImageLinks[i].onclick = null;
            this.ImageLinks[i].onmouseover = null;
            this.ImageLinks[i].onmouseout = null;
        }
    },

    AddEvent:function(Target, Func, Type) {
        var Type=(window.addEventListener)? Type : "on" + Type;
        if (Target.addEventListener)
            Target.addEventListener(Type, Func, false);
        else if (Target.attachEvent)
            Target.attachEvent(Type, Func);
    },

    Start:function() {
        this.IEFilterEnabled = (this.IEFilterEnabled && this.EnableTransition);
        var Links = document.getElementsByTagName("a");
        for (var i=0; i<Links.length; i++) {
            if (Links[i].getAttribute("rel") && /enlargeimage:/i.test(Links[i].getAttribute("rel"))) {
                var initType=Links[i].getAttribute("rel").split("::")[1];
                if (initType=="mouseover") {
                    this.ImageArr[this.ImageArr.length] = new Image();
                    this.ImageArr[this.ImageArr.length-1].src = Links[i].href;
                    Links[i]["onclick"] = function() {
                        return false;
                    }
                }
                Links[i]["on"+initType] = function() {
                    Viewer.LoadImage(this);
                    return false;
                }
                if (this.HideImgMouseOut) Links[i]["onmouseout"] = function() {
                    Viewer.HideImage(this);
                }
                this.ImageLinks[this.ImageLinks.length] = Links[i];
            }
        }
    }
}


if (document.addEventListener)
    Viewer.AddEvent(document, function() {Viewer.Started=1; Viewer.Start();}, "DOMContentLoaded");
else if (document.all && document.getElementsByTagName("a").length>0) {
    Viewer.Started = 1;
    Viewer.Start();
}

Viewer.AddEvent(window, function() {if (!Viewer.Started) Viewer.Start()}, "load");
Viewer.AddEvent(window, function() { Viewer.Clean(); }, "unload");
