﻿function Slideshow(schemalocation, showdivid, runUponLoad) {
    this.Pic = [];
    this.speed = 10000;
    this.p = 0;
    this.j = 0;
    this.divid = showdivid;
    this.schemalocation = schemalocation;
    this.play = true;
    this.runUponLoad = runUponLoad;
}

Slideshow.prototype.runSlideShow = function() {
$('#' + this.divid).fadeIn(2000);
    var self = this;
    if (this.play) {    
        $('#' + this.divid).css('background-image', 'url(' + this.Pic[this.j] + ')');
        this.j = this.j + 1
        if (this.j > (this.p - 1)) this.j = 0;
        $('#' + this.divid).fadeOut(6000);
        var t = setTimeout(function() { self.runSlideShow(); }, this.speed);
    }
}

Slideshow.prototype.stopSlideShow = function() {
    this.play = false;
}

Slideshow.prototype.getslides = function() {
    var self = this;
    $.get(this.schemalocation, function(d) {
        $(d).find('Slide > source').each(function() {
            var source = $(this).text();
            self.Pic.push(source);
        });
        self.p = self.Pic.length;
        //alert(this.ru);
        if (self.runUponLoad === true) {
            self.runSlideShow();
        }
    });
}

