﻿/*
创建实例:
	参数直接赋值法
	new FlashPicture(ID,Width,Height,AutoTime,Tween,ShowButton,TitlePosition,LinkMode,TitleColor,TitleBackground,TitleAlpha,ButtonColor,ButtonOver)

	参数动态赋值法
	var FlashNews = new FlashPicture(ID)	*此参数必选
	FlashNews.Width = 400;
	FlashNews.Height = 300;
	FlashNews.AutoTime = 5;
	FlashNews.Tween = 0;
	FlashNews.ShowButton = 1;
	FlashNews.TitlePosition = 2;
	FlashNews.LinkMode = "_self";
	FlashNews.TitleColor = "FFFFFF";
	FlashNews.TitleBackground = "000000";
	FlashNews.TitleAlpha = 60;
	FlashNews.ButtonColor = "888888";
	FlashNews.ButtonOver = "999999";
	FlashNews.Show();

	参数说明:
		ID					"ObjectID"					容器ID					(必选)
		Width				(400)
		Height				(300)
		AutoTime			(3)						自动播放时间：单位是秒
		Tween				(2)						图片过渡效果：0，表示亮度过渡，1表示透明度过渡，2表示模糊过渡，3表示运动模糊过渡
		ShowButton			(1)						是否显示按钮：1表示显示按键，0表示隐藏按键，更适合做广告挑轮换
		TitlePosition		(0)						图片名称文字位置，0表示文字在顶端，1表示文字在底部，2表示文字在顶端浮动
		LinkMode			(_blank)				打开窗口：_blank表示新窗口打开。_self表示在当前窗口打开 _blank
		TitleColor			(FFFFFF)				图片名称文字颜色
		TitleBackground		(FF6600)				图片名称文字背景颜色
		TitleAlpha			(0)						图片名称文字背景颜色透明度：0-100值，0表示全部透明
		ButtonColor			(FF6600)				按键默认的颜色
		ButtonOver			(000033)				按键当前的颜色
*/


/*
	版权所有:木炭中国[WoodCoal.CN]
	E-Mail:woodcoal@qq.com
	网址:http://www.woodcoal.cn/
*/
function FlashPicture(){
	this.ID = document.getElementById(arguments[0]);
	if(!this.ID)
	{
		this.ID = -1;
		return;
	}
	this.Width = this.Height = this.AutoTime = this.Tween = this.ShowButton = this.TitlePosition = this.TitleAlpha = 0;
	this.LinkMode = "_blank";
	this.TitleColor = this.TitleBackground = this.ButtonColor = this.ButtonOver = "";

	if(typeof arguments[1] == "number")this.Width = arguments[1];
	if(typeof arguments[2] == "number")this.Height = arguments[2];
	if(typeof arguments[3] == "number")this.AutoTime = arguments[3];
	if(typeof arguments[4] == "number")this.Tween = arguments[4];
	if(typeof arguments[5] == "number")this.ShowButton = arguments[5];
	if(typeof arguments[6] == "number")this.TitlePosition = arguments[6];

	this.LinkMode = arguments[7];
	this.TitleColor = arguments[8];
	this.TitleBackground = arguments[9];

	if(typeof arguments[10] == "number")this.TitleAlpha = arguments[10];

	this.ButtonColor = arguments[11];
	this.ButtonOver = arguments[12];

	if(arguments.length >= 2)this.Show();
}

FlashPicture.prototype.Show = function() {
	if(this.ID == -1)return;
	if (this.Width < 1) this.Width = 400;
	if (this.Height < 1) this.Height = 300;
	if (this.AutoTime < 1) this.AutoTime = 3;
	if (this.Tween < 1 || this.Tween > 3) this.Tween = 2;
	if (this.ShowButton != 1) this.ShowButton = 0;
	if (this.TitlePosition < 1) this.TitlePosition = 0;
	if (this.LinkMode != "_blank") this.LinkMode = "_blank";
	if (this.TitleAlpha < 1) this.TitleAlpha = 60;

	if (!this.TitleColor) this.TitleColor = "";
	if (!this.TitleBackground) this.TitleBackground = "";
	if (!this.ButtonColor) this.ButtonColor = "";
	if (!this.ButtonOver) this.ButtonOver = "";

	// 输出 Flash 代码
	var FlashCode = "";
	var FlashPath = "http://webpic.sgamer.com/News/ShowAdv.swf"


	FlashCode += "&AutoPlayTime=" + this.AutoTime;
	FlashCode += "&Tween=" + this.Tween;
	FlashCode += "&IsShowBtn=" + this.ShowButton;
	FlashCode += "&TitleBgPosition=" + this.TitlePosition;
	FlashCode += "&WinOpen=" + this.LinkMode;
	FlashCode += "&TitleBgAlpha=" + this.TitleAlpha;

	if (this.TitleColor != "")	FlashCode += "&TitleTextColor=0x" + this.TitleColor;
	if (this.TitleBackground != "")	FlashCode += "&TitleBgColor=0x" + this.TitleBackground;
	if (this.ButtonColor != "")	FlashCode += "&BtnDefaultColor=0x" + this.ButtonColor;
	if (this.ButtonOver != "")	FlashCode += "&BtnOverColor=0x" + this.ButtonOver;

	var imgUrl = "";
	var imgLink = "";
	var imgtext = "";

	var Obj_A = this.ID.getElementsByTagName("a");
	for (var i=0; i<Obj_A.length; i++) {
		if (i==Obj_A.length-1) {
			imgLink = imgLink + Obj_A[i].href;
		} else {
			imgLink = imgLink + Obj_A[i].href + "|";
		}
	}
	var Obj_Img = this.ID.getElementsByTagName("img");
	for (var i=0; i<Obj_Img.length; i++) {
		if (i == Obj_Img.length-1) {
			imgUrl = imgUrl + Obj_Img[i].src;
			imgtext = imgtext + Obj_Img[i].alt;
		} else {
			imgUrl = imgUrl + Obj_Img[i].src + "|" ;
			imgtext = imgtext + Obj_Img[i].alt + "|";
		}
	}

	imgUrl = escape(imgUrl);
	imgLink = escape(imgLink);
	imgtext = imgtext;

	if (imgUrl.length < 4) return

	FlashCode = "bcastr_file=" + imgUrl + "&bcastr_link=" + imgLink + "&bcastr_title=" + imgtext + FlashCode

	FlashCode = "<embed src=\"" + FlashPath + "\" width=\"" + this.Width + "\" height=\"" + this.Height + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" flashvars=\"" + FlashCode + "\" menu=\"false\" wmode=\"opaque\" bgcolor=\"#ffffff\"></embed>";
	this.ID.innerHTML = FlashCode;
	this.ID.style.display = "";
}
