
var globalBrowser = false;


if (navigator.appName == "Microsoft Internet Explorer") {
    globalBrowser = true;
}



function toggleMenu(theMenuButton) {
    var theMenuButtonObj = theMenuButton;
    var theMenuButtonTxt;

    if (globalBrowser) {
        theMenuButtonTxt = theMenuButtonObj.childNodes[0];
    } else {
        theMenuButtonTxt = theMenuButtonObj.childNodes[1];
    }

    if (theMenuButtonObj.className.indexOf("Off") != -1) {
        theMenuButtonObj.className = theMenuButtonObj.className.replace("Off", "On");
        //theMenuButtonTxt.style.backgroundImage = theMenuButtonTxt.style.backgroundImage.replace("Off","On");
        theMenuButtonTxt.src = theMenuButtonTxt.src.replace("Off", "On");
    }
    else {
        theMenuButtonObj.className = theMenuButtonObj.className.replace("On", "Off");
        //theMenuButtonTxt.style.backgroundImage = theMenuButtonTxt.style.backgroundImage.replace("On","Off"); 
        theMenuButtonTxt.src = theMenuButtonTxt.src.replace("On", "Off");
    }
}

function goUrl(theUrl) {
    document.location.href = theUrl;
}


function showSubMenu(elementID) {
    objID = document.getElementById(elementID);
    objID.style.display = 'block';
}
function hideSubMenu(elementID) {
    objID = document.getElementById(elementID);
    objID.style.display = 'none';
}


function openPop(popNum) {

    var theImgObj = document.getElementById("theImg" + popNum);
    var thePop = document.getElementById("popDiv" + popNum);
    var thePopHead = document.getElementById("popHead" + popNum);

    thePop.style.display = "inline";
    thePop.style.width = theImgObj.width + 20 + "px";
    thePopHead.style.width = theImgObj.width + 20 + "px";


    var thePopHeight = theImgObj.offsetHeight + 150 + "px";

    thePop.style.top = (((screen.availHeight) / 2) - thePopHeight.substring(0, thePopHeight.lastIndexOf("px")) / 2) + document.documentElement.scrollTop + "px";
    thePop.style.left = ((screen.availWidth) / 2) - ((theImgObj.width + 20) / 2) + "px";

}



function closePop(popNum) {
    var thePop = document.getElementById("popDiv" + popNum);
    thePop.style.display = "none";
}

//----------------------------------modal functions----------------------------------
//-----------------------------------------------------------------------------------
var isIE = document.all ? true : false;



if (typeof ($) != "function") {
    function $() {
        var elements = new Array();
        for (var i = 0; i < arguments.length; i++) {
            var element = arguments[i];
            if (typeof element == 'string')
                element = document.getElementById(element);
            if (arguments.length == 1)
                return element;
            elements.push(element);
        }
        return elements;
    }
}


function xClientHeight() {
    var v = 0, d = document, w = window;
    if (d.compatMode == 'CSS1Compat' && !w.opera && d.documentElement && d.documentElement.clientHeight)
    { v = d.documentElement.clientHeight; }
    else if (d.body && d.body.clientHeight)
    { v = d.body.clientHeight; }
    else if (xDef(w.innerWidth, w.innerHeight, d.width)) {
        v = w.innerHeight;
        if (d.width > w.innerWidth) v -= 16;
    }
    return v;
}

function xClientWidth() {
    var v = 0, d = document, w = window;
    if (d.compatMode == 'CSS1Compat' && !w.opera && d.documentElement && d.documentElement.clientWidth)
    { v = d.documentElement.clientWidth; }
    else if (d.body && d.body.clientWidth)
    { v = d.body.clientWidth; }
    else if (xDef(w.innerWidth, w.innerHeight, d.height)) {
        v = w.innerWidth;
        if (d.height > w.innerHeight) v -= 16;
    }
    return v;
}


function xScrollTop(e, bWin) {
    var offset = 0;
    if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
        var w = window;
        if (bWin && e) w = e;
        if (w.document.documentElement && w.document.documentElement.scrollTop) offset = w.document.documentElement.scrollTop;
        else if (w.document.body && xDef(w.document.body.scrollTop)) offset = w.document.body.scrollTop;
    }
    else {
        e = xGetElementById(e);
        if (e && xNum(e.scrollTop)) offset = e.scrollTop;
    }
    return offset;
}

function xDef() {
    for (var i = 0; i < arguments.length; ++i) { if (typeof (arguments[i]) == 'undefined') return false; }
    return true;
}

