//Code Developed By Don Jereczek
//HP Hood IT Services
//Last Modified 09/11/2009

//PreLoad Navigation Images
function simplePreload() {
    var args = simplePreload.arguments;
    document.imageArray = new Array(args.length);
    for (var i = 0; i < args.length; i++) {
        document.imageArray[i] = new Image;
        document.imageArray[i].src = args[i];
    }
}

//Searchbox Automation
function clearSearch(obj) {
    if (obj.value == 'SEARCH') { obj.value = ''; }
}

function resetSearch(obj) {
    if (obj.value == '') { obj.value = 'SEARCH'; }
}

//Swap side navigation images
function swapSideImage(imageID, state) {
    var obj = document.getElementById(imageID);
    var objsrc = obj.src;

    if (state == 'On') {
        objsrc = objsrc.replace('_Off', '_On');
    } else {
        objsrc = objsrc.replace('_On', '_Off');
    }

    obj.src = objsrc;
}

//Swap brand images and descriptions
function swapBrand(imageID, state, desc) {
    var obj = document.getElementById(imageID);
    var objsrc = obj.src;

    if (state == 'On') {
        objsrc = objsrc.replace('_Off', '_On');
        document.getElementById(desc).style.display = 'inline';
    } else {
        objsrc = objsrc.replace('_On', '_Off');
        document.getElementById(desc).style.display = 'none';
    }

    obj.src = objsrc;
}

//Preload for auto navigation images
function navPreload(element) {
    var getMenu = document.getElementById(element);
    var getImages = getMenu.getElementsByTagName("img");
    document.imageArray = new Array(getImages.length);  
    for (var i = 0; i < getImages.length; i++) {
        var objsrc = getImages[i].src;
        objsrc = objsrc.replace('_Off', '_On');
        document.imageArray[i] = new Image;
        document.imageArray[i].src = objsrc;
    }
}

//Format date for Press Release
function pressDate(date) {
    var m_names = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");
    document.write(m_names[parseInt(date.substr(5, 2), 10) - 1] + " " + date.substr(8, 2)
+ ", " + date.substr(0, 4));
}

//Generic Popup Window
function popupWin(url, width, height) {
    newwindow = window.open(url, 'name', 'height=' + height + ',width=' + width + ', scrollbars=yes');
    if (window.focus) { newwindow.focus() }
    return false;
}

//Searchbox Automation
function clearSearch(obj) {
    if (obj.value == 'SEARCH SITE') { obj.value = ''; }
}

function resetSearch(obj) {
    if (obj.value == '') { obj.value = 'SEARCH SITE'; }
}

// Query String +
function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}
// Query String -

// Print Recipe +
function printRecipe(qid) {
    var url = "";
    if (qid != null) {
        url = "/recipes/recipeprint.aspx?id=" + qid;
    } else {
        url = "/recipes/recipeprint.aspx?id=" + querySt('id');
    }
    popupWin(url, '565', '600');
}
// Print Recipe -

// Recipe Mail +
function recipeMail(qid) {
    var url = "";
    if (qid != null) {
        url = "/recipes/recipemail.aspx?id=" + qid;
    } else {
        url = "/recipes/recipemail.aspx?id=" + querySt('id');
    }
    window.location = url;
}
// Recipe Mail -

// Bookmark/Favorites +
function bookmark(){
	var url= window.location.href;
	var title= window.document.title;
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		window.external.AddFavorite(url,title);
	} else if (navigator.appName == "Netscape") {
		window.sidebar.addPanel(title,url,"");
	} else {
		alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
	}
}
// Bookmark/Favorites -

// JQuery +
$(function() {
	
	// Set classes on the Home Features.
	$(".featuresArea .features_frame div:first-child").addClass("feature_item01");
	$(".featuresArea .features_frame div:eq(1)").addClass("feature_item02");
	$(".featuresArea .features_frame div:eq(2)").addClass("feature_item03");
	
	// Remove the pipe image from the last subnav <li>
	$("div.subnav ul li:last-child").addClass("last");
	
	// Add class names to the Top Nav tabs in order to apply specific widths.
	$(".BC_menu .ekmenu_menu_level_0:first-child").addClass("tab_01")
	$(".BC_menu * .ekmenu_menu_level_0:eq(1)").addClass("tab_02");
	$(".BC_menu * .ekmenu_menu_level_0:eq(2)").addClass("tab_03");
	$(".BC_menu * .ekmenu_menu_level_0:eq(3)").addClass("tab_04");
	$(".BC_menu * .ekmenu_menu_level_0:eq(4)").addClass("tab_05");
	
	// Add classes to the colbox frame columns for CSS traction
	$("div.colBox_frame div.colBox_col:nth-child(1)").addClass("colBox_01");
	$("div.colBox_frame div.colBox_col:nth-child(2)").addClass("colBox_02");
	$("div.colBox_frame div.colBox_col:nth-child(3)").addClass("colBox_03");
	$("div.colBox_frame div.colBox_col:nth-child(4)").addClass("colBox_04");
	$("div.colBox_frame div.colBox_col:nth-child(5)").addClass("colBox_05");
	$("div.colBox_frame div.colBox_col:last-child").addClass("colBox_last");
	
	// Add a class to remove padding from the parent of an element with the class "unpadbox"
	$(".unpadbox").parent("div").addClass("un_pad");
	
	$("table.simpleform tr td:last-child").addClass("right");
	
	//var recipeTeaserHeight = $("div.recipe_teaser").height();
	//recipeTeaserHeight = recipeTeaserHeight + "px";
	//$("div.recipe_teaser_frame").height(recipeTeaserHeight);
	
});
// JQuery -

