/* @author leo ： flash_focus */
																		//图片信息数组					
/*
*插入图片信息
*/

var poco_flash_focus = new Object();
poco_flash_focus = {
	/*
	*初始构造
	*/
	initial	:	function(options)
	{
		if(typeof(options)!="object")
		{
			return false;
		}
		
		this.options = {
			"title_extend"	:	options.title_extend		?		options.title_extend:	false,
			"img_info"		:	options.img_info			?		options.img_info	:	[],
			"show_index"	:	options.show_index			?		options.show_index	:	-1,
			"obj_width"		:	options.obj_width			?		options.obj_width	:	280,
			"obj_height"	:	options.obj_height			?		options.obj_height	:	210,
			"imgs_num"		:	options.imgs_num			?		options.imgs_num	:	options.img_info.length,
			"handler"		:	options.handler				?		options.handler		:	null,
			"handler_arr"	:	options.handler_arr			?		options.handler_arr	:	Array(),
			"time"			:	options.time				?		options.time		:	5000,
			"btn_head"		:	options.btn_head			?		options.btn_head	:	"http://www.poco.cn/pic/flash_btn",
			"btn_pre"		:	options.btn_pre				?		options.btn_pre		:	"http://www.poco.cn/pic/flash_back.gif",
			"btn_next"		:	options.btn_next			?		options.btn_next	:	"http://www.poco.cn//pic/flash_next.gif",
			"link_color"	:	options.link_color			?		options.link_color	:	"#6BBD31",
			"btn_clolor"	:	options.btn_clolor			?		options.btn_clolor	:	"#6BBD31",
			"btn_width"		:	options.btn_width			?		options.btn_width	:	12,
			"btn_height"	:	options.btn_height			?		options.btn_height	:	11
		};

		this.write_focus_block();
	},

    $ : function(e)
	{
		return typeof(e) == 'object' ? e : document.getElementById(e);
	},

	write_focus_block	:	function(){																		//写入焦点图框架层及样式
		document.write("<style>");

		document.write("#flash_img_244 {position:absolute;left:0px; height: "+(this.options.obj_height+1)+"px;");
		document.write("}#flash_img_244 IMG { WIDTH: "+this.options.obj_width+"px; HEIGHT: "+this.options.obj_height+"px;top:0px;left:0px;");
		document.write("}#flash_img_244 a{ position:absolute;");
		document.write("}#flash_show_control_244 {OVERFLOW: hidden; height:20px;width:"+this.options.obj_width+"px text-align:center; background-color:#E1E1E1; padding:3px; filter:progid:DXImageTransform.Microsoft.gradient(startcolorstr=#FCFCFC,endcolorstr=#DFDFDF,gradientType=1)");
		document.write("}#flash_show_ctl_msg_244 { FILTER: progid:DXImageTransform.Microsoft.Fade(Overlap=1.00); FLOAT: left;padding-right:5px;text-align:left;width:"+this.options.obj_width+"px");
		document.write("}#flash_btn_244 { FILTER: alpha(opacity=50); BACKGROUND-COLOR: #fff; text-align:right; height:12px; padding-left:220px; margin-top:3px; filter:progid:DXImageTransform.Microsoft.gradient(startcolorstr=#424F95,endcolorstr=#F6F9F2,gradientType=1)");
		document.write("}#flash_content_244 { position:absolute;left:0px;bottom:0px;width:"+this.options.obj_width+"px;overflow:hidden");
		document.write("}#flash_btn_244 DIV {MARGIN: 0px 0px 0px 8px; float:left}");
		document.write("}</style>");

		document.write('<div style="width:auto;height:240px; POSITION: relative;">')
		document.write('<div id="flash_img_244"></div>');
		document.write('<div id="flash_content_244">');
		document.write('<div id="flash_show_control_244">');
		document.write('<div id="flash_show_ctl_msg_244" style="float:left;">');
		document.write('<a href="#" id="flash_title_244"></a>');
		document.write('</div>');
		document.write('</div>');
		document.write('<div id="flash_btn_244">');
		
		for(var num=0;num<this.options.imgs_num;num++)
		{
			pic_num = num+1;
			document.write("<div><img onclick='javascript:poco_flash_focus.show_img("+num+",true)' src='"+this.options.btn_head+"_"+pic_num+".gif' style='cursor:pointer;'  alt='' width='"+this.options.btn_width+"' height='"+this.options.btn_height+"' border='0' /></div>");
		}

		document.write("</div>");
		document.write("</div>");
		document.write('</div>');
		//if(!this.options.title_extend)	document.getElementById("flash_show_control_244").style.display = "none";

		this.show_img(this.options.show_index+1);
	},

	set_opacity			:	function( el , opacity ){														//设置图片的透明度
		if (opacity <= 0)
		{
			el.style.visibility != "hidden"  && ( el.style.visibility = "hidden" );
		} 
		else 
		{
			el.style.visibility != "visible" && ( el.style.visibility = "visible" ) ;
		}
		
		(!el.currentStyle || !el.currentStyle.hasLayout) && ( el.style.zoom = 1);
		window.ActiveXObject && ( el.style.filter = (opacity == 1) ? '' : "alpha(opacity=" + opacity * 100 + ")" ) ;
		el.style.opacity = opacity;
	},

	show_img			:	function(imageIndex,clear){														//显示图片
		if(imageIndex==this.options.show_index)																//点击当前索引返回false
		{
			return false;
		}
		if(clear)																							//点击图片按钮序号清除句柄
		{
			clearInterval(this.options.handler_arr[this.options.show_index]);
			clearTimeout(this.options.handler);
		}
		var flash_img_div = this.$("flash_img_244");													//包含图片div元素
		var flash_title = this.$("flash_title_244");													//包含标题内容div元素

		if(imageIndex>this.options.imgs_num-1)
		{
			imageIndex = 0;																					//序号上超出图片数,重置序号为0
		}
		if(imageIndex<0)
		{
			imageIndex = this.options.imgs_num-1;															//序号下低出0,置序号为最大
		}

		var img_id =  "img_"+imageIndex;																	//选择当前图片的ID
		var pre_img_id = "img_"+this.options.show_index ;													//当前图片之前的ID

		if(!this.options.img_info) return false;															//无图片，返回false

		if(this.$(img_id)&&this.$(pre_img_id))																//存在元素，执行滤镜效果
		{
			if(imageIndex!==this.options.show_index)				
			this.opaque_play(this.$(img_id),this.$(pre_img_id),imageIndex);
		}
		else																								//无指定ID元素则创建元素																
		{
			var img = new Image();
			img.border = "0";
			img.src = this.options.img_info[imageIndex].img;
			var a = document.createElement("a");
			a.href = this.options.img_info[imageIndex].href;
			a.target = "_blank";
			a.appendChild(img);
			a.id = img_id;
			pre_node = flash_img_div.lastChild;
			flash_img_div.appendChild(a,pre_node);
			this.opaque_play(a,pre_node,imageIndex);														//执行滤镜效果
		}
		flash_title.href =this.options.img_info[imageIndex].href;
		flash_title.target = "_blank";
		flash_title.innerHTML =this.options.img_info[imageIndex].title;
		this.options.show_index = imageIndex;
		this.options.handler = setTimeout("poco_flash_focus.show_img(poco_flash_focus.options.show_index+1)",this.options.time);
	},
	pre_pic		:	function()																				//前一个图片
	{
		clearInterval(this.options.handler_arr[this.options.show_index]);
		clearTimeout(this.options.handler);
		this.show_img(this.options.show_index-1);
	},

	next_pic	:	function()																				//后一个图片
	{
		clearInterval(this.options.handler_arr[this.options.show_index]);
		clearTimeout(this.options.handler);
		this.show_img(this.options.show_index+1);
	},
	opaque_play		:	function(el,pre_node,index)															//滤镜效果
	{
		var opaque = 0;
		for(var i=0;i<this.options.imgs_num;i++)
		{
			if(this.$("img_"+i)) this.$("img_"+i).style.zIndex = 0;											//全部图层置0
		}
		if(pre_node) pre_node.style.zIndex = 998;															//设置当前图层上一个图片层
		el.style.zIndex	=	999;
		this.set_opacity(el,opaque);																		//设置当前图片层最顶层
		this.options.handler_arr[index] = setInterval(function(){
		opaque=opaque+0.1;
		if(opaque>1)
		{
			clearInterval(poco_flash_focus.options.handler_arr[index]);
		}
		poco_flash_focus.set_opacity(el,opaque);

		}
		,90)
	}
};
