﻿// Object to handle creating a layer and rendering the required flash object
function Viewer(a)
{
    this.fi = a;
    this.fp = "/viewer.swf";
    this.fo = new SWFObject(this.fp, "viewer", "100%", "100%", "8", "#181818");
    this.fs = "~/simpleviewer.xml?pageId=" + a;
    this.fl = "gallery";
    this.fc = "flashcontent";
} 
Viewer.prototype.show = function()
{
    var e=document.createElement("div");
    e.setAttribute("id",this.fl);
    e.style.top = (window.pageYOffset ? window.pageYOffset : (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop)) +"px";
    
    var f = document.createElement("div");
    f.setAttribute("id",this.fc);
    e.appendChild(f);
    
    var a=document.createElement("a");
    a.setAttribute("href", "javascript:HideGallery();");
    var i=document.createElement("img");
    i.setAttribute("src", "/Images/misc/close.png");
    i.setAttribute("id", "galleryclose");
    i.setAttribute("alt", "Close");
    a.appendChild(i);
    f.appendChild(a);
    
    var b=document.getElementById("mainbox");
    b.appendChild(e);
    
    this.draw();
};   
Viewer.prototype.draw = function()
{
    // SIMPLEVIEWER CONFIGURATION OPTIONS
    // To use an option, uncomment it by removing the "//" at the start of the line
    // For a description of config options, go to: 
    // http://www.airtightinteractive.com/simpleviewer/options.html
    this.fo.addVariable("xmlDataPath", this.fs);
    //this.fo.addVariable("firstImageIndex", "5");	
    //this.fo.addVariable("langOpenImage", "Open Image in New Window");
    //this.fo.addVariable("langAbout", "About");	
    //this.fo.addVariable("preloaderColor", "0xFFFFFF");    
    this.fo.write(this.fc);
    this.overflow();
    
    //Close
    var a=document.createElement("a");
    a.setAttribute("href", "javascript:HideGallery();");
    a.setAttribute("id", "galleryclose");
    a.appendChild(document.createTextNode("Close"));
    document.getElementById(this.fc).appendChild(a);
}
Viewer.prototype.hide = function()
{
    var e = document.getElementById(this.fl);
    e.parentNode.removeChild(e);   
    this.overflow();
}
Viewer.prototype.overflow = function()
{
    var e,f;
    for (var i=0;i<document.childNodes.length;i++){
    if(document.childNodes[i].tagName=="HTML"){e=document.childNodes[i];break;}}
    if (e){f = e.style.overflow;e.style.overflow = f == "hidden" ? "auto" : "hidden" ;}
}


var v;
function HideGallery()
{
    v.hide();
}
function DisplayGallery(a)
{    
    v = new Viewer(a);
    v.show();
}
function rewriteHref(o,i)
{
    if (document.getElementById){
        var e=document.getElementById(o);
        if (e){
            e.href="javascript:DisplayGallery("+i+");";}
    }
}