var cti = 0;
var dur = 7;
var ct = 0;
var cache = [];
var hole = [];
var sstop = 0;
var spause = 1;
var randinc = 1;
function getnext() {
    var a = (iHoleCt + cti) % iHoleCt;
    var n = ct % portPhotos.length;
    var b = imagenames[a];
    if (hole[a] == null || hole[a].src == null) {
        var c = 0;
        var d = 0;
        try {
            c = document[b].width;
            d = document[b].height
        } catch (ex) { }
        var e = (c > d) ? c : d;
        var f = 0;
        var g = -1;
        var h = (iHoleCt >= 3) ? 3 : 1;
        for (i = 0; i < h; i++) {
            var j = ((i + 1) * n) - 1;
            if (cache[j] == null) {
                if (g < 0) g = i;
                continue
            }
            var k = cache[j].src;
            if (k.indexOf('&s=' + e.toString()) > 0) {
                f = 1;
                hole[a] = cache[j];
                break
            }
        }
        if (f == 0 && g >= 0)
        {
        	var j = ((g + 1) * n) - 1;
        	cache[j] = new Image();
        	cache[j].src = portPhotos[n].Src + "&s=" + e;
        	hole[a] = cache[j]
        }

        if (hole[a] == null)
        {
        	// Fix bug where holes stop getting refreshed. Just init the whole thing.
        	cache = [];
        	ct = iHoleCt + iStart;
        	if (iHoleCt == 1 && iPortCt > 3)
        	{
        		if ((iPortCt % 3) != 0) randinc = 3;
        		else if (iPortCt > 5 && (iPortCt % 5) != 0) randinc = 5;
        		else if (iPortCt > 7 && (iPortCt % 7) != 0) randinc = 7;
        		else if (iPortCt > 11 && (iPortCt % 11) != 0) randinc = 11
        	}
        	if (iPortCt > iHoleCt && iHoleCt > 0)
        	{
        		if (iHoleCt > 1) dur = 3;
        		getnext();
        	}
        }
    }
}
function switchImg() {
    if (sstop == 1) return 0;
    var a = (iHoleCt + cti) % iHoleCt;
    var n = ct % portPhotos.length;
    if (imagenames.length > a - 1) {
        var b = imagenames[a];
        var c = 0;
        if (document.all && window.ActiveXObject && document[b]) {
            document[b].style.filter = "blendTrans(duration=2)";
            document[b].filters.blendTrans.Apply()
        }
        if (hole[a] != null && hole[a].complete) {
            if (document[b]) {
                if (document.all && window.ActiveXObject) document[b].filters.blendTrans.Play();
                document[b].src = hole[a].src;
            }
            hole[a] = null;
            c = 1;
            ct = ct + randinc;
            cti = cti + 1;
            getnext()
        }
        setTimeout("switchImg()", c ? (dur * 1000) : 500);
        return 1
    }
}
function slideInit() {
    if (document.images) {
        ct = iHoleCt + iStart;
        if (iHoleCt == 1 && iPortCt > 3) {
            if ((iPortCt % 3) != 0) randinc = 3;
            else if (iPortCt > 5 && (iPortCt % 5) != 0) randinc = 5;
            else if (iPortCt > 7 && (iPortCt % 7) != 0) randinc = 7;
            else if (iPortCt > 11 && (iPortCt % 11) != 0) randinc = 11
        }
        if (iPortCt > iHoleCt && iHoleCt > 0) {
            if (iHoleCt > 1) dur = 3;
            getnext();
            setTimeout("switchImg()", dur * 1000)
        }
    }
}
function slideStart(a) {
    spause = !spause;
    if (a == 1) spause = 0;
    if (spause) {
        if (iPortCt > iHoleCt) {
            sstop = 0;
            setTimeout("switchImg()", dur * 1000)
        }
    } else sstop = 1;
    if (document.images && document.images["ctl00_CPCenter_ibPlay"] != null) {
        var s = document.images["ctl00_CPCenter_ibPlay"].src;
        if (spause) s = s.replace("play", "pause");
        else s = s.replace("pause", "play");
        document.images["ctl00_CPCenter_ibPlay"].src = s
    }
    if (document.images && document.images["ibPlay"] != null) {
        var s = document.images["ibPlay"].src;
        if (spause) s = s.replace("play", "pause");
        else s = s.replace("pause", "play");
        document.images["ibPlay"].src = s
    }
}
function incPhoto(a) {
    sstop = 1;
    if (spause) {
        if (document.images && document.images["ctl00_CPCenter_ibPlay"] != null) {
            var s = document.images["ctl00_CPCenter_ibPlay"].src;
            s = s.replace("pause", "play");
            document.images["ctl00_CPCenter_ibPlay"].src = s
        }
        if (document.images && document.images["ibPlay"] != null) {
            var s = document.images["ibPlay"].src;
            s = s.replace("pause", "play");
            document.images["ibPlay"].src = s
        }
        spause = 0
    }
    ct = ct + a;
    if (ct < 0) ct = iPortCt - 1;
    if (ct >= iPortCt) ct = 0;
    var n = (ct >= 1 ? ct - 1 : iPortCt - 1) % portPhotos.length;
    if (imagenames.length > 0) {
        imagename = imagenames[0];
        var b = 0;
        var c = 0;
        try {
            b = document[imagename].width;
            c = document[imagename].height
        } catch (e) { }
        var d = (b > c) ? b : c;
        document.images[imagename].src = portPhotos[n].Src + "&s=" + d;
    }
}
function showOne(a) {
    try {
        var b = document.images[a].src;
        var c = b.search("&i=");
        var d = b.search("&c=");
        if (c >= 0 && d >= 0) {
            var f = solink + b.substring(c + 3, d);
            document.location = f
        }
    } catch (e) { }
}
