﻿
// Common JavaScript functions across entire DomEx application (user and Admin)
var mouseX;
var mouseY;


function addFavorite() {
    if (window.external && document.all) {
        window.external.AddFavorite("http://www.domexhardwoods.com", "Dom-Ex Hardwoods");
    }
    else 
    {
        if (window.sidebar) {
            alert("Firefox users: press CTRL+D to add this site to your Bookmarks.");
        }
    }
}

function hideItemDetails() {
    var divItemDetails = document.getElementById("divItemDetails");
    if (divItemDetails) {
        divItemDetails.style.display = "none";
    }
}

// Image Swapper
function featureDiv(url, title) {
    this.Url = url;
    this.Title = title;
}

// activeDiv gets faded out, backDiv gets faded in and made activeDiv
function swapDiv() {
    nextDivIndex = currentDivIndex + 1;
    if (nextDivIndex == divCount)
        nextDivIndex = 0;

    var fadeOutDiv = document.getElementById('divFeatured' + currentDivIndex);
    var fadeInDiv = document.getElementById('divFeatured' + nextDivIndex);

    // set backDiv, fade it in. Change ZIndex so Tooltip corresponds to correct Div.
    if (fadeOutDiv != null)
        fadeOutDiv.style.zIndex = 99;

    fadeInDiv.style.zIndex = 100;
    fadeInDiv.style.display = "block";

    fade('in', nextDivIndex);
    if (fadeOutDiv != null)
        fade('out', currentDivIndex);

    currentDivIndex = nextDivIndex;
}

function fade(direction, imgIndex) {

    var element = document.getElementById('divFeatured' + imgIndex);

    if (element.CurrentOpacity == null)
        element.CurrentOpacity = 0;

    if (element.CurrentOpacity < 0) {
        element.CurrentOpacity = 0;
        if (direction == 'out')
            element.style.display = 'none';
    }
    if (element.CurrentOpacity > 1) {
        element.CurrentOpacity = 1;
    }

    element.CurrentOpacity = (element.CurrentOpacity + ((direction == 'out') ? -.07 : .07));

    // apply the new opacity value in IE + FireFox
    element.style.opacity = element.CurrentOpacity;
    element.style.filter = 'alpha(opacity = ' + (element.CurrentOpacity * 100) + ')';

    if (element.CurrentOpacity < 0 || element.CurrentOpacity > 1)
        return;

    setTimeout("fade('" + direction + "', " + imgIndex + ")", 35);
}


function captureMouseCoords(e) {
    var posx = 0;
    var posy = 0;

    if (!e) var e = window.event;
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft
            + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop
            + document.documentElement.scrollTop;
    }

    mouseX = posx;
    mouseY = posy;
}