// Scripts for handling thumbnail gallery
// Assumptions: 
thumbnailGallery = { // try to get this assumptive info from somewhere else that can be dynam updated
//rootFileName: 'three-five-hard-drive-', // assumes this base file name for frame images
//imagesDirectory: '/EdgeTechCorp_EComm_Live (Beta)/Storefront/Assets/images/harddrive/', // directory for images
imageGalleryLinks: [],
init:function() {
	if (!document.getElementsByTagName || !document.getElementById) { return false; }

	/* get links that are gallery elements */
	thumbnailGallery.imageGalleryLinks = document.getElementsByTagName("a");
	for(var i=0; i<thumbnailGallery.imageGalleryLinks.length; i++) {
		if (DOMhelp.cssjs('check', thumbnailGallery.imageGalleryLinks[i], 'galleryLink')) {
			// on hover over a gallery link call show image
			DOMhelp.addEvent(thumbnailGallery.imageGalleryLinks[i], 'mouseover', thumbnailGallery.showImage, false);
			DOMhelp.addEvent(thumbnailGallery.imageGalleryLinks[i], 'click', thumbnailGallery.cancelThisClick, false);
		}
	}
},
showImage:function(e) {
	var obj = DOMhelp.getTarget(e);
	if (obj != 'NULL') {
		// if the click is taken by the img node then get the a tag around it.
		if (obj.nodeName.toLowerCase() != 'a') {
			obj = obj.parentNode; 
		}
	}
	//if(obj.nodeName == 'DIV') { alert('div receiving hover '); }
	// get the big image container and if it not here then exit return true to follow click
	if(!document.getElementById("productImage")) { return true; }
	var productImage = document.getElementById("productImage");
	// get the links href which is the source file of the big image
	var source = obj.getAttribute("href");
	// set the image container source to be this href value
	productImage.setAttribute("src", source);

// (this goes away now.) Change the drop down to match the swatch color
//	if(thumbnailGallery.colorSelector) {
//		alert('color');
//		var colorName = obj.getAttribute("title");
//		thumbnailGallery.colorSelector.selectedIndex = thumbnailGallery.colors[colorName];
//	}
},
cancelThisClick:function(e) {
	DOMhelp.cancelClick(e);
	return false;
},
changeImage:function(e) {
	//var obj = DOMhelp.getTarget(e);
	//if (obj != null) {
	//	if (obj.nodeName != 'SELECT') {
			// Mozilla is not getting the right value for e.target
			// Resetting it to e.currentTarget
	//		obj = e.currentTarget; 
	//	}
	//}
	/*if(!document.getElementById("productImage")) { return true; }
	var productImage = document.getElementById("productImage");
	var colorIndex = obj.selectedIndex;
	var colorName = obj.options[colorIndex].getAttribute('value');
	var source = thumbnailGallery.imagesDirectory + thumbnailGallery.rootFileName + colorName + ".jpg";
	productImage.setAttribute('src', source);
	*/
}

}	
DOMhelp.addEvent(window,'load', thumbnailGallery.init, false);





