var current_browser = navigator.appName;  // Browser name
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))//test for MSIE x.x;
{ 
	var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
}
 
var imgPath = '/wp-content/themes/motionsoft1/_images/_product-showcase/';
var onFocusImg = imgPath + 'tab_blur.jpg';
var onBlurImg = imgPath + 'tab_blur.jpg';

// Image Format
// Use PNG for non-reflective icons (these are primarly used for non-white backgrounds)
// var imgFormat = 'png';
// Use JPG for reflective icons (used for white backgrounds
var imgFormat = 'jpg';

// Function place features in product showcase
function placeFeatures( productID )
{
	
	var logo = 'theCircuitLogo.png';
	if ( productID == 'fillmygym' )
	{
		logo = 'theFMGLogo.png';
	}
		
	if ( productID == 'the-circuit' || productID == 'fillmygym' )
	{		
		// For FF and Opera & IE 9
		if ( current_browser == 'Netscape' || current_browser == 'Opera' || ( current_browser == 'Microsoft Internet Explorer' && ieversion == '9' ) )
		{
			var product_showcase = document.getElementById('product_showcase');
			circuit_container = product_showcase.childNodes[1].childNodes[2];
			circuit_container.childNodes[1].innerHTML = '<img src="/wp-content/themes/motionsoft1/_images/' + logo + '" />';
			circuit_container.style.display = 'inline';
			circuit_container.style.paddingTop = '10px';
			circuit_container.style.marginLeft = '-20px';
			for ( var otherCnt = 3; otherCnt < circuit_container.childNodes.length; otherCnt+=2 )
			{
				// alert( circuit_container.childNodes[ otherCnt ].nodeName );
				circuit_container.childNodes[ otherCnt ].style.display = 'none';
			}
		}
		// IE 8, Chrome, Safari, and others
		else
		{
			var product_showcase = document.getElementById('product_showcase');
			circuit_container = product_showcase.childNodes[0].childNodes[1];
			circuit_container.childNodes[0].innerHTML = '<img src="/wp-content/themes/motionsoft1/_images/' + logo + '" />';
			circuit_container.style.display = 'inline';
			circuit_container.style.paddingTop = '10px';
			circuit_container.style.marginLeft = '-20px';
			for ( var otherCnt = 1; otherCnt < circuit_container.childNodes.length; otherCnt++ )
			{
				// alert( circuit_container.childNodes[ otherCnt ].nodeName );
				circuit_container.childNodes[ otherCnt ].style.display = 'none';
			}
		}
	}
	else
	{
		// For FF and Opera & IE 9
		if ( current_browser == 'Netscape' || current_browser == 'Opera' || ( current_browser == 'Microsoft Internet Explorer' && ieversion == '9' ) )
		{ 
			// First, do not display any product features
			var products = document.getElementById('product_showcase');
			// If the Circuit has been visited, reset the first set of LI nodes
			circuit_container = products.childNodes[1].childNodes[2];
			//circuit_container.childNodes[1].innerHTML = '<img src="/wp-content/themes/motionsoft1/_images/' + logo + '.png" />';
			//circuit_container.childNodes[1].innerHTML = '<img src="/wp-content/themes/motionsoft1/_images/' + logo + '.jpg" />';
			circuit_container.childNodes[1].innerHTML = '<img src="/wp-content/themes/motionsoft1/_images/' + logo + '.' + imgFormat + '" />';
			circuit_container.style.display = 'none';
			circuit_container.style.paddingTop = '0px';
			circuit_container.style.marginLeft = '0px';
			for ( var otherCnt = 3; otherCnt < circuit_container.childNodes.length; otherCnt+=2 )
			{
				// alert( circuit_container.childNodes[ otherCnt ].nodeName );
				circuit_container.childNodes[ otherCnt ].style.display = 'inline';
			}
			var products_length = products.childNodes.length;
			for (x=1; x<products_length; x+=2)
			{
				products.childNodes[x].childNodes[2].style.display = 'none';
				products.childNodes[x].style.background = 'url(/wp-content/themes/motionsoft1/_images/_product-showcase/tab_blur.jpg) no-repeat center center';
				products.childNodes[x].childNodes[0].childNodes[0].style.color = '#ffffff';
				products.childNodes[x].childNodes[0].childNodes[0].style.fontWeight = 'normal';
			}
			// Show the features of the product selected
			var product_list = document.getElementById(productID);
			var list_length = product_list.childNodes[2].childNodes.length;
			for (i=1; i<list_length; i++)
			{
				feature_id = product_list.childNodes[2].childNodes[i].attributes[0].value;
				feature_item = document.getElementById(feature_id);
				
				// First remove any existing items in case it is the same product
				var link2remove = feature_item.childNodes[0];
				feature_item.removeChild(link2remove);
				
				// Create an A (hyperlink) and place it into the LI
				var feature_link = document.createElement('a'); 
				var flink = '/' + productID + '/' + feature_id + '/';
				feature_link.href = flink; // for browsers that don't support setAttribute 
				feature_link.setAttribute('href', flink);
				feature_item.appendChild(feature_link);
				
				// Create an image and place it into the A
				var feature_img = document.createElement('img');
				//var fimg = imgPath + feature_id + '.jpg';
				//var fimg = imgPath + feature_id + '.png';
				var fimg = imgPath + feature_id + '.' + imgFormat;
				feature_img.src = fimg;
				feature_img.setAttribute('src', fimg);
				feature_img.style.border = '0px';
				feature_img.setAttribute('border', '0px');
				feature_link.appendChild(feature_img);
				
				i++;
			}
			product_list.childNodes[2].style.display = 'inline';
			product_list.style.background = 'url(/wp-content/themes/motionsoft1/_images/_product-showcase/tab_focus.jpg) no-repeat center center';
			product_list.childNodes[0].childNodes[0].style.color = '#333333';
			product_list.childNodes[0].childNodes[0].style.fontWeight = 'bold';
		}
		// IE, Chrome, Safari, and others
		else
		{
			// First, do not display any product features
			var products = document.getElementById('product_showcase');
			// If the Circuit has been visited, reset the first set of LI nodes
			circuit_container = products.childNodes[0].childNodes[1];
			circuit_container.style.display = 'none';
			circuit_container.style.paddingTop = '0px';
			circuit_container.style.marginLeft = '0px';
			for ( var otherCnt = 1; otherCnt < circuit_container.childNodes.length; otherCnt++ )
			{
				circuit_container.childNodes[ otherCnt ].style.display = 'inline';
			}
			var products_length = products.childNodes.length;
			for (k=0; k<products_length; k++)
			{
				products.childNodes[k].childNodes[1].style.display = 'none';
				products.childNodes[k].style.background = 'url(/wp-content/themes/motionsoft1/_images/_product-showcase/tab_blur.jpg) no-repeat center center';
				products.childNodes[k].childNodes[0].childNodes[0].style.color = '#ffffff';
				products.childNodes[k].childNodes[0].childNodes[0].style.fontWeight = 'normal';
			}
			
			// Show the features of the product selected
			var product_list = document.getElementById(productID);
			var list_length = product_list.childNodes[1].childNodes.length;
			
			// Create the child elements, including the link and image
			for (i=0; i<list_length; i++)
			{
				// Grab the feature item by the LI id
				var feature_id = product_list.childNodes[1].childNodes[i].id;
				var feature_item = document.getElementById(feature_id);
				
				// First remove any existing items in case it is the same product
				var link2remove = feature_item.childNodes[0];
				feature_item.removeChild(link2remove);
				
				// Create an A (hyperlink) and place it into the LI
				var feature_link = document.createElement('a'); 
				var flink = '/' + productID + '/' + feature_id + '/';
				feature_link.href = flink; // for browsers that don't support setAttribute 
				feature_link.setAttribute('href', flink);
				feature_item.appendChild(feature_link);
				
				// Create an image and place it into the A
				var feature_img = document.createElement('img');
				//var fimg = imgPath + feature_id + '.png';
				//var fimg = imgPath + feature_id + '.jpg';
				var fimg = imgPath + feature_id + '.' + imgFormat;
				feature_img.src = fimg;
				feature_img.setAttribute('src', fimg);
				feature_img.style.border = '0px';
				feature_img.setAttribute('border', '0px');
				feature_link.appendChild(feature_img);
			}
			// Make the product features visible
			product_list.childNodes[1].style.display = 'inline';
			product_list.childNodes[1].style.zIndex = '5';
			product_list.style.background = 'url(/wp-content/themes/motionsoft1/_images/_product-showcase/tab_focus.jpg) no-repeat center center';
			product_list.childNodes[0].childNodes[0].style.color = '#333333';
			product_list.childNodes[0].childNodes[0].style.fontWeight = 'bold';
		}
	}
}
