$.fn.ItemDetail = function(Flie){
	var $Target = this;
	var targetId = $Target.parent().attr('id');
	
	$.ajax({
		url:Flie,
		dataType:'xml',
		success:function(data){GetData(data)},
		error:function(){error();},
		complete:function(){Preload()}
	});
	
	function error(){
		alert('XMLファイルがありません。');
	}
	
	function GetData(data){
		var OutPut  = '';
		$(data).find('item').each(function(i){
			OutPut += '<li class="'+$(this).attr('class')+'" num="'+i+'">';
				OutPut += '<a href="'+$(this).attr('link')+'" class="group-rover">';
					$(this).find('img').each(function(i){
						OutPut += '<img src="'+$(this).text()+'" width="185" height="105" alt="" class="pic" num="'+i+'" />';
					});
					OutPut += '<strong>'+$(this).find('title').attr('alt')+'</strong>';
				OutPut += '</a>';
			OutPut += '</li>';
		});		
		$Target.prepend(OutPut);
	}

	function Preload(){		
		$('#'+targetId).find('ul li a').each(function(){
			var n = Math.floor(Math.random() * 3);
			$(this).find('img.pic').eq(n).addClass('active');
		});
		setTimeout(function(){Change();},3000);
	}
	
	function Change(){	
  		var n = Math.floor(Math.random() * 11);
			var num = $('#'+targetId).find('li').attr('num');
			
			if(n != num){			
  			$('#'+targetId).find('li').eq(n).find('a').each(function(){
					var n02 = Math.floor(Math.random() * 3);
					var num02 = $(this).find('img.active').attr('num');
				
					if(n02 != num02){
						$(this).find('img.pic').not('img.active').animate({'opacity':0},800);
						$(this).find('img.pic').stop().animate({'opacity':0},800,function(){
							$(this).removeClass('active');
							$(this).parent().find('img.pic').eq(n02).addClass('active').animate({'opacity':1},800);
						});
						setTimeout(function(){Change();},3000);
					}else{
						Change();
					}
  			});
			}else{
				Change();
			}
	}
}
