document.observe('dom:loaded', initImageSwapper);

function initImageSwapper(){
	if($('thumb')){
		$('thumb').observe('click', function(ev){
			swapImages(); 
			ev.stop();
		})
	}
}

function swapImages(){
	var mainImg = $('detail');
	var thumbImg = $('thumb');
	var newMain = document.createElement('img');
	var newThumb = document.createElement('img');
	newMain.id = "detail";
	newMain.src = thumbImg.src;
	newThumb.id = "thumb";
	newThumb.src = mainImg.src;
	
	document.body.replaceChild(newMain, mainImg);
	thumbImg.parentNode.replaceChild(newThumb, thumbImg);
	initImageSwapper();
}