// action_image.js
function ActionImage(actionBox_id){
	this.ActionBox = document.getElementById(actionBox_id);
}

ActionImage.action = null;
actionObject = ActionImage.prototype;

actionObject.width = 240; // 图片宽度
actionObject.height = 200; // 图片高度
actionObject.outTime = 6000; //图片停滞时间
actionObject.showTitle = true; // 是否显示标题
actionObject.showDescription = true; // 是否显示简介
actionObject.titleSize =20; //标题字体大小
actionObject.descriptionSize = 12; //简介字体大小
actionObject.imageAutoSize = false; // 自动按比例缩小图片尺寸适应框架大小
actionObject.length = 5;// 显示幻灯的数量
actionObject.buttonStyle = "background-color:#FFFFFF;" //按钮样式设定
actionObject.focusStyle = "background-color:red;" //选种的按钮设置
actionObject.buttonBar = "font-size:12px;" //按钮条设置
+ "text-align:right;"
+ "background-color:gray;"
+ "filter:alpha(opacity=80);"
+ "opacity:0.8;";

actionObject.imageList = new Array();
actionObject.interval = null;
actionObject.num = 0; //计数器
actionObject.ActionBox = null;

actionObject.setActionData = function(imageList){
	var id = this.imageList.length;
	this.imageList[id] = new Array()
	this.imageList[id]["image"] = new Image();
	this.imageList[id]['image'].src = imageList['imgUrl'];
	this.imageList[id]['link'] = imageList['link'];
	this.imageList[id]['title'] = imageList['title'];
	this.imageList[id]['text'] = imageList['text'];

}

actionObject.actionHTML = function(){
	var imageHTML , _button, buttonHTML , titleHTML , descriptionHTML, imageWidth, imageHeight ;

	_button = "";

	for(i=0 ; i < this.imageList.length && i < this.length; ++i){
		button_style =this.buttonStyle;
		if(i == this.num){
			button_style  = this.focusStyle;
		}
		_button += "<a style=' "
		+ "text-decoration:none;"
		+ button_style
		+ "margin-left:4px;"
		+"' href='#' onmouseover='javascript:ActionImage.action.display(" +  i +  ")' >&nbsp;" + (i+1) + "&nbsp;</a>";
	}

	image = this.imageList[this.num]['image'];
	//alert(this.imageList[this.num+1]['image'].src);
	proportion = image.width/image.height;
	if(this.imageAutoSize){
		if(proportion >= 1){
			imageWidth = this.width;
			imageHeight = Math.round(this.width/proportion);
		}
		else{
			imageWidth = Math.round(this.height*proportion);
			imageHeight = this.height;
		}
	}
	else{
		imageWidth =this.width;
		imageHeight = this.height;
	}

	//image.src  ="";
	imageHTML = "<a href='" + this.imageList[this.num]['link'] + "' target='_blank' >"
	+ "<img src='" +  image.src + "'"
	+ "style='width:" + imageWidth + "px;"
	+ "height:" + (imageHeight-16) + "px;"
	+ "border:none;"
	+ "margin:0px;"
	+  " ' /></a>";


	titleHTML = this.showTitle?"<a href='" + this.imageList[this.num]['link'] 
	+ "' target='_blank' style='"
	+ "text-align:center;"
	+ "font-size:" + this.titleSize + "px;"
	+ "font-weight:bolder;"
	+ "height:34px;"
	+ "margin-top:12px; '>"
	+ this.imageList[this.num]['title']
	+ "</a>":"";

	descriptionHTML = this.showDescription?"<div style='"
	+ "font-size:" + this.descriptionSize + "px;"
	+ "text-align:left;"
	+ "'>" + this.imageList[this.num]['text'] + "</div>":"";

	buttonHTML = "<div style='"
	+ 	"position:relative;"
	+ "left:0px;"
	+ "top:" + (-20) + "px;"
	+ "width:100%;"
	+"height:20px;"
	+ this.buttonBar
	+ "'>"
	+ _button
	+ "</div>";

	return  imageHTML + buttonHTML + titleHTML + descriptionHTML ;
}

actionObject.display = function(){
	var actionBoxHeight  = this.height;
	if(this.showTitle){
		actionBoxHeight += Math.round(this.titleSize *1.5) +12;
	}
	if(this.showDescription){
		actionBoxHeight += Math.round(this.descriptionSize*1.5 *3);
	}
	if(this.interval != null){
		clearInterval(this.interval);
	}
	else{
		this.ActionBox.style.cssText = "width:" + this.width + "px;"
		+	"height:" + actionBoxHeight  + "px;"
		+ 	"margin:4px 2px 4px 0px;"
		+	"text-align:center;"
		//+	"position:relative;"
		+ 	"overflow:hidden;";
	}
	if( this.num >= this.imageList.length || this.num >=this.length){
		this.num = 0;
	}
	if(arguments.length == 1){
		this.num = arguments[0];
	}
	var imageHTML , _button, buttonHTML , titleHTML , descriptionHTML, imageWidth, imageHeight ;


	//this.ActionBox.innerHTML = this.actionHTML();
	if(window.ActiveXObject){
		var iTransitionType;
		while(true){
			iTransitionType = Math.round(Math.random()*100);
			if(iTransitionType < 23){
				break;
			}
		}

		this.ActionBox.style.filter="RevealTrans(duration=1, transition=" + iTransitionType + ")";
		this.ActionBox.filters.item(0).apply();
		this.ActionBox.innerHTML = this.actionHTML();
		this.ActionBox.filters.item(0).play();
	}
	else{
		this.ActionBox.innerHTML = this.actionHTML();
	}
	

	++this.num;



	this.interval = setInterval('ActionImage.action.display()' , this.outTime);
}

ActionImage.createAction = function(actionBox_id){
	return ActionImage.action = new ActionImage(actionBox_id);
}


