function toggleProductTab(divID, parentID) {

    if ($(divID).hasClassName('Description')) {
        $(divID).hide().removeClassName('Description');
    }

    var divs = $(parentID).getElementsBySelector('div');

    $(divs).each(function(e) {
        if ($(e).visible() && $(e).identify() != divID) {
            $(e).fade({ duration: 0.3 });
        }

        if (!$(e).visible() && $(e).identify() == divID) {
            $(e).appear({ duration: 0.3 });
        }
    });

}

//below added by AJC 8/5/09
function changeSwatch(colorID, switchDropdown) {
		//remove the selected class from whatever swatch was selected
		var swatchWrapper = document.getElementById("swatchWrapper")
		var arrSwatch = swatchWrapper.childNodes;
		for (var i = 0; i < arrSwatch.length; i++) {  
			
			var myImg = arrSwatch[i].id;
			
			try {
				if(myImg.indexOf("dvSwatch_") == 0) { 
					var arrDivSwatch = arrSwatch[i].childNodes;
					for (var iCount = 0; iCount < arrDivSwatch.length; iCount++) {
						try {
							if(arrDivSwatch[iCount].id.indexOf("swatch_") == 0) { 
								$(arrDivSwatch[iCount].id).removeClassName('on').addClassName('Off');
							}
							
							if(arrDivSwatch[iCount].id.indexOf("linkSw_") == 0) { 
								$(arrDivSwatch[iCount].id).removeClassName('onLink').addClassName('OffLink');
							}
						}
						catch(ex) {
							//ignore
						}
					}
				}
				
			}
			catch (e) {
				//ignore
			}
		}
		
		if (switchDropdown == false) {
			colorID=colorID.split(';')[2];	
		}
		//add the selected class to the swatch being selected
		$('swatch_' + colorID).removeClassName('Off').addClassName('on');
		//change the dropdown box value
		//  should be false if event was triggered by dropdown
		if (switchDropdown) {
			for (var iSwitcher = 0; iSwitcher < $('selectableOptions').length; iSwitcher++) {
				//alert($('selectableOptions')[iSwitcher].value + '==' + colorID);
				if ($('selectableOptions')[iSwitcher].value.split(';')[2] == colorID) {
					$('selectableOptions').selectedIndex = iSwitcher;
					$('swatch_' + colorID).removeClassName('Off').addClassName('on');
					$('linkSw_' + colorID).removeClassName('OffLink').addClassName('onLink');
					break;
				}
			}
		}
		
		//no thumbnail in this one.
		//hide all the thumbnail sections
		//$$('#productThumbnails div').each(function(item) { item.hide(); });

		//no thumbnail in this one.
		//show the thumbnails for this option
		//$('thumbs_' + colorID).show();

		//replace the main image with the first thumbnail
		//$('imgMain').src = '../getdynamicimage.aspx?path=' + document.getElementById('image_' + colorID).value + '&w=' + 220;
		$('imgMain').src = '../itemimages/' + document.getElementById('image_' + colorID).value;
		
		$('options').value = $('option_' + colorID).value;
	
		changePrice(colorID);
		changeSKU(colorID);
		changeStockStatus(colorID);
	}

	function changePrice(colorID) {
		if ($('values_' + colorID)) {
			var offset = $('values_' + colorID).value.split(';')[0];
			if (parseFloat(offset) >= 0) {
				if (parseFloat($('baseSale').value) == 0) {
					$('Price').innerHTML = '$' + formatCurrency(parseFloat($('basePrice').value) + parseFloat(offset));
				}
				else {
					$('Price').innerHTML = '$' + formatCurrency(parseFloat($('basePrice').value) + parseFloat(offset));
				}
			}
			else {
				if (parseFloat($('baseSale').value) == 0) {
					$('Price').innerHTML = '$' + formatCurrency(parseFloat($('basePrice').value));
				}
				else {
					$('Price').innerHTML = '$' + formatCurrency(parseFloat($('basePrice').value)) + ' $' + formatCurrency(parseFloat($('baseSale').value));
				}
			}
		}
	}

	function changeSKU(colorID) {
		if ($('values_' + colorID)) {
			if ($('Sku')) {
				$('Sku').innerHTML = $('values_' + colorID).value.split(';')[1];
			}
			
			var sel = document.getElementById("selectableOptions");
			
			//get the selected option
			var selectedText = sel.options[sel.selectedIndex].text;

			$('ProductName').innerHTML = selectedText + ' ' + $('hdnName').value;
			$('aProdBread').innerHTML = selectedText + ' ' + $('hdnName').value;
		}
	}

	function changeStockStatus(colorID) {
		if ($('values_' + colorID)) {
			if ($('StockStatus')) {
					var iThreshold = 0
				//  NR:  Waiting for stock status in product options
				var quantity = $('values_' + colorID).value.split(';')[2];
				var stockStatus = 1;

				if (quantity <= iThreshold)
					stockStatus = 2;

				if (stockStatus == 1) {
					$('StockStatus').innerHTML = "stock status: <strong>In Stock</strong>";
					$('AddToCart').show();
					$('prodQty').disabled = false;
				}
				else {
					$('StockStatus').innerHTML = "stock status: <strong>Out of Stock</strong>";
					$('AddToCart').hide();
					$('prodQty').disabled = true;
				}
			}
		}
	}
	
	
	function formatCurrency(amount) {
		var i = parseFloat(amount);
		if (isNaN(i)) { i = 0.00; }
		var minus = '';
		if (i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if (s.indexOf('.') < 0) { s += '.00'; }
		if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		return s;
	}
	
	function AddToCart() {
	
	
		showProduct('Shopping Bag');
	
		var dropdownIndex;
		var dropdownValue;
		try {
			dropdownIndex = document.getElementById('selectableOptions').selectedIndex;
			dropdownValue = document.getElementById('selectableOptions')[dropdownIndex].value;
		}
		catch(ex) {
			//ignore
		}
		var qty = document.getElementById('prodQty').value;
		var itemsinbag=0;
		
		//check out header.asp wrap span tag around it pull the innerhtml out of it and add the quantity to the number.....
		//get innerhtml of  document.getElementById('spnCartCount').innerHTML
		itemsinbag=document.getElementById('spnCartCount').innerHTML;
		itemsinbag=itemsinbag.replace('(','');
		itemsinbag=itemsinbag.replace(')','');
		var totalItems = parseInt(qty) + parseInt(itemsinbag);
		
		//add to bag....
		document.getElementById('spnCartCount').innerHTML = '(' + totalItems.toString() + ')';
		
		
		return(false);
	}
	
	//below for light window
	function showProduct(title) {
		//vars....prod,qty and options.....
		//prod=productid
		//quantity
		//option may not be there.... this is the droplist
		//options=selected value
		//alert('selected productid=' + dropdownValue);
		var dropdownIndex;
		var dropdownValue='';
		try {
			dropdownIndex = document.getElementById('selectableOptions').selectedIndex;
			dropdownValue = document.getElementById('selectableOptions')[dropdownIndex].value;
			
			//JL: remove the 3rd part..
			dropdownValue = dropdownValue.split(';')[0] + ';' + dropdownValue.split(';')[1];
		}
		catch(ex) {
			//ignore
		}
		var qty = document.getElementById('prodQty').value;
		showLightWindow('../ajax_addedtocart.asp?prod=' + document.getElementById('prodID').value.toString() + '&quantity=' + qty.toString() + '&options=' + dropdownValue, title, 420, 422);
		
		//return(false);
	}

	function showLightWindow(iUrl,iTitle,iWidth,iHeight){
		if (iTitle.length > 40)	{
			iTitle = iTitle.substring(0,40);
		}
		//  Create the lightwindow
		myLightWindow.activateWindow({
			href: iUrl,
			type: 'page',
			title: iTitle,
			width: iWidth,
			height: iHeight
		});
	}

	
	function showProductVideoVapour(videoName) {
		//alert(videoName);
		//var oImage = document.getElementById('imageArea');
		//oImage.style.display = 'none';
		
		var oVideo = document.getElementById('videoArea');
		oVideo.style.display = 'block';
		
		if (videoName != '') {
			//show it
			
			flowAPI = flashembed("videoArea",
			  {
				 src:'/FlowPlayerLP.swf',
					width: 400,
					height: 300
			  },
	
			  {config: {
					videoFile: videoName,
					autoPlay: false
			  }}
		   );
		}
	}
//above added by AJC 8/5/09

function homePageArea() { 
	if (!document.all) {
		new fadeshow(fadeimages, 950, 377, 0, 3000, 1, "");}
	else		
	{
		document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>'); 
		var contentloadtag=document.getElementById("contentloadtag");  
		contentloadtag.onreadystatechange=function() { if (this.readyState=="complete")  {new fadeshow(fadeimages, 950, 377, 0, 3000, 1, "");} } 
	} 
	
}