//定义图片的类型
function MyImage(path,title,url){ 
	this.Path=path;
	this.Title=title;
	this.URL=url;
} 
jQuery.fn.duximgfade = function(options) {
	var settings = {
	FadeSpeed: 500,
	ImagesList:null,
	Interval:2000,
	StretchImage:true,
	ShowMaskTitle:true
	};
	if(options){
		jQuery.extend(settings, options);
	}
	$('head').append("<LINK media=screen href=\" jquery/duximgfade.css \" type=text/css rel=stylesheet>");
	
	var box=$(this);
	var CurrentIndex=0;
	var Count=0;
	var Switching=null;
	if(settings.ImagesList!=null){Count=settings.ImagesList.length;}
	init();//初始化
	
	function init()
	{
		box.append('<div id="s_mask" class="s_mask"></div>');
		$(box).width(200).height(89);
		$(box).find('.s_mask').width(200).height(89).click(function(){
			window.location.href=settings.ImagesList[CurrentIndex].URL;
		});
		PickTitle(CurrentIndex);
		$(settings.ImagesList).each(function(i)
		{
			if(i!=0)
			{
				$(box).append('<img src="'+settings.ImagesList[i].Path+'" class="s_fiximg" style="display:none" />');
			}
			else
			{
				$(box).append('<img src="'+settings.ImagesList[i].Path+'" class="s_fiximg" />');
			}
		});
		
		if(settings.StretchImage)
		{
			$('img',$(box)).each(function(){
				$(this).width(200).height(89);
			});
		}
		if(settings.ShowMaskTitle)
		{
			$('img',$(box)).each(function(){
				$(this).bind("mouseover",function(e)
				{
					$('#s_mask',$(box)).show();e.stopPropagation();
					
				});
				$('#s_mask',$(box)).bind('mouseout',function(e)
				{
					if(e.target==this)
					{
						$('#s_mask',$(box)).hide();e.stopPropagation();
					}
				});
			});
		}
	}
	function switchImage()
	{
		if(settings.ImagesList.length>1)
		{
			if(CurrentIndex<Count-1)
			{
				$('.s_fiximg',$(box)).eq(CurrentIndex).fadeOut(settings.FadeSpeed);
				$('.s_fiximg',$(box)).eq(CurrentIndex+1).fadeIn(settings.FadeSpeed);
				CurrentIndex++;
				PickTitle(CurrentIndex);
	
			}
			else
			{
				$('.s_fiximg',$(box)).eq(CurrentIndex).fadeOut(settings.FadeSpeed);
				$('.s_fiximg',$(box)).eq(0).fadeIn(settings.FadeSpeed);
				CurrentIndex=0;
				PickTitle(CurrentIndex);
			}	
			Switching=setTimeout(function(){switchImage()},settings.Interval);
		}
	}
	function PickTitle(idx)
	{
		$('#s_mask',$(box)).html(settings.ImagesList[idx].Title);
	}
	function startSwitching()
	{
		//setTimeout(function(){switchImage()},settings.Interval);
		setTimeout(function(){switchImage()},settings.Interval);
	}
	function stopSwitching()
	{
		if(Switching!=null)
		{
			clearTimeout(Switching);
			Switching=null;
		}
	}
	startSwitching();//初始化后的起点
};