function IEContentLoaded(a, b) {
    var c = a.document,
        d = false,
        e = function () {
            if (!d) {
                d = true;
                b()
            }
        };
    (function () {
        try {
            c.documentElement.doScroll("left")
        } catch (a) {
            setTimeout(arguments.callee, 50);
            return
        }
        e()
    })();
    c.onreadystatechange = function () {
        if (c.readyState == "complete") {
            c.onreadystatechange = null;
            e()
        }
    }
}
function load() {
    LO = new login;
    setMenu(sec);
    if (sec == "gallery") {
        pshow = new Photos;
        pshow.load(4)
    }
}
function loginval(a) {
    var b = a;
    errcount = 0;
    flds = ["memUserName", "memPassword"];
    var c = flds.length;
    if (b) {
        while (c--) {
            fld = flds[c];
            lbl = document.getElementById(fld + "Label");
            fels = b.elements;
            if (fels[fld].value == "") {
                fels[fld].focus();
                lbl.innerHTML = "Required";
                errcount++
            } else {
                lbl.innerHTML = ""
            }
        }
        if (errcount > 0) {
            return false
        } else {
            return true
        }
    }
    return false
}
function setMenu(a) {
    if (a != "undefined" && a != "") {
        var b = $("nav_" + a);
        if (b) {
            b.className = "init"
        }
    }
}
function Photos() {
    var self = this;
    var arrlen = 0;
    var interval = 4e3;
    var photoslist = {};
    var photoarr = [];
    var photourls = [];
	var photofiles = [];
    var preloaderstring = '<div id="preloader" class="cnt"><br/><br/><br/><br/><br/><br/><span style="font-size:14px">Loading...</span><br/><img class="imgcnt" src="/vimages/ajaxloader.gif" width="32" height="32" alt=""  /></div>';
    var target = $("photos");
    var errbox = $("photoerr");
    var xhr = new XMLHttpRequest;
    var loadcheckInterval = null;
	var firstload = false;
	
	this.ajaximg = function(url) {
		var img = document.createElement('img');
        img.async = true;
		img.src = url;
		img.style.position = "absolute";
        img.style.opacity = 0;
        img.style.filter = "alpha(opacity=0)";
        img.style.display = "none";
		return img;
	};
	
    this.load = function(n) {
        target.innerHTML = preloaderstring;
        xhr.open("GET", "/gallery/json/gallery" + n + ".json?"+Math.round(), true);
        xhr.setRequestHeader("Content-Type", "application/json");
        xhr.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		xhr.send(null);
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                response = xhr.responseText;
                text = eval("(" + response + ")");
                if (typeof text == "object") {
                    photoslist = text;
                    photoarr = photoslist.Photos;
                    arrlen = photoarr.length;
					startint = Math.floor(Math.random()*arrlen);
					for (i = 0; i < arrlen; i++) {
						var imgurl = "/gallery/photos/" + photoarr[i].fullfilename;
						photourls[i] = imgurl;
						//photofiles[i] = b;
                    }
					self.play(startint);
					
                } else {
                    target.innerHTML = "Error Parsing JSON"
                }
            } else {
                //target.innerHTML = preloaderstring;
            }
        };
    };
    this.next = function (a) {
        var to;
		var b = a;
        var to = setTimeout(function () {
            self.play(b + 1)
        }, interval)
    };
	this.cleaner = function(a) {
		//cleaner
		var imgarr = target.getElementsByTagName('img');
		for (i = 0; i < imgarr.length; i++) {	
			var oldNode = target.removeChild(imgarr[i]);
			delete oldNode;
		}
			
	};
	
    this.play = function (a) {
        clearTimeout(loadcheckInterval);
        if (arrlen > 0) {
            if (a > arrlen - 1) {
                a = 0
            }
			//Async Attach Image
			//var b = photofiles[a];
			var b = document.createElement('img');
			b.async = true;
			b.src = photourls[a];
            b.style.position = "absolute";
        	b.style.opacity = 0;
        	b.style.filter = "alpha(opacity=0)";
        	b.style.display = "none";
			
			(function loader() {
	            if (b.complete) {
					if ($('preloader')) target.removeChild($('preloader'));
					//if (a < arrlen) {
						target.appendChild(b);
					//}
					
					b.style.display = "block";
	                if (firstload) {
						var ajx = new tJS.fx.animate(b, "opacity", 900, {
		                    start: 0,
		                    end: 100,
		                    easing: "easeOutQuad"
		                }, function() { self.next(a); self.cleaner(a); });
						delete ajx;
					} else {
						//First Loaded Photo
						firstload = true;
						var ajx = new tJS.fx.animate(b, "opacity", 300, {
		                    start: 0,
		                    end: 100,
		                    easing: "easeOutQuad"
		                }, function() { self.next(a); });
						delete ajx;
					}
					delete b;
	            } else {
					//alert("hi");
	                loadcheckInterval = setTimeout(function () {
	                    loader();
	                }, 100)
	            }
			})();
			
			
			
        } else {
            errbox = "No Photos Currently Available"
        }
    }
}
function login() {
    var a = this;
    this.fade = 75;
    var b = $("content");
    var c = $("photos");
    var d = $("loginbg");
    var e, f, g;
    if ($("contentadmin")) {
        e = $("contentadmin");
        f = $("contentadmin").offsetWidth;
        g = $("contentadmin").offsetHeight
    } else {
        e = $("content") ? $("content") : $("photos");
        f = $("content") ? $("content").offsetWidth : $("photos").offsetWidth;
        g = $("content") ? $("content").offsetHeight : $("photos").offsetHeight
    }
    var h = $("loginholder");
    this.SessionVerify = function () {
        var a = new XMLHttpRequest;
        a.open("GET", "/members/sessioncheck.aspx?", true);
        a.onreadystatechange = function () {
            if (a.readyState == 4 && a.status == 200) {
                response = parseInt(a.responseText);
                if (response > 0) {
                    location.href = "/members/members.aspx"
                } else {
                    return
                }
            }
        };
        a.send()
    };
    this.loader = function () {
        a.SessionVerify();
        if (!$("loginbg")) {
            newdiv = document.createElement("div");
            newdiv.setAttribute("id", "loginbg");
            newdiv.style.width = f + "px";
            newdiv.style.height = g + "px";
            e.appendChild(newdiv);
            var b = new tJS.fx.animate(newdiv, "opacity", 200, {
                start: 0,
                end: this.fade,
                easing: "easeOutQuad"
            }, function () {
                newdiv.onclick = function () {
                    a.closeit()
                }
            });
            delete b;
            setTimeout(function () {
                h.style.display = "block";
                document.forms[0]["memUserName"].focus();
                tJS.fx.animate(h, "opacity", 200, {
                    start: 0,
                    end: 95,
                    easing: "easeInQuart"
                })
            }, 150)
        }
    };
    this.closeit = function () {
        h.style.display = "none";
        h.style.opacity = 0;
        h.style.filter = "alpha(opacity=0)";
        var a = new tJS.fx.animate($("loginbg"), "opacity", 300, {
            start: this.fade,
            end: 0,
            easing: "easeOutQuad"
        }, function () {
            e.removeChild($("loginbg"))
        });
        delete a
    }
}
function $(a) {
    return document.getElementById(a)
}
var LO, sec, pshow;
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", load, false)
} else {
    IEContentLoaded(window, load)
}
