//*****************************************************************************
// Author:	Page8 Studios - Jackie Apshire Jr.
// Date:	5/14/2008

// The purpose of this script is to allow the implementation of
// the Highslide image resizing script in the AmeriCommerce system.
// It allows the user to only have to supply a single image for each
// product by tapping into AmeriCommerce's "Image Resizer" system.
//*****************************************************************************

function getHighSlideFullImage(oHighSlideLink){
	
	var oThumbImage = oHighSlideLink.getElementsByTagName("img")[0];
	var sFullImagePath = "/store/images/default-product-image.jpg"; // AC's default image when none can be found.
	
	if(oThumbImage != null){
		//alert("Image found!");
		sFullImagePath = oThumbImage.src;
		//alert("Path: " + sFullImagePath);
		
		// Pull out just the image path
		var iStartOfPath = sFullImagePath.indexOf("?path=") + 6;
		var iEndOfPath = sFullImagePath.indexOf("&");
		sFullImagePath = sFullImagePath.substring(iStartOfPath, iEndOfPath);
		//alert("Final Path: " + sFullImagePath);
	}
	
	// Check to see if we found anything and if so then lets pass it to Highslide.
	oHighSlideLink.setAttribute("href", sFullImagePath);
	
	return hs.expand(oHighSlideLink);
}	

// Added 9/29/2008
function zoomButtonClicked(poDivID)
{
	var oMainDiv = document.getElementById(poDivID);
	// This is more of a hack...Firefox seems to create multiple copies of the link/image
	// and you have to use 2 for you index for it to work correctly.
	var oMainLink = oMainDiv.getElementsByTagName("a")[2];
	var oMainImg = oMainDiv.getElementsByTagName("img")[0];
	
	//alert(oMainImg.src);
	if(oMainImg != null){
		//alert("Image found!");
		sFullImagePath = oMainImg.src;
		//alert("Path: " + sFullImagePath);
		
		// Pull out just the image path
		var iStartOfPath = sFullImagePath.indexOf("?path=") + 6;
		var iEndOfPath = sFullImagePath.indexOf("&");
		sFullImagePath = sFullImagePath.substring(iStartOfPath, iEndOfPath);
		//alert("Final Path: " + sFullImagePath);
	}

	//alert(oMainLink.id);
	oMainLink.setAttribute("href", sFullImagePath);
	
	return hs.expand(oMainLink);
}
