﻿var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open() {
    jsddm_canceltimer();
    jsddm_close();
    ddmenuitem = $(this).find("div").css("visibility", "visible");
    ddmenuitem.css("left", parseInt(($(this).width() - ddmenuitem.width()) / 2) + "px");
}

function jsddm_close() {
    if (ddmenuitem) ddmenuitem.css("visibility", "hidden");
}

function jsddm_timer() {
    closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

$(document).ready(function() {
    $("#top_nav > li").bind("mouseover", jsddm_open)
    $("#top_nav > li").bind("mouseout", jsddm_timer)
});



document.onclick = jsddm_close;

//var bread = document.getElementById("breadcrumb_links");
//var h = document.getElementById("h1head");
//if (bread) {
//    bread.style.marginLeft = '16px'; //default margin
//}
//if (h) {
//    if (h.parentNode) {
//        h = h.parentNode;
//        for (var x = 0; x < h.attributes.length; x++) {
//            // window.alert(h.attributes[x].nodeName.toLowerCase() + '=' + h.attributes[x].nodeValue);
//            if (h.attributes[x].nodeName.toLowerCase() == 'class') {
//                if (h.attributes[x].nodeValue == "active" || h.attributes[x].nodeValue == "prod_info") {
//                    //heading should be to the right for product page
//                    bread.style.marginLeft = '349px';
//                }
//                if (h.attributes[x].nodeValue == "bodycopyleft") {

//                    bread.style.marginLeft = '329px';
//                }
//                if (h.attributes[x].nodeValue == "right_column") {
//                    bread.style.marginLeft = '324px';
//                }
//                if (h.attributes[x].nodeValue == "left_narrow") {
//                    bread.style.marginLeft = '44px';
//                }
//                if (h.attributes[x].nodeValue == "left_wide") {
//                    bread.style.marginLeft = '154px';
//                }
//                if (h.attributes[x].nodeValue == "whatsnew") {
//                    bread.style.marginLeft = '352px';
//                }
//                if (h.attributes[x].nodeValue == "intro") {
//                // holiday promo page
//                    bread.style.marginLeft = '177px';
//                }

//            }
//            if (h.attributes[x].nodeName.toLowerCase() == 'id' && h.attributes[x].nodeValue == 'td_h1head') {
//                //for H1's inside tables in Perfect Cup section 
//                bread.style.marginLeft = '294px';
//            }
//            if (h.attributes[x].nodeName.toLowerCase() == 'id' && h.attributes[x].nodeValue == 'about_us') {
//                //for H1's inside tables in Perfect Cup section 
//                bread.style.marginLeft = '342px';
//            }
//            if (h.attributes[x].nodeName.toLowerCase() == 'id' && h.attributes[x].nodeValue == 'td_enjoy') {
//                //for H1's inside tables in Enjoying Coffee section
//                bread.style.marginLeft = '302px';
//            }
//            if (h.attributes[x].nodeName.toLowerCase() == 'id' &&  h.attributes[x].nodeValue == "holiday_header") {
//                //for H1's inside tables in Enjoying Coffee section
//                bread.style.marginLeft = '154px';
//            }
//        }
//    }
//}

function limitText(limitField, limitCountDisplay, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        var spnDisplay = document.getElementById(limitCountDisplay);
        var remain = limitNum - limitField.value.length;
        if (remain == 1) {
            spnDisplay.innerHTML = "[" + remain + "] character remaining";
        } else {
            spnDisplay.innerHTML = "[" + remain + "] characters remaining";
        }
    }
}

function limitWords(obj, limitCountDisplay, limitNum) {
    var len = obj.value.split(/[\s]+/);

    if (len.length > limitNum) {
        var limitArray = obj.value.split(/[\s]+/, limitNum);
        obj.value = limitArray.join(" ");
    } else {

        if (len.length == 1) {
            wordOrWords = " word";
        }
        else {
            wordOrWords = " words";
        }

        var spnDisplay = document.getElementById(limitCountDisplay);
        spnDisplay.innerHTML = "[" + (limitNum - len.length) + "]" + wordOrWords + " remaining";
        
    }
}

//    var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
//    var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
//    var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
//    var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
//    var splitString = cleanedStr.split(" ");
//    var word_count = splitString.length - 1;


function OpenOffSite(a) {
    window.open(a.href, "OffSite", "directories=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes").focus();
    return false;
}