/*--------------------------------------------------------------
Breadcrumb stuff
Customize the breadcrumb separator if necessary...and the
hyperlink class for the breadcrumbs below...
Add a new entry for each folder name so that you can
translate the nice text description and the URL...
--------------------------------------------------------------*/
var strSeparator = '&nbsp;&gt;&gt;&nbsp;';
var strHyperlinkClass = 'breadcrumb';


var arrPathSegments = document.location.pathname.split('/');
var arrPathSegmentsProcessed = new Array();
for (var i = 0; i < arrPathSegments.length; i++) {
	if (arrPathSegments[i] != '' && arrPathSegments[i].indexOf('.') == -1) {
		arrPathSegmentsProcessed.push(arrPathSegments[i]);
	}
}

function _MW_objBreadcrumb(strDescription, strURL) {
	this.description = strDescription;
	this.url = strURL;
}

// add any new items to this array...like so:
// arrBreadCrumbs['folderName'] = new _MW_objBreadcrumb('Display Text', 'Absolute URL');
var arrBreadcrumbs = new Array();
arrBreadcrumbs['about'] = new _MW_objBreadcrumb('About Us', '/eng/about/');
arrBreadcrumbs['history'] = new _MW_objBreadcrumb('History', '/eng/about/history/');
arrBreadcrumbs['philosophy'] = new _MW_objBreadcrumb('Philosophy', '/eng/about/philosophy/');
arrBreadcrumbs['mission'] = new _MW_objBreadcrumb('Mission', '/eng/about/mission/');
arrBreadcrumbs['products'] = new _MW_objBreadcrumb('Products', '/eng/products/');
arrBreadcrumbs['wholecell'] = new _MW_objBreadcrumb('Whole Cell / Nutritional Yeast', '/eng/products/wholecell/');
arrBreadcrumbs['extracts'] = new _MW_objBreadcrumb('Extracts', '/eng/products/extracts/');
arrBreadcrumbs['Torula'] = new _MW_objBreadcrumb('Torula', '/eng/products/Torula/');
arrBreadcrumbs['wholelyfe'] = new _MW_objBreadcrumb('Yeast Autolysates', '/eng/products/wholelyfe/');
arrBreadcrumbs['lyfe'] = new _MW_objBreadcrumb('Lyfe Vegetarian Yeast', '/eng/products/lyfe/');
arrBreadcrumbs['recipes'] = new _MW_objBreadcrumb('Recipes', '/eng/recipes/');
arrBreadcrumbs['broker'] = new _MW_objBreadcrumb('Brokers &amp; Distributors', '/eng/broker/');
arrBreadcrumbs['canada'] = new _MW_objBreadcrumb('Canada', '/eng/broker/canada/');
arrBreadcrumbs['mexico'] = new _MW_objBreadcrumb('Mexico', '/eng/broker/mexico/');
arrBreadcrumbs['usa'] = new _MW_objBreadcrumb('United States', '/eng/broker/usa/');
arrBreadcrumbs['europe'] = new _MW_objBreadcrumb('Europe', '/eng/broker/europe/');
arrBreadcrumbs['asia'] = new _MW_objBreadcrumb('Asia', '/eng/broker/asia/');
arrBreadcrumbs['samples'] = new _MW_objBreadcrumb('Request Samples', '/eng/samples/');
arrBreadcrumbs['links'] = new _MW_objBreadcrumb('Links', '/eng/links/');

// build the breadcrumb string
var strBreadcrumbHTML = '&nbsp;'; // until we add one...
strBreadcrumbHTML = '<a href="/eng/" class="' + strHyperlinkClass + '">Home</a>';
if (document.location.pathname.indexOf('/eng/FNI/') != -1) {
	strBreadcrumbHTML += strSeparator + '<a href="/eng/FNI/home.asp" class="' + strHyperlinkClass + '">FNI</a>';
} else {
	strBreadcrumbHTML += strSeparator + '<a href="/eng/home.asp" class="' + strHyperlinkClass + '">Food Ingredients</a>';
}
if (arrPathSegmentsProcessed.length > 0) {
	for (var i = 0; i < arrPathSegmentsProcessed.length; i++) {
		if (arrBreadcrumbs[arrPathSegmentsProcessed[i]]) {
			strBreadcrumbHTML += strSeparator + '<a href="' + arrBreadcrumbs[arrPathSegmentsProcessed[i]].url + '" class="' + strHyperlinkClass + '">' + arrBreadcrumbs[arrPathSegmentsProcessed[i]].description + '</a>';
		}
	}
}

// variable setup - don't customize
var MW_currentImage = null;
var MW_swap = (document.images)?true:false;
var MW_isLoaded = false;

// variables to customize
var MW_strDefaultPath = "/eng/images/navigation/"; // strDefaultPath is the path to the images for rollovers
var MW_arrImages = new Array();

// create an object to hold the image name, its path and filenames
function MW_objRollover(strImageName, strImagePath, strImageFilename1, strImageFilename2) {
	this.imageName = strImageName;
	this.imagePath = (strImagePath)?strImagePath:MW_strDefaultPath;
	this.image1 = new Image();
	this.image1.src = this.imagePath + ((strImageFilename1)?strImageFilename1:this.imageName + '1' + '_' + charLanguage + '.' + ((strFileExtension)?strFileExtension:strDefaultFileExtension));
	this.image2 = new Image();
	this.image2.src = this.imagePath + ((strImageFilename2)?strImageFilename2:this.imageName + '2' + '_' + charLanguage + '.' + ((strFileExtension)?strFileExtension:strDefaultFileExtension))

	// add the event handlers to the anchor
	// try adding to the parentNode
	var loopLimit = 10;
	var loopCounter = 0;
	var nodeImgParent = document.images[strImageName].parentNode;
	if (nodeImgParent) {
		while (nodeImgParent.tagName.toLowerCase() != 'a' && loopLimit < loopCounter) {
			loopCounter++;
			nodeImgParent = nodeImgParent.parentNode;
		}
		if (nodeImgParent.tagName.toLowerCase() == 'a') {
			nodeImgParent.onmouseover = MW_swapImage;
			nodeImgParent.onmouseout = MW_turnOff;
			nodeImgParent.ptrArrImages = this;
		}
	}
}

