﻿var imgID = -1;
var imgID = StartRotate;
var myImage = new Image();
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var fullVersion = '' + parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion, 10);
var nameOffset, verOffset, ix;

if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
    browserName = "IE";
    fullVersion = nAgt.substring(verOffset + 5);
}
else if ((verOffset = nAgt.indexOf("Opera")) != -1) {
    browserName = "Opera";
    fullVersion = nAgt.substring(verOffset + 6);
}
else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
    browserName = "Chrome";
    fullVersion = nAgt.substring(verOffset + 7);
}
else if ((verOffset = nAgt.indexOf("Safari")) != -1) {
    browserName = "Safari";
    fullVersion = nAgt.substring(verOffset + 7);
}
else if ((verOffset = nAgt.indexOf("Firefox")) != -1) {
    browserName = "Firefox";
    fullVersion = nAgt.substring(verOffset + 8);
}
else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
    browserName = nAgt.substring(nameOffset, verOffset);
    fullVersion = nAgt.substring(verOffset + 1);
    if (browserName.toLowerCase() == browserName.toUpperCase()) {
        browserName = navigator.appName;
    }
}
if ((ix = fullVersion.indexOf(";")) != -1) fullVersion = fullVersion.substring(0, ix);
if ((ix = fullVersion.indexOf(" ")) != -1) fullVersion = fullVersion.substring(0, ix);

majorVersion = parseInt('' + fullVersion, 10);
if (isNaN(majorVersion)) {
    fullVersion = '' + parseFloat(navigator.appVersion);
    majorVersion = parseInt(navigator.appVersion, 10);
}

window.onresize = resizeWin;

var ieMarginTop = 0;

if (browserName == 'IE' && (majorVersion == '7' || majorVersion == '6')) {
    ieMarginTop = 50;
}

if (browserName == 'IE' && (majorVersion == '7' || majorVersion == '6')) {
    document.getElementById('divLogo').style.top = (parseInt(document.getElementById('divMain').offsetTop) + 50) + "px";
    document.getElementById('divMenu').style.top = (parseInt(document.getElementById('divMain').offsetTop) + 73) + "px";
}
else {
    document.getElementById('divLogo').style.top = (parseInt(document.getElementById('divMain').offsetTop) + 0) + "px";
    document.getElementById('divMenu').style.top = (parseInt(document.getElementById('divMain').offsetTop) + 24) + "px";
}

document.getElementById('divLogo').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 10) + 'px';
document.getElementById('divMenu').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 312) + "px";

document.getElementById('divLogo').style.visibility = 'visible';
document.getElementById('divMenu').style.visibility = 'visible';

//alert(document.getElementById('divMenu').style.left + ' ' + document.getElementById('divMenu').style.top);

//function setEmailHover() {
    if (document.getElementById('divEmail')) {
        document.getElementById('divEmail').style.top = (parseInt(document.getElementById('divMain').offsetTop) + ieMarginTop + 269) + "px";
        document.getElementById('divEmail').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 0) + "px";
        document.getElementById('emailHover').style.top = (parseInt(document.getElementById('divMain').offsetTop) + ieMarginTop + 489) + "px";
        document.getElementById('emailHover').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 525) + "px";
        document.getElementById('SRQMap').style.top = (parseInt(document.getElementById('divMain').offsetTop) + ieMarginTop + 460) + "px";
        document.getElementById('SRQMap').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 525) + "px";
        document.getElementById('NAPMap').style.top = (parseInt(document.getElementById('divMain').offsetTop) + ieMarginTop + 477) + "px";
        document.getElementById('NAPMap').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 720) + "px";
    }
//}

//setTimeout("setEmailHover()", 300)

function resizeWin() {
    if (browserName == 'IE' && (majorVersion == '7' || majorVersion == '6')) {
        document.getElementById('divLogo').style.top = (parseInt(document.getElementById('divMain').offsetTop) + 50) + "px";
        document.getElementById('divMenu').style.top = (parseInt(document.getElementById('divMain').offsetTop) + 73) + "px";
    }
    else {
        document.getElementById('divLogo').style.top = (parseInt(document.getElementById('divMain').offsetTop) + 0) + "px";
        document.getElementById('divMenu').style.top = (parseInt(document.getElementById('divMain').offsetTop) + 24) + "px";
    }

    document.getElementById('divLogo').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 10) + 'px';
    document.getElementById('divMenu').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 312) + 'px';

    if (document.getElementById('divEmail')) {
        document.getElementById('divEmail').style.top = (parseInt(document.getElementById('divMain').offsetTop) + ieMarginTop + 269) + "px";
        document.getElementById('divEmail').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 0) + "px";
        document.getElementById('emailHover').style.top = (parseInt(document.getElementById('divMain').offsetTop) + ieMarginTop + 489) + "px";
        document.getElementById('emailHover').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 525) + "px";
        document.getElementById('SRQMap').style.top = (parseInt(document.getElementById('divMain').offsetTop) + ieMarginTop + 460) + "px";
        document.getElementById('SRQMap').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 525) + "px";
        document.getElementById('NAPMap').style.top = (parseInt(document.getElementById('divMain').offsetTop) + ieMarginTop + 477) + "px";
        document.getElementById('NAPMap').style.left = (parseInt(document.getElementById('divMain').offsetLeft) + 720) + "px";
    }
}

