/* CLIENT SNIFF **********************************************************************************/

    var agt=navigator.userAgent.toLowerCase();
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);


/* MAIN SCRIPT ***********************************************************************************/


    // Slideshow by Gallery 1.4.1 (http://gallery.sourceforge.net)
    // Modified by mr (mr@bbp.biz) / February 2004


    //Globale Vars

    // IE Überlendungseffekte aktivieren
    var browserTransitions = (is_ie5_5up);


    //Überlendungen
    var transitions = new Array;
    transitions[0] = "progid:DXImageTransform.Microsoft.Fade(duration=1)";
    transitions[1] = "progid:DXImageTransform.Microsoft.Blinds(Duration=1,bands=20)";
    transitions[2] = "progid:DXImageTransform.Microsoft.Checkerboard(Duration=1,squaresX=20,squaresY=20)";
    transitions[3] = "progid:DXImageTransform.Microsoft.Strips(Duration=1,motion=rightdown)";
    transitions[4] = "progid:DXImageTransform.Microsoft.Barn(Duration=1,orientation=vertical)";
    transitions[5] = "progid:DXImageTransform.Microsoft.GradientWipe(duration=1)";
    transitions[6] = "progid:DXImageTransform.Microsoft.Iris(Duration=1,motion=out)";
    transitions[7] = "progid:DXImageTransform.Microsoft.Wheel(Duration=1,spokes=12)";
    transitions[8] = "progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration=1)";
    transitions[9] = "progid:DXImageTransform.Microsoft.RadialWipe(Duration=1,wipeStyle=clock)";
    transitions[10] = "progid:DXImageTransform.Microsoft.RandomBars(Duration=1,orientation=vertical)";
    transitions[11] = "progid:DXImageTransform.Microsoft.Slide(Duration=1,slideStyle=push)";
    transitions[12] = "progid:DXImageTransform.Microsoft.RandomDissolve(Duration=1,orientation=vertical)";
    transitions[13] = "progid:DXImageTransform.Microsoft.Spiral(Duration=1,gridSizeX=40,gridSizeY=40)";
    transitions[14] = "progid:DXImageTransform.Microsoft.Stretch(Duration=1,stretchStyle=push)";
    transitions[15] = "random";
    var transition_count = transitions.length;


    // Zufallszahl zw. min und max
    function rand(min,max){
       return (Math.round(Math.random()*(max-min)))+min;
    }


    // Object Funktionen
    function diashow_play() {
        this.onoff = 1;
        this.photo_count = this.pics.length - 1;
        this.go_to_next_photo();
    }

    function diashow_stop() {
        this.onoff = 0;
    }


    function diashow_preload_complete() {
    }

    function diashow_reset_timer() {
        clearTimeout(this.timer);
        if (this.onoff) {
            if(this.randomhold){
                this.timeout_value = (rand((this.hold-3 < 0 ? 1 : this.hold), this.hold+3) * 1000);
            }else{
                this.timeout_value = this.hold * 1000;
            }
            this.timer = setTimeout(this.cname+'.go_to_next_photo()', this.timeout_value);
        }
    }

    function diashow_wait_for_current_photo() {

        if (!this.show_current_photo()) {
            clearTimeout(this.timer);
            this.timer = setTimeout(this.cname+'.wait_for_current_photo()', 500);
            return 0;
        } else {
            this.preload_next_photo();
            this.reset_timer();
        }
    }

    function diashow_go_to_next_photo() {
        this.current_location = this.next_location;

        if (!this.show_current_photo()) {
            this.wait_for_current_photo();
            return 0;
        }

        this.preload_next_photo();
        this.reset_timer();
    }

    function diashow_preload_next_photo() {

        this.next_location = (parseInt(this.current_location) + parseInt(this.direction));
        if (this.next_location > this.photo_count) {
            this.next_location = 1;
            if (!this.loop) {
                this.stop();
            }
        }
        if (this.next_location == 0) {
            this.next_location = this.photo_count;
            if (!this.loop) {
                this.stop();
            }
        }

        this.preload_photo(this.next_location);
    }

    function diashow_show_current_photo() {

        if (!this.preload[this.current_location] || !this.preload[this.current_location].complete) {
            this.preload_photo(this.current_location);
            return 0;
        }

        if (browserTransitions){
            var do_transition;
            if (this.transition == (this.transition_count)) {
                do_transition = Math.floor(Math.random() * this.transition_count);
            } else {
                do_transition = this.transition;
            }
            document.images[this.targetimage].style.filter=transitions[do_transition];
            document.images[this.targetimage].filters[0].Apply();
        }
        document.images[this.targetimage].src = this.preload[this.current_location].src;

        if (browserTransitions) {
            document.images[this.targetimage].filters[0].Play();
        }

        return 1;
    }

    function diashow_preload_photo(index) {

        if (this.pics_loaded < this.photo_count) {

        if (!this.preload[index]) {
            this.preload[index] = new Image;
            this.preload[index].onLoad = this.preload_complete();
            this.preload[index].src = this.pics[index];
            this.pics_loaded++;
        }
        }
    }



    // DiaShow Class
    function diashow (){

        //Interne Vars

        //Überblendung (0-14, 15 = Zufall)
        this.transition = 0;

        //Wiederholen (1/0)
        this.loop = 1;

        //Zeit zwischen den Bildern
        this.hold = 5;

        //Zufallszeit zw. dem Bilderwechsel (1/0)
        this.randomhold = 0;

        //Ziel Bild das ausgetauscht wird
        this.targetimage = 'diaimg';

        //Name des Objektes
        this.cname = 'ds';

        //Interne Vars
        this.pics = new Array;
        this.preload = new Array;
        this.current_location = 1;
        this.next_location = 1;
        this.timer;
        this.timeout_value;
        this.direction = 1;
        this.pics_loaded = 0;
        this.photo_count = 0;


        //Mappings
        this.play = diashow_play;
        this.stop = diashow_stop;
        this.go_to_next_photo = diashow_go_to_next_photo;
        this.show_current_photo = diashow_show_current_photo;
        this.wait_for_current_photo = diashow_wait_for_current_photo;
        this.preload_next_photo = diashow_preload_next_photo;
        this.preload_photo = diashow_preload_photo;
        this.reset_timer = diashow_reset_timer;
        this.preload_complete = diashow_preload_complete;
    }







