﻿function CreateFlash(box,width,height,url,maxlength) {
	this.Box = $("#" + box);
	this.Name = "图片切换";
	this.Author = "Keboy";
	this.Version = "1.0";
	this.CreateDate = "2009-12-24";
}
CreateFlash.prototype = {
	Width: 0,
	Height: 0,
	LoadUrl: "",
	MaxLength: 0,
	Speed: 0,
	BigPic: new Array(),
	SmallPic: new Array(),
	LinkUrl: new Array(),
	Stay: 0,
	Start: function() {
		var _this = this;
		$.ajax( {
			type: "get",
			url: _this.LoadUrl,
			cache: false,
			data: "",
			dataType: ($.browser.msie) ? "text" : "xml",
			error: function() { alert("Error loading XML document"); },
			success: function(result) {
				if ( typeof result == "string" ) {
					var xml = new ActiveXObject("Microsoft.XMLDOM");
					xml.async = false;
					xml.loadXML(result);
				}
				else {
					var xml = result;
				}
				var l = xml.getElementsByTagName("data")[0].getElementsByTagName("l")
				for ( var i = 0; i < l.length; i++ ) {
					with(_this) {
						BigPic[i] = l[i].getAttribute("big");
						SmallPic[i] = l[i].getAttribute("small");
						LinkUrl[i] = l[i].getAttribute("url");
					}
				}
				_this.CreateBox();
			}
		} );
	},
	CreateBox: function() {
		var htmldata = "";
		htmldata += "<img class='boxbigger' src='" + this.BigPic[0] + "' width='" + this.Width + "' height='" + this.Height + "' style='cursor:pointer;' />";
		htmldata += "<div id='sbox' style='padding-right:50px;position:relative;margin-top:-50px;width:212px;height:40px;margin-left:auto;overflow:hidden;'>";
		for ( var i = 0; i < this.SmallPic.length; i++ ) {
			htmldata += "<div class='sboxes' rel='" + i + "' style='width:43px;height:40px;float:left;margin-right:10px;'>";
			htmldata += "	<div class='sboxarrow' style='width:43px;height:8px;overflow:hidden;clear:both;'><!----></div>";
			htmldata += "	<div class='sboximg' style='width:41px;height:30px;border:1px #FFF solid;overflow:hidden;clear:both;background:#000;'><img src='" + this.SmallPic[i] + "' width='41' height='30' style='cursor:pointer;' /></div>";
			htmldata += "</div>";
		}
		htmldata += "</div>";
		this.Box.html(htmldata);
		$("#sbox img").fadeTo(0.01,0.3);
		this.Stay = this.MaxLength - 1;
		this.MovieStart();
	},
	MovieStart: function() {
		var _this = this;
		GoCross(0);
		var mar = setInterval(GoCross,this.Speed * 1000);
		function GoCross(newStay) {
			$("#sbox div.sboxes:eq(" + _this.Stay + ") div.sboxarrow:first").css("background","none").next().find("img").fadeTo("fast",0.3);
			if ( newStay == null ) {
				if ( _this.Stay == _this.MaxLength - 1 ) {
					_this.Stay = 0;
				}
				else {
					_this.Stay++;
				}
			}
			else {
				_this.Stay = newStay;
			}
			_this.Box.find("img.boxbigger").fadeTo("fast",0.3,function() {
				$(this).attr("src",_this.BigPic[_this.Stay]).attr("rel",_this.LinkUrl[_this.Stay]).fadeTo("fast",0.99);
			});
			$("#sbox div.sboxes:eq(" + _this.Stay + ") div.sboxarrow:first").css("background","url(js/banner/arrow.gif) no-repeat center").next().find("img").fadeTo("fast",0.99);
		}
		$("#sbox div.sboxes").click( function() {
			clearInterval(mar);
			GoCross(parseInt($(this).attr("rel")));
			mar = setInterval(GoCross,_this.Speed * 1000);
		} );
		this.Box.find(".boxbigger").click( function() {
			if ( $(this).attr("rel") != "" ) {
				window.open($(this).attr("rel"));
			}
		} );
	}
};