if (typeof Browser == 'undefined') {
    var Browser = {
        a : navigator.userAgent.toLowerCase(),
        b : parseInt(navigator.appVersion)
    }
    Browser = {
        ie : /*@cc_on true || @*/ false,
        ie6 : Browser.a.indexOf('msie 6') != -1,
        ie7 : Browser.a.indexOf('msie 7') != -1,
        ie8 : Browser.a.indexOf('msie 8') != -1,
        moz : ((Browser.a.indexOf('mozilla') != -1) && (Browser.a.indexOf('spoofer') == -1) && (Browser.a.indexOf('compatible') == -1)
        && (Browser.a.indexOf('opera') == -1) && (Browser.a.indexOf('webtv') == -1) && (Browser.a.indexOf('hotjava') == -1)),
        opera : !!window.opera,
        opera7 : ((Browser.a.indexOf('opera 7') != -1) || (Browser.a.indexOf('opera/7') != -1)
        || (Browser.a.indexOf('opera 8') != -1) || (Browser.a.indexOf('opera/8') != -1)
        || (Browser.a.indexOf('opera 9') != -1) || (Browser.a.indexOf('opera/9') != -1)),
        opera56 : (Browser.opera && !Browser.opera7),
        safari : Browser.a.indexOf('safari') != -1,
        safari3 : Browser.a.indexOf('applewebkit/5') != -1,
        win : ((Browser.a.indexOf("win") != -1) || (Browser.a.indexOf("16bit") != -1)),
        mac : Browser.a.indexOf('mac') != -1
    }
}

if (typeof tpl_suppress_veffects == 'undefined') {
    var tpl_suppress_veffects = 0;
}

function SlideShow() {
    this.Speed = 3000;
    this.Pics = new Array();
    this.Links = new Array();
    this.Preloaded = new Array();
    this.PreloadPos = 0;
    this.Pos = this.PreloadPos;
    this.Stopped = 0;
    this.Resizer = 0;
    this.Width = screen.width;
    this.Height = screen.height;
    this.Pad = 60;
    this.Filter = "";
    this.FilterDisabled = 0;
    this.Object = "SlideShow";
    this.ObjectID;
    this.Timer;

    this.timer_run = function(time_ms){
        var _self = this;
        if (this.Timer) {
            clearTimeout(this.Timer);
        }
        return setTimeout(function(){ _self.run(0); }, (time_ms ? time_ms : 100));
    }

    this.preload = function(index) {
        if (typeof index == 'undefined') {
            var index = this.Pos;
        }
        if (this.Pics[index] != ''){
            window.status = 'Loading: ' + this.Pics[index];
            this.Preloaded[index] = new Image();
            this.Preloaded[index].src = this.Pics[index];
            this.Pics[index] = '';
            window.status='';
        }
    }

    this.run = function(first_run){
        if (this.Pics.length <= 1) {
            return;
        }
        if (this.Speed < 20) {
            this.Speed = this.Speed * 1000;
        }
        if (this.Stopped || first_run) {
            if (first_run) {
                this.PreloadPos = this.PreloadPos + 1;
                this.preload(this.PreloadPos);
            }
            this.Timer = this.timer_run(this.Speed);
            return;
        }
        if (!this.Preloaded[this.PreloadPos].complete) {
            this.Timer = this.timer_run(this.Speed / 2);
            return;
        }

        if (typeof this.Object == 'string') {
            this.ObjectID = document.getElementById(this.Object);
            if (!this.ObjectID) {
                this.ObjectID = document.getElementsByName(this.Object)[0];
            }
        } else {
            this.ObjectID = this.Object;
        }
        if (!this.ObjectID) return;

        if (Browser.ie && !tpl_suppress_veffects && !this.FilterDisabled){
            var my_filter = "";
            if (!this.Filter) {
                var rval = Math.floor(Math.random()*5);
                switch (rval) {
                    case 1:
                        my_filter = "progid:DXImageTransform.Microsoft.Pixelate()";
                        break;
                    case 2:
                        my_filter = "blendTrans(duration=0.6)";
                        break;
                    case 3:
                        my_filter = "progid:DXImageTransform.Microsoft.gradientWipe(duration=0.6)";
                        break;
                    case 4:
                        my_filter = "progid:DXImageTransform.Microsoft.gradientWipe(duration=0.6)";
                        break;
                    default:
                        my_filter = "revealTrans(duration=0.6, transition=12)";
                        break;
                }
            } else {
                my_filter = this.Filter;
            }
            this.ObjectID.style.filter = my_filter;
            this.ObjectID.filters[0].Apply()
        }

        if (this.Resizer) {
            var cur_w = this.Preloaded[this.PreloadPos].width;
            var cur_h = this.Preloaded[this.PreloadPos].height;

            var my_tmp = cur_w;
            cur_w = this.Width - this.Pad;
            cur_h = cur_h / (my_tmp / (this.Width - this.Pad));

            if (cur_w > this.Width - this.Pad) {
                my_tmp = cur_w;
                cur_w = this.Width - this.Pad;
                cur_h = cur_h / (my_tmp / (this.Width - this.Pad));
            }
            if (cur_h > this.Height - this.Pad * 1.6) {
                my_tmp = cur_h;
                cur_h = this.Height - this.Pad * 1.6;
                cur_w = cur_w / (my_tmp / (this.Height - this.Pad * 1.6));
            }
            this.ObjectID.width = cur_w;
            this.ObjectID.height = cur_h;
        } else {
            this.ObjectID.width = this.Preloaded[this.PreloadPos].width;
            this.ObjectID.height = this.Preloaded[this.PreloadPos].height;
        }

        this.ObjectID.src = this.Preloaded[this.PreloadPos].src;
        if (Browser.ie && !tpl_suppress_veffects && !this.FilterDisabled) {
            this.ObjectID.filters[0].Play()
        }

        this.Pos = this.PreloadPos;

        this.PreloadPos = this.PreloadPos + 1;
        if (this.PreloadPos > (this.Pics.length-1)) {
            this.PreloadPos=0;
        }
        this.preload(this.PreloadPos);
        this.Timer = this.timer_run(this.Speed);
    }

    this.end = function(){
        self.close();
    }

    this.open = function() {
        location.href = this.Links[this.Pos];
    }

    this.toggle = function() {
        this.Stopped = !this.Stopped;
    }

    this.stop = function() {
        this.Stopped=1;
    }

    this.start = function() {
        this.Stopped=0;
    }
}
