function insertAfter(new_node, existing_node) {
  // if the existing node has a following sibling, insert the current
	// node before it. otherwise appending it to the parent node
	// will correctly place it just after the existing node.
	
	if (existing_node.nextSibling) {
		// there is a next sibling. insert before it using the mutual
		// parent's insertBefore() method.
		existing_node.parentNode.insertBefore(new_node, existing_node.nextSibling);
	} else {
		// there is no next sibling. append to the end of the parent's
		// node list.
		existing_node.parentNode.appendChild(new_node);
	}
	
} // insertAfter()
	
	function IsImageOk(img) {
// During the onload event, IE correctly identifiesany images that
// weren’t downloaded as not complete. Others should too. Gecko-based
// browsers act like NS4 in that they report this incorrectly.
if (!img.complete) {
return false;
}

// However, they do have two very useful properties:naturalWidth and
// naturalHeight. These give the true size of the image. If it failed
// to load, either of these should be zero.
if (typeof img.naturalWidth != 'undefined' && img.naturalWidth == 0) {
return false;
}

// No other way of checking: assume it’s ok.
return true;
}


function swapImage(img, src){
		//img.src=src;
        var count = 0;
        var loadingimg = document.createElement('img');
			loadingimg.style.position = 'absolute';
            		var img1 = new Image();
                    loadingimg.img1 = img1;
                    loadingimg.count = 0;
            loadingimg.onload = function () {
         //           if (!count) {
					loadingimg.style.width = 127; //for ie6
					loadingimg.width = 127; //for ie6
					loadingimg.style.top = (((img.height/2) - (loadingimg.height/2))) + "px";
					loadingimg.style.left = (((img.width/2) - (loadingimg.width/2)) + 7) + "px";
					loadingimg.style.zIndex = 3;
					//anything other than thumbnails skips in IE for some reason
					img.parentNode.insertBefore(loadingimg,img);
           //         count++;
           loadingimg.count = 1;
             //       }
				};
			loadingimg.src = "images/loader.white.gif";
            
        img1.onload = function () { 
                if (loadingimg.count) {
				loadingimg.parentNode.removeChild(loadingimg);
                }
                else {
                 loadingimg.onload = function () {
                 loadingimg.parentNode.removeChild(loadingimg);
                 loadingimg.count = 1;
                 };
                }//else
				(document.getElementById('mainimage')).style.width = (14 + img1.width) + "px";
				img.style.height = img1.height + "px";
				img.style.width = img1.width + "px";
				img.src=src;
			};
		img1.src = src; 
            
		
	}
	
    /*
    function swapImage(img, src){
		//img.src=src;
		
		var img1 = new Image();
		img1.src = src; 
		if (!IsImageOk(img1)) {
			var loadingimg = document.createElement('img');
			loadingimg.style.position = 'absolute';
			loadingimg.src = "images/loader.white.gif";
			if (!IsImageOk(loadingimg)) {
				loadingimg.onload = function () {
					loadingimg.style.width = 127; //for ie6
					loadingimg.width = 127; //for ie6
					loadingimg.style.top = (((img.height/2) - (loadingimg.height/2))) + "px";
					loadingimg.style.left = (((img.width/2) - (loadingimg.width/2)) + 7) + "px";
					loadingimg.style.zIndex = 3;
					//anything other than thumbnails skips in IE for some reason
					img.parentNode.insertBefore(loadingimg,img);
				};
			}
			else {
				loadingimg.style.width = 127; //for ie6
				loadingimg.width = 127; //for ie6
				loadingimg.style.top = (((img.height/2) - (loadingimg.height/2))) + "px";
				loadingimg.style.left = (((img.width/2) - (loadingimg.width/2)) + 7) + "px";
				loadingimg.style.zIndex = 3;
				//anything other than thumbnails skips in IE for some reason
				img.parentNode.insertBefore(loadingimg,img);
			}
			
			img1.onload = function () { 
				loadingimg.parentNode.removeChild(loadingimg);
				(document.getElementById('mainimage')).style.width = (14 + img1.width) + "px";
				img.style.height = img1.height + "px";
				img.style.width = img1.width + "px";
				img.src=src;
			};
		}
		else {
			(document.getElementById('mainimage')).style.width = (14 + img1.width) + "px";
			img.src=src;
			img.style.height = img1.height + "px";
img.style.width = img1.width + "px";
		}
		
	}
*/