function goHome() {
    window.location.href = 'default.aspx';
}

function blendimage(divid, imageid, imagefile, millisec) {
    imgID++;

    if (imgID == Caption.length) { imgID = 0 }

    myImage.src = eval('Img' + imgID).src

    var speed = Math.round(millisec / 100);
    var timer = 0;

    // BEGIN Testimonial Block
    if (myImage.src != document.getElementById('blendImage').src) {
        fade(document.getElementById('paraCaption'), 'color', new Color(255, 255, 255), new Color(0x41, 0x41, 42), 20, 5);
        fade(document.getElementById('paraCaptionby'), 'color', new Color(255, 255, 255), new Color(0x41, 0x41, 42), 20, 5);
        fade(document.getElementById('paraTagline'), 'color', new Color(192, 192, 192), new Color(0x41, 0x41, 42), 20, 5);
//        while (document.getElementById('paraCaption').style.color != '#414142'){
//        
//        }
        setTimeout("chgText(" + imgID + ")", 550);
        setTimeout("fade(document.getElementById('paraCaption'), 'color', new Color(0x41, 0x41, 42), new Color(255, 255, 255), 40, 6)", 500);
        setTimeout("fade(document.getElementById('paraCaptionby'), 'color', new Color(0x41, 0x41, 42), new Color(255, 255, 255), 40, 6)", 500);
        setTimeout("fade(document.getElementById('paraTagline'), 'color', new Color(0x41, 0x41, 42), new Color(192, 192, 192), 40, 6)", 500);
    }
    // END Testimonial Block
    
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById('blendImage').src + ")";

    changeOpac(0, imageid);

    setTimeout("chgIMG()", 100)
    
    timer = 0;
    for (i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'blendImage')", (timer * speed));
        timer++;
    }
}

function chgIMG() {
    document.getElementById('blendImage').src = myImage.src;
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

setInterval("blendimage('blenddiv','blendImage', '', 900)", 10000);

function chgText(index) {
    document.getElementById('paraCaption').innerHTML = Caption[index];
    document.getElementById('paraCaptionby').innerHTML = CaptionBy[index];
    document.getElementById('paraTagline').innerHTML = Tagline[index];
    document.getElementById('paraCaption').style.letterSpacing = LSCaption[index];
    document.getElementById('paraTagline').style.letterSpacing = LSTag[index];
    
}


function Color(r, g, b) {
    this.r = r;
    this.g = g;
    this.b = b;
}
/** otherColor is a Color, degree is number in range [0..1] */
Color.prototype.blend = function blend(otherColor, degree) {
    var invDegree = 1 - degree;
    return new Color(Math.round(otherColor.r * degree + this.r * invDegree),Math.round(otherColor.g * degree + this.g * invDegree),Math.round(otherColor.b * degree + this.b * invDegree));
};
Color.prototype.toString = function toString() {
    return "rgb(" + this.r + "," + this.g + "," + this.b + ")";
};

// then the animator

/**
* elem : element to apply style to
* styleProp: style property to assign color to (e.g. "color"
* or "backgroundColor")
* color1: starting color;
* color2: ending color
* steps : number of intermediate steps
* delay : number of milliseconds between steps (approx.)
* callback: optional function called when fading is complete.
* called with elem, styleProp and color2 as arguments.
*/
function fade(elem, styleProp, color1, color2, steps, delay, callback) {
    var step = 0;
    var id = setInterval(function() {
        step++;
        var newColor = color1.blend(color2, step / steps);
        elem.style[styleProp] = newColor.toString();
        if (step >= steps) {
            clearInterval(id);
            if (callback) {
                callback(elem, styleProp, color2);
            }
        }
    }, delay);
    return id;
}

