function RollImage()
{
	this.ArrImages;
	this.ArrSpanNumber;
	this.TimeOut;
	this.ImageIndex = 0;
	this.AbsolutelyLeft = 0;
	this.AbsolutelyTop = 0;
	this.divNumber = document.createElement("div");
	this.divNumber.style.width = "100%";

	this.divArea;
	this.StartRoll=function(area,imgs,showNumber)
	{
		if(!area)
		{
			return;
		}
		this.span;
		
		this.divArea = area;

		this.ArrImages = imgs.split("|");
		this.ArrSpanNumber = new Array(this.ArrImages.length);
		for(var i=0;i<this.ArrImages.length;i++)
		{			
			if(i==0)
			{
				this.Roll(this.ArrImages[0]);
			}
			
			this.span = document.createElement("div");
			this.span.setAttribute("imgSource",this.ArrImages[i]);
			this.span.setAttribute("ImageIndex",i)
			this.span.style.width = "14px";
			this.span.style.height = "14px";
			this.span.style.textAlign = "center";
			this.span.style.position = "absolute";
			this.span.style.border = "1px solid #cccccc";
			this.span.style.fontSize = "12px";
			this.span.style.paddingLeft = "2px";
			this.span.style.paddingRight = "2px";
			this.span.style.cursor="hand";
			this.span.style.backgroundColor = "#EEEEEE";
			this.span.style.marginLeft = (i * 22) + "px";
			this.span.style.marginTop = "-16px";
			this.span.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=60)";
			this.span.innerHTML = "<a href='"+ this.ArrImages[i].split("*")[1] + "' target='_blank'>" + (i+1).toString() + "</a>";			

			var _this = this;
			this.span.attachEvent("onmouseover",this.Span_MouseOver(_this,_this.span,_this.ArrImages[i]));
			this.span.attachEvent("onmouseout",this.Span_MouseOut(_this,_this.span,null));			

			this.ArrSpanNumber[i] = this.span;

			if(showNumber)
				this.divArea.parentElement.appendChild(this.span);
			if(i==0)
			{
				this.ChangeFocusStyle(_this.span);
			}
		}
		
		
        var callback = function(){ _this.AutoRoll(); };
        _this.TimeOut = window.setInterval(callback,5000);

	}
	this.GetAbsolutelyLeft=function(obj)
	{
		var absolutelyLeft = 0
		while(obj = obj.offsetParent)
		{
			absolutelyLeft += obj.offsetLeft;
		}
		return absolutelyLeft;
	}

	this.GetAbsolutelyTop=function(obj)
	{
		var absolutelyTop = 0
		while(obj = obj.offsetParent)
		{
			absolutelyTop += obj.offsetTop;
		}
		return absolutelyTop;
	}

	this.ChangeFocusStyle=function(span)
	{		
		var spans = span.parentNode.getElementsByTagName("div");
		for(var i=0;i<spans.length;i++)
		{
			if(spans[i].getAttribute("imgSource") != null)
			{				
				spans[i].style.backgroundColor = "#EEEEEE";
			}
		}
		span.style.backgroundColor = "#ff0000";
	}

	this.Roll=function(img)
	{
		var random = Math.round(Math.random()*10);

		switch(random)
		{
			case 0:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.Barn(duration=1)";
				break;
			case 1:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.Blinds(duration=1)";
				break;
			case 2:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.CheckerBoard(duration=1)";
				break;
			case 3:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.GradientWipe(duration=1)";
				break;
			case 4:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.Inset(duration=1)";
				break;
			case 5:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.Iris(duration=1)";
				break;
			case 6:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.Pixelate(duration=1)";
				break;
			case 7:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.RadialWipe(duration=1)";
				break;
			case 8:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.RandomBars(duration=1)";
				break;
			case 9:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.RandomDissolve(duration=1)";
				break;
			default:
				this.divArea.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=1)";

		}
		this.divArea.filters[0].Apply();

		this.divArea.innerHTML = "";

		var a = document.createElement("a");
		a.href = img.split("*")[1];

		var image = document.createElement("img");
		image.src = img.split("*")[0];
		image.border = "0";

/*
		//如果不是IE
		if(navigator.appName != "Microsoft Internet Explorer")
		{
			image.height = this.divArea.offsetParent.offsetHeight;
		}
		//如果是IE，但是不是IE7
		else if(navigator.appVersion.match(/7./i)!='7.')
		{
			image.height = this.divArea.offsetParent.offsetHeight;
		}
*/
		a.appendChild(image);
		this.divArea.appendChild(a);

		this.divArea.filters[0].Play();
	}

	this.AutoRoll=function()
	{
		this.ImageIndex += 1;
		//到最后一张图片了
		if(this.ImageIndex >= this.ArrImages.length)
		{
			this.ImageIndex = 0;
		}
		this.Roll(this.ArrImages[this.ImageIndex]);
		this.ChangeFocusStyle(this.ArrSpanNumber[this.ImageIndex]);
	}

	this.Body_AutoRoll=function(rollImage)
	{
		return function()
		{			
			rollImage.AutoRoll();
		}
	}
	this.Span_MouseOver=function(rollImage,sender,args)
	{
		return function()
		{			
			rollImage.Roll(args);
			rollImage.ChangeFocusStyle(sender);
			rollImage.ImageIndex = parseInt(sender.getAttribute("ImageIndex"));
			window.clearInterval(rollImage.TimeOut);
		}
	}	

	this.Span_MouseOut=function(rollImage,sender,args)
	{
		return function()
		{
			rollImage.TimeOut = window.setInterval(rollImage.Body_AutoRoll(rollImage),3000);
		}
	}
}

window.onerror=function()
{
	return true;
}