function MW_swapImage() {
	if (MW_swap && MW_isLoaded) {
		document.images[this.ptrArrImages.imageName].src = this.ptrArrImages.image2.src;
		MW_currentImage = this.ptrArrImages;
		
		// added in to include popup menu of the same name (without the roll_)
		if (this.ptrArrImages.imageName.indexOf('roll_menu_') != -1) {
			//alert(document.images[this.ptrArrImages.imageName].src);
			popup(this.ptrArrImages.imageName.split('roll_')[1], this.ptrArrImages.imageName, -115, 168);
			window.status = this.ptrArrImages.imageName;
		}
	}
}

function MW_turnOff() {
	if (MW_swap && MW_isLoaded && MW_currentImage) {
		document.images[MW_currentImage.imageName].src = MW_currentImage.image1.src;
		MW_currentImage = null;
		
		// added in to include popup menu of the same name (without the roll_)
		if (this.ptrArrImages.imageName.indexOf('roll_menu_') != -1) {
			popdown();
		}
	}
}

var MW_arrTabStrips = null; // declare this to stop errors, may use later if tabs are in use on the site

function MW_initUI() {
	// general variable that states if the page is loaded
	MW_isLoaded = true;

	// setup the image rollovers
	if (MW_swap) {
		// preprocess the site and look for the image that matches the folder name
		var arrPaths = document.location.pathname.split('/');
	
		
		// try preprocessing the page and looking for images named "roll_anything"
		for (var i = 0; i < document.images.length; i++) {
			if (document.images[i].name.indexOf('roll_') != -1) {
				strImagePath = document.images[i].src;
				strImageFilename1 = strImagePath.substring(strImagePath.lastIndexOf('/') + 1, strImagePath.length);
				if (arrPaths.length >= 2 && arrPaths[arrPaths.length - 2] != '' && document.images[i].name.indexOf(arrPaths[arrPaths.length - 2]) != -1) { // check for an image to flip to state 3...
					if (strImageFilename1.indexOf('1') != -1) {
						strImageFilename1 = strImageFilename1.replace(/([^1])1(.*)/, "$13$2");
						document.images[i].src = strImagePath.substring(0, strImagePath.lastIndexOf('/') + 1) + strImageFilename1;
					}
				}
				else {
					// we have an image with this name...create the object accordingly
					strImageFilename2 = strImageFilename1;
					if (strImageFilename2.indexOf('1') != -1) {
						strImageFilename2 = strImageFilename2.replace(/([^1])1(.*)/, "$12$2");
					}
					else {
						strImageFilename2 = strImageFilename2.replace(/([^2])2(.*)/, "$11$2");
					}
		
					strImagePath = strImagePath.substring(0, strImagePath.lastIndexOf('/') + 1);
					MW_arrImages.push(new MW_objRollover(document.images[i].name, strImagePath, strImageFilename1, strImageFilename2));
				}
			}
		}
	}
	
	// look for <tr> with the id = "UI_rollover"
	var arrTableRows = document.getElementsByTagName('tr');
	for (var i = 0; i < arrTableRows.length; i++) {
		if (arrTableRows[i].id == 'UI_rollover') {
			arrTableRows[i].onmouseover = MW_UI_row_onmouseover;
			arrTableRows[i].onmouseout = MW_UI_row_onmouseout;
		}
	}
	// look for <td> with the id = "UI_rollover"
	var arrTableRows = document.getElementsByTagName('td');
	for (var i = 0; i < arrTableRows.length; i++) {
		if (arrTableRows[i].id == 'UI_rollover') {
			arrTableRows[i].onmouseover = MW_UI_row_onmouseover;
			arrTableRows[i].onmouseout = MW_UI_row_onmouseout;
		}
	}
	
	// look for confirm hyperlinks and add the onclick to them
	var arrConfirmVAL = document.getElementsByTagName('a');
	for (var i = 0; i < arrConfirmVAL.length; i++) {
		if (arrConfirmVAL[i].id == 'VAL_confirm') {
			arrConfirmVAL[i].onclick = function () {
				if (this.title) {
					return MW_confirmAction(this.title);
				}
				else {
					return MW_confirmAction(null);
				}
			}
		}
	}
	
	// initialize any tab strips on this page
	if (MW_arrTabStrips) 
		_MW_init_TABS();
}

//------------------------------------------------------------------------------------
// End - Image Rollover Code
//------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------
// Function to confirm action on an item
//------------------------------------------------------------------------------------
function MW_confirmAction(msg) {
	// if no message is passed, use a generic one
	if (!msg) {
		msg = 'Are you sure you want to do this?';
	}
	
	if (confirm(msg)) {
		return true;
	}
	else {
		return false;
	}
}

//------------------------------------------------------------------------------------
// Functions to activate tr on hover
//------------------------------------------------------------------------------------
function MW_UI_row_onmouseover() {
	this.className = 'displayTable2';
}

function MW_UI_row_onmouseout() {
	this.className = 'displayTable1';
}

//------------------------------------------------------------------------------------
// set the onload event handler to setup the UI functions and objects
//------------------------------------------------------------------------------------
window.onload = MW_initUI;