﻿var changeDelay = 9000;
var stepTime = 60;
var textColor = "#8C8C8C";
var linkColor = "#1880B7";
var sourceColor = "#8C8C8C";
var locationColor = "#8C8C8C";
var testimonialTimeout = null;
function testimonial(textID, linkID, sourceID, locationID) {
    this.textID = textID;
    this.linkID = linkID;
    this.sourceID = sourceID;
    this.locationID = locationID;
    this.textFader = new fader(this.textID);
    this.linkFader = new fader(this.linkID);
    this.sourceFader = new fader(this.sourceID);
    this.locationFader = new fader(this.locationID);
    startFade();
}

function startFade() {
    testimonialTimeout = setTimeout(function() {
        fadeColor(testimonialPreview.textFader, "#FFFFFF", stepTime);
        fadeColor(testimonialPreview.sourceFader, "#FFFFFF", stepTime);
        fadeColor(testimonialPreview.locationFader, "#FFFFFF", stepTime);
        fadeColor(testimonialPreview.linkFader, "#FFFFFF", stepTime, fillTestimonial);
    }, changeDelay);
}

fillTestimonial = function() {
    clearTimeout(testimonialTimeout);
    $.ajax({
        type: "POST",
        url: "Testimonial.asmx/GetRandomTestimonial",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            var data = msg.d;
            var text = document.getElementById(testimonialPreview.textID);
            var source = document.getElementById(testimonialPreview.sourceID);
            var location = document.getElementById(testimonialPreview.locationID);
            var link = document.getElementById(testimonialPreview.linkID);
            if (text) {
                text.innerHTML = data.PreviewText;
            }
            if (source) {
                source.innerHTML = data.Submitter;
            }
            if (location) {
                location.innerHTML = data.Location;
            }
            if (link) {
                link.href = "testimonial.aspx#testimonial_" + data.ID;
            }
            fadeColor(testimonialPreview.textFader, textColor, stepTime);
            fadeColor(testimonialPreview.sourceFader, sourceColor, stepTime);
            fadeColor(testimonialPreview.locationFader, locationColor, stepTime);
            fadeColor(testimonialPreview.linkFader, linkColor, stepTime, startFade());
        },
        error: function(msg) {
        }
    });
}