﻿/*
*   ===================  MENU SECTION ===================================
*/
var menuIDs = new Array('dvBlank', 'dvProducts', 'dvSupport', 'dvNews', 'dvContact', 'dvMembers');
var divIDs = new Array('mnuHome', 'mnuProducts', 'mnuSupport', 'mnuNews', 'mnuContact', 'mnuMembers');
var btnIDs = new Array('btnHome', 'btnProducts', 'btnSupport', 'btnNews', 'btnContact', 'btnMembers');

function changeMenu(id, divID, btnID) {
    hideAllIds();
    showDiv(id);
    highlightDiv(divID, btnID);
}

/* Hides all submenus and clears all menu selections */
function hideAllIds() {
    for (var i = 0; i < menuIDs.length; i++) {
        hideDiv(menuIDs[i]);
    }

    for (var i = 0; i < divIDs.length; i++) {
        resetDiv(divIDs[i], btnIDs[i]);
    }
}

/* Hides the specified DIV */
function hideDiv(id) {
    document.getElementById(id).style.display = 'none';
}

/* Displays the specified DIV */
function showDiv(id) {
    document.getElementById(id).style.display = 'block';
}

/* Resets the DIV colouring */
function resetDiv(id, btnID) {
    document.getElementById(id).style.backgroundColor = "White";
    document.getElementById(btnID).style.color = "Black";
}

/* Sets the DIV highlight colouring */
function highlightDiv(id, btnID) {
    document.getElementById(id).style.backgroundColor = "#003D79";
    document.getElementById(btnID).style.color = "#FFFFCC";
}

/*
*   ===================  HOMEPAGE CONTENT ROTATION ===================================
*/

var iIntervalID = 0;
var iCurrentContent = 0 //which one is selected
var contentIDs = new Array('divX800', 'divXS31', 'divXLSeries', 'divEIP4200');
var backgrounds = new Array('/images/redesign/homepage/X800_rev1.jpg', '/images/redesign/homepage/XS31_rev1.jpg', '/images/redesign/homepage/XLSeries_rev1.jpg', '/images/redesign/homepage/EIP4200_rev1.jpg');

function startStopContentRotation() {
    if (iIntervalID != 0) {
        clearInterval(iIntervalID);
        document.getElementById("controls_play").src = "/images/redesign/homepage/controls_play.png";
        iIntervalID = 0;
    } else {
        iIntervalID = setInterval("rotateHomepageContent()", 30000)
        document.getElementById("controls_play").src = "/images/redesign/homepage/timer.gif";
    }
}

function rotateHomepageContent() {
    iCurrentContent = (iCurrentContent < contentIDs.length - 1) ? iCurrentContent + 1 : 0;
    prevcontentindex = (iCurrentContent == 0) ? contentIDs.length - 1 : iCurrentContent - 1;

    document.getElementById(contentIDs[prevcontentindex]).style.display = 'none';
    document.getElementById(contentIDs[iCurrentContent]).style.display = 'block';
    document.getElementById('dvContentFrame').style.background = "url('" + backgrounds[iCurrentContent] + "')";
}


function rotateHomepageContentBack() {
    iCurrentContent = (iCurrentContent == 0) ? contentIDs.length - 1 : iCurrentContent - 1;
    prevcontentindex = (iCurrentContent < contentIDs.length - 1) ? iCurrentContent + 1 : 0;

    document.getElementById(contentIDs[prevcontentindex]).style.display = 'none';
    document.getElementById(contentIDs[iCurrentContent]).style.display = 'block';
    document.getElementById('dvContentFrame').style.background = "url('" + backgrounds[iCurrentContent] + "')";
}


/*
*   ===================  TABS SECTION ===================================
*/
var btnAttached = 'btnAttached';
var divAttached = 'divAttached';
var btnOptional = 'btnOptional';
var divOptional = 'divOptional';

function ShowAttachedLens() {
    hideDiv('dvOptional');
    hideDiv('dvOptionalNote');
    showDiv('dvAttachedNote');
    showDiv('dvAttached');

    document.getElementById(btnAttached).style.background = "url('/images/redesign/tab_attached_selected.png')";
    document.getElementById(btnAttached).style.width = "311px";
    document.getElementById(divAttached).setAttribute("class", "SelectedTab");

    document.getElementById(btnOptional).style.background = "url('/images/redesign/tab_optional_not.png')";
    document.getElementById(btnOptional).style.width = "253px";
    document.getElementById(divOptional).setAttribute("class", "UnselectedTab");

    document.getElementById('PageLeft').style.background = "url('/images/redesign/page_left_red.png')";
    document.getElementById('PageRight').style.background = "url('/images/redesign/page_right_red.png')";
    document.getElementById('PageBottom').style.background = "url('/images/redesign/page_bottom_red.png')";
    document.getElementById('PageTop').style.background = "url('/images/redesign/page_top_red.png')";
}

function ShowOptionalLens() {
    hideDiv('dvAttached');
    hideDiv('dvAttachedNote');
    showDiv('dvOptionalNote');
    showDiv('dvOptional');

    document.getElementById(btnAttached).style.background = "url('/images/redesign/tab_attached_not.png')";
    document.getElementById(btnAttached).style.width = "253px";
    document.getElementById(divAttached).setAttribute("class", "UnselectedTab");

    document.getElementById(btnOptional).style.background = "url('/images/redesign/tab_optional_selected.png')";
    document.getElementById(btnOptional).style.width = "311px";
    document.getElementById(divOptional).setAttribute("class", "SelectedTab");

    document.getElementById('PageLeft').style.background = "url('/images/redesign/page_left_blue.png')";
    document.getElementById('PageRight').style.background = "url('/images/redesign/page_right_blue.png')";
    document.getElementById('PageBottom').style.background = "url('/images/redesign/page_bottom_blue.png')";
    document.getElementById('PageTop').style.background = "url('/images/redesign/page_top_blue.png')";
}


//Specify highlight behavior. "TD" to highlight table cells, "TR" to highlight the entire row:
var highlightbehavior = "TD"
var ns6 = document.getElementById && !document.all
var ie = document.all

var highlightcolor = '#F8F8F8';
var originalcolor = '#FFFFFF';

//try to run it on a timer for a fade effect
var colours = new Array('#FFFFFF', '#FEFEFF', '#FAFCFE', '#F8FAFC', '#F6F8FA', '#F4F6F8');

function changeto(e) {
    source = ie ? event.srcElement : e.target
    if (source.tagName == "TABLE")
        return
    while (source.tagName != highlightbehavior && source.tagName != "HTML")
        source = ns6 ? source.parentNode : source.parentElement
    if (source.style.backgroundColor != highlightcolor && source.className == "ProductBox")
        //myfade(source, originalcolor, highlightcolor, 10, 32)
        source.style.backgroundColor = highlightcolor
}

function contains_ns6(master, slave) { //check if slave is contained by master
    while (slave.parentNode)
        if ((slave = slave.parentNode) == master)
        return true;
    return false;
}

function changeback(e) {
    if (ie && (event.fromElement.contains(event.toElement) || source.contains(event.toElement) || source.className != "ProductBox") || source.tagName == "TABLE")
        return
    else if (ns6 && (contains_ns6(source, e.relatedTarget) || source.className != "ProductBox"))
        return
    if (ie && event.toElement != source || ns6 && e.relatedTarget != source)
        //myfade(source, highlightcolor, originalcolor, 10, 16)
        source.style.backgroundColor = originalcolor
}