//returns an array of elements that match full or partial (indexOf) classname
function ElementsByClass(rootElement, ElementClass, ElementType, partialMatch) {
    ElementType = ElementType ? ElementType : '*';
    var elementsArray = new Array();
    var theElements = rootElement.getElementsByTagName(ElementType);

    for (var x = 0; x < theElements.length; x++) {
        if (partialMatch) {
            if (theElements[x].className.indexOf(ElementClass) > -1) {
                elementsArray[elementsArray.length] = theElements[x];
            }
        } else {
            if (theElements[x].className == ElementClass) {
                elementsArray[elementsArray.length] = theElements[x];
            }
        }
    }

    return elementsArray;
}

function hideSelectBox() {
    //hide selects to fix annoying select bug in ie
    var allSelects = document.getElementsByTagName("select");
    for (var x = 0; x < allSelects.length; x++) {
        //if not in a modal box
        if (allSelects[x].className.indexOf('modal') == -1) {
            allSelects[x].style.visibility = "hidden";
        }
    }
}

function showSelectBox() {
    //hide selects to fix annoying select bug in ie
    var allSelects = document.getElementsByTagName("select");
    for (var x = 0; x < allSelects.length; x++) {
        allSelects[x].style.visibility = "visible";
    }
}

function showModalBox(modalboxID) {
    var modalBackdrop = $('modalBackdrop');
    var modalBox = $(modalboxID);
    currentOpenModal = modalboxID;
    if (isIE) {
        hideSelectBox();
    }

    //set width and height parameters on the object, so we could use them later while
    // the objet is in display 'none'
    if (!modalBox.boxWidth && !modalBox.boxHeight) {
        modalBox.boxWidth = modalBox.offsetWidth;
        modalBox.boxHeight = modalBox.offsetHeight;

    }
    //alert(xDocSize().h)	
    modalBox.style.display = "none";
    modalBox.style.left = Math.round((xClientWidth() / 2 - modalBox.boxWidth / 2)) + "px";
    modalBox.style.top = Math.round((xClientHeight() / 6) - modalBox.boxHeight / 10 + xScrollTop(document.body)) + "px";

    new Effect.Appear('modalBackdrop', { duration: 0.2, from: 0.0, to: 0.3, queue: 'end' });
    new Effect.Appear(modalboxID, { duration: 0.2, from: 0.0, to: 1.0, queue: 'end' });
}

function hideModalBox(modalboxID, funcAfterFinish) {
    var modalBox = $(modalboxID);

    new Effect.Fade(modalboxID, { duration: 0.2, from: 1.0, to: 0.0, queue: 'end' });
    new Effect.Fade('modalBackdrop', { duration: 0.2, from: 0.3, to: 0.0, queue: 'end', afterFinish: function() { modalBox.style.left = "-2000px"; currentOpenModal = false; showSelectBox(); if (funcAfterFinish) funcAfterFinish() } });
}

function getNext(productIndex) {
    var array_length = globalProductArray.length;
    if (productIndex == array_length - 1) {
        product_current = 0;
    }
    else {
        product_current++;
    }
    setIneerHTML(product_current, globalProductArray);
}

function getPrev(productIndex) {
    var array_length = globalProductArray.length;
    if (productIndex == 0) {
        product_current = array_length - 1;
    }
    else {
        product_current--;
    }
    setIneerHTML(product_current, globalProductArray);
}

function changeProductCurrent(productIndex, productArray) {
    globalProductArray = productArray;
    setIneerHTML(productIndex, globalProductArray);

    showModalBox('popDiv1')
}
function setIneerHTML(productIndex, globalProductArray) {
    var rootElement = document.getElementById('popDiv1');
    var imageObj = ElementsByClass(rootElement, 'popScreen')[0];
    var titleObj = ElementsByClass(rootElement, 'textBox_title')[0];
    var textObj = ElementsByClass(rootElement, 'textBox_TXT')[0];
    imageObj.src = globalProductArray[productIndex].popScreen;
    titleObj.innerHTML = globalProductArray[productIndex].textBox_title;
    textObj.innerHTML = globalProductArray[productIndex].textBox_TXT;
}

// these functions prevent mouseovers from bubbling up into
function containsDOM(container, containee) {
    var isParent = false;
    do {
        if ((isParent = container == containee))
            break;
        containee = containee.parentNode;
    }
    while (containee != null);
    return isParent;
}

function checkMouseEnter(element, evt) {
    if (element.contains && evt.fromElement) {
        return !element.contains(evt.fromElement);
    }
    else if (evt.relatedTarget) {
        return !containsDOM(element, evt.relatedTarget);
    }
}

function checkMouseLeave(element, evt) {
    if (element.contains && evt.toElement) {
        return !element.contains(evt.toElement);
    }
    else if (evt.relatedTarget) {
        return !containsDOM(element, evt.relatedTarget);
    }
}