﻿// JavaScript Document
// DHTML Menu
var openmenus = new Array();
var pressed = new Array();
var timer;
var okDOM = (document.getElementById);

// Creates timer that will close DHTML Menu
function setTimer() {
    timer = setTimeout('closeAll(1)', 1750);
}

// Get object info in order to set the style for displaying or hiding the submenu
function getObj(name) {
    if (document.getElementById) { return document.getElementById(name).style; }
}

// Close all dhtml menus that are open
function closeAll(lvl) {
    for (i = openmenus.length - 1; i >= lvl; i--) {
        if (openmenus[i]) {
            var x = getObj(openmenus[i]);
            x.visibility = 'hidden';
        }
        openmenus[i] = null;
        
        // If not the current page, remove the hover class so that the button does not appear to be in the over state
        if (pressed[i]) {
            if (pressed[i].className != 'current') {
                pressed[i].className = '';
            }
            pressed[i] = null;
        }
    }
}
function display(name, lvl, obj) {
    if (!okDOM) return;
    clearTimeout(timer);
    if (openmenus[lvl] && openmenus[lvl] == name) return;
    if (openmenus[lvl]) closeAll(lvl);
    if (name) {
        var x = getObj(name);
        x.visibility = 'visible';
        
        // If there is no name, there is no dhtml menu, so no don't see the class as the css will handle this...Also, we don't want to change the class
        if (obj.className != 'current') {
            obj.className = 'hover';
        }
    }
    openmenus[lvl] = name;
    pressed[lvl] = obj;

}

// Open a new Window
function nw(url) {
    var wname = '_blank';
    open(url, wname);
}

// Show/Hide Elements
function showHide(lnk,div) 
{
    if (document.getElementById(div).style.display == "block")
    {
        document.getElementById(div).style.display = "none";
        lnk.className= "showHideExpand";
    }
    else
    {
        document.getElementById(div).style.display = "block";
        lnk.className = "showHideCollapse";
    }
}

// General Mailto Link Builder
function email(user, domain) {
    document.write('<a href="mailto:' + user + '@' + domain + '">' + user + '@' + domain + '</a>');
}
// Mailto Link builder with Subject
function emailSubject(user, domain, subject) {
    document.write('<a href="mailto:' + user + '@' + domain + '?subject=' + subject + '">' + user + '@' + domain + '</a>');
}


// Onload script for Home Page
if (document.title.match(/National Title Insurance and Settlement Solutions/)) {
    window.onload = playShow;

    /* Number of slide show frames */
    var frameCount = 3;
}

// Homepage slide show
// Variables for slideshow
var currentFrame = 0;
var nextFrame = 0;
var elementPrefix = 'ism';
var frameDelay = 6000; // 1000 = 1 second
var playSet = 0;
var func = 'nextSlide()';
var pauseSet = 0;

function swapSlides() {
    // Display next slide
    document.getElementById(elementPrefix + nextFrame).setAttribute("class", "ismshow"); // Works for all standard browsers
    document.getElementById(elementPrefix + nextFrame).setAttribute("className", "ismshow"); // IE workaround

    // Hide previous slide
    document.getElementById(elementPrefix + currentFrame).setAttribute("class", "ismhide"); // Works for all standard browsers
    document.getElementById(elementPrefix + currentFrame).setAttribute("className", "ismhide"); // IE workaround

    // If playing, reset timer and run play function
    if (playset == 1) {
        clearTimeout(playID);
        playShow();
    }
}

function previousSlide() {
    // Set func variable to function in process
    func = 'previousSlide()';

    // If Pause button has been set to true, then don't automatically run slide show	
    if (pauseSet == 1) {
        playset = 0;
    }

    if (nextFrame == 0) {
        currentFrame = 0;
        nextFrame = frameCount - 1;
        swapSlides();
    } else {
        currentFrame = nextFrame;
        nextFrame = nextFrame - 1;
        swapSlides();
    }
}

function nextSlide() {
    // Set func variable to function in process
    func = 'nextSlide()';

    // If Pause button has been set to true, then don't automatically run slide show
    if (pauseSet == 1) {
        playset = 0;
    }

    if (nextFrame == (frameCount - 1)) {
        currentFrame = nextFrame;
        nextFrame = 0;
        swapSlides();
    } else {
        currentFrame = nextFrame;
        nextFrame = nextFrame + 1;
        swapSlides();
    }
}

function playShow() {
    playset = 1;
    playID = setTimeout(func, frameDelay);
}