$(function(){
	var selectClass = 'select_item';
	
	var photoSct = $('div.js_swap_photo, table.js_swap_photo');
	photoSct.each(
		function(){
			var imgElm = $(this).find('table.js_swap_photo img.js_swap_photo');
			var anchorElm = $(this).find('table.js_swap_photo a').filter('table.js_swap_photo .js_swap_photo, table.js_swap_photo .js_swap_photo_hover');

			anchorElm.each(function(index){
				var $this = $(this);
				if($this.hasClass('js_swap_photo_hover')){
					$this
						.mouseover(function(evnt){
							swapImage.apply(this, [imgElm, $(this).attr('rel'), $(this).attr('href')]);
							swapClass.apply(this, [anchorElm, selectClass]);
							return false;
						})
					;
				}
				else{
					$this
						.click(function(evnt){
							swapImage.apply(this, [imgElm, $(this).attr('href'), null]);
							swapClass.apply(this, [anchorElm, selectClass]);
							return false;
						})
					;
				}
				
			});
		}
	);
	
	function swapImage(imgElm, src, href){
		imgElm.attr('src', src);
		if(href){
			imgElm.parent('a').attr('href', href);
		}
	}

	function swapClass(anchorElm, selectClass){
		anchorElm.removeClass(selectClass);
		$(this).addClass(selectClass);
	}
});
