/* Sitecore IE6 image width fix */
window.addEvent('domready', function() {
	if(Browser.Engine.trident && Browser.Engine.version==4) {
        $(document.body).getElements('img').removeProperty('width');

		// src = .src.replace(/\?.*$/, '') + '?' + Math.random();
		
		$(document.body).getElements('img').each(function(image, index) {
			image.setStyle('opacity', 1);
			image.setProperty('src', image.getProperty('src'));
      });


	} 
});

function loadImageGallery() {
    window.addEvent('domready', function() {
	    // setup variables
	    var largeImage		= $('ProductImageLarge');
	    var largeImageWidth	= 287;
	    var galleryImages	= $('ProductImages').getElements('a');
	    var currentImage	= $('ProductImages').getFirst('a');
	    	    
	    // loop through images
	    galleryImages.each(function(image, index) {    	    
	        // fade all images except the first image
    	    if (image != currentImage) image.getElement('img').setStyle('opacity', 0.25);
    	    
		    image.addEvent('mouseenter', function() {
		        // show the current image and fade the others
        	    image.getElement('img').setStyle('opacity', 1);	    
        	    if (image != currentImage) currentImage.getElement('img').setStyle('opacity', 0.25);
        	    
			    // change the large image
		        largeImage.setProperty('src', image.getProperty('href') + '?h=' + largeImageWidth);
		        
   			    // set current image
    		    currentImage = image;
		    });   
	    })    			

        largeImage.addEvent('click', function() {
            // open gallery starting at the current image
            Shadowbox.open(currentImage,{player:'img',gallery:'images'});
        })
	    
    });
}