$.fn.autoSlider = function(file,options){
	var options = {
		time      : 10000,
		duration  : 1000,
		count     : 13,
		easing    : 'linear'
	};
	$.extend(options,options);
	var $target = this;
	
	//setting
	$target.find(' > div').wrapAll('<div class="'+$target.attr('id')+'-inline"></div>');
	var Inline = '.'+$target.attr('id')+'-inline';
	var Outline = '.'+$target.attr('id')+'-outline';
	var firstPosition = $target.position().left;
	$(Inline).css({
		'width'    : $target.width(),
		'height'   : $target.height(),
		'position' : 'absolute',
		'top'      : '0',
		'left'     : $target.position().left
	});
	$target.css({
		'width' : '100%',
		'height'   : $target.height(),
		'overflow' : 'hidden',
		'position' : 'relative'
	});
	
	
	$.ajax({
		url      : file,
		async    : true,
		cache    : false,
		dataType : "xml",
		success  : function(xml){
			var OutPut = '';
			var Detail = '';
			$(xml).find('item').each(function(i){
				
				OutPut += '<div id="thums'+$(this).attr('id')+'" class="thums '+$(this).attr('type')+' detail'+$(this).attr('id')+'">';
				OutPut += '<p><a href="'+$(this).find('link').text()+'" target="'+$(this).find('link').attr('target')+'">';
				if($(this).attr('type') == 'small'){
					OutPut += '<img src="'+$(this).find('thum').text()+'" width="95" height="95" alt="" />';
				}else if($(this).attr('type') == 'medium'){
					OutPut += '<img src="'+$(this).find('thum').text()+'" width="212" height="95" alt="" />';
				}else if($(this).attr('type') == 'large'){
					OutPut += '<img src="'+$(this).find('thum').text()+'" width="212" height="212" alt="" />';
				}
				OutPut += '</a></p>';
				OutPut += '</div>';
				Detail += '<dl id="detail'+$(this).attr('id')+'" class="tool_detail">';
				Detail += '<dt>'+$(this).find('title').text()+'</dt>';
				Detail += '<dd>'+$(this).find('text').text()+'</dd>';
				Detail += '</dl>';
				
				
			});
			$(Inline).append(OutPut).find(' > div').not('#Loading').css('opacity','0');
			$target.after(Detail);
		},
		error   : function(xml){
			alert('XMLファイルがありません。');
		},
		complete : function(){
			setTimeout(function(){
				$target.find('#Loading').fadeOut(300,function(){
					$(this).remove();
					$('noscript').remove();
					LoadStart();
				});
			},1000);
		}
	});
	
	function LoadStart(){
		var ItemArr = $.makeArray($(Inline).find(' > div'));
		var count   = ItemArr.length;
		while(count){
			var j = Math.floor(Math.random() * count);
			var t = ItemArr[--count];
			ItemArr[count] = ItemArr[j];
			ItemArr[j] = t;
		}
		
		var num = 0;
		var int = setInterval(function(){
			if(num == options.count){
				clearInterval(int);
				setTimeout(function(){
					CloneItem();
				},800);
			}else{
				$(ItemArr).eq(num).animate({'opacity':'1'},{duration:options.duration,easing:options.easing});
			}
			num++;
		},100);
	}
	
	function CloneItem(){
		var $clone = $(Inline);
		for(i=1;i<5;i++){
			$target.append($clone.clone());
		}
		$(Inline).wrapAll('<div class="'+$target.attr('id')+'-outline"></div>');
		$(Outline).css({
			'width'     : $(Inline).width()*5,
			'height'    : $(Inline).height(),
			'overflow'  : 'hidden',
			'position'  : 'absolute',
			'top'       : '0',
			'left'      : firstPosition - $(Inline).width()*2
		});
		$(Inline).each(function(i){
			$(this).addClass('inline0'+(i+1));
			
			$(this).css('left',$(this).width()*i);
			if(i != 2){
				$(this).hide().fadeIn(options.duration,function(){
					$(Outline).css('left',firstPosition - $(Inline).width());
					$(Inline).css({
						'position':'relative',
						'top':'0',
						'left':'0',
						'float':'left',
						'display':'inline'
					});
				});
			}
		});
		setTimeout(function(){
			AutoSlider();
		},800);
	}
	
	function AutoSlider(){
		$(Outline).simplyScroll();
		var Split = '';
		$(Inline).find('.thums').hover(function(){
			$('.tool_detail').hide().css('z-index','2');
			Split = $(this).attr('class').split(' ');
			$(this).mousemove(function(e){
				$('#'+Split[2]).show().css({
					'top'  : e.pageY + 10 ,
					'left' : e.pageX + 10 ,
					'z-index' : '1000'
				});
			});
		},function(){
			$('.tool_detail').hide().css('z-index','2');
		});
	}
}
