var qcomic_body_w = 0; //width
var qcomic_body_h = 0; //height
var qcomic_body_t = 0; //top
var qcomic_body_l = 0; //left
jQuery(document.body).ready(function(){
	qcomic_utils.debug('enter','document ready');
	qcomic_body_w = jQuery('body').width();
	qcomic_body_h = jQuery('body').height();
	//qcomic_utils.debug('body='+jQuery('body')+',$(body).width()='+jQuery('body').width()+',$(body).height()='+jQuery('body').height(),'document ready');
});

function QComicOutput()
{
	var _browser = '';
	var _js_cache = new Object(); //数据缓存
	var _js_config = new Object(); //配置缓存
	var _js_relate = new Object(); //相关缓存
	var _flash_cache = '';

	function init(params)
	{
		qcomic_utils.debug('enter','init');
		qcomic_utils.debug(params,'init');

		var idx = params[2];
		setConfig({'idx':idx,'data':params[0]});
		setDisplayData({'idx':idx,'data':params[1]});
		initPage({'idx':idx});
	}

	/**
	 * 设置配置数据
	 */
	function setConfig(params)
	{
		qcomic_utils.debug('enter','setConfig');

		/* debug */
		qcomic_utils.debug(params['data'],'setConfig');

		/* assign */
		if( !_js_config[params['idx']] )
		{
			_js_config[params['idx']] = params['data'];
		}
	};

	/**
	 * 设置显示数据
	 */ 
	function setDisplayData(params)
	{
		qcomic_utils.debug('enter','setDisplayData');

		/* debug */
		qcomic_utils.debug(params['data'],'setDisplayData');
		//qcomic_utils.debug(params['data']['data'][0],'setDisplayData');

		/* assign */
		if( !_js_cache[params['idx']] )
		{
			_js_cache[params['idx']] = params['data'];
		}
	};

	/**
	 * 初始化页面
	 */
	function initPage(params)
	{
		qcomic_utils.debug('enter','initPage');

		var idx = params['idx'];
		var pos = _js_config[idx]['pos'] ? _js_config[idx]['pos'] : 1;
		var view_id = 0;
		if( pos == 1 )
			view_id = 'qcomic_view_'+idx+'_before';
		else
			view_id = 'qcomic_view_'+idx+'_after';

		/* ubb */
		var ubb_container_id = 'qcomic_ubb_'+idx;
		if( jQuery('#'+ubb_container_id).length == 0 )
			jQuery('#'+view_id).append('<div id="'+ubb_container_id+'" style="padding:0px;margin:0px;font-size:12px;text-align:left;"></div>');

		/* slide */
		var slide_container_id = 'qcomic_slide_'+idx;
		if( jQuery('#'+slide_container_id).length == 0 )
			jQuery('#'+view_id).append('<div id="'+slide_container_id+'" style="padding:0px;margin:0px;font-size:12px;text-align:left;"></div>');

		/* thread */
		var thread_container_id = 'qcomic_thread_'+idx;
		if( jQuery('#'+thread_container_id).length == 0 )
			jQuery('#'+view_id).append('<div id="'+thread_container_id+'" style="padding:0px;margin:0px;font-size:12px;text-align:left;clear:both;"></div>');

		/* relate */
		var relate_container_id = 'qcomic_relate_'+idx;
		if( jQuery('#'+relate_container_id).length == 0 )
			jQuery('#'+view_id).append('<div id="'+relate_container_id+'" style="padding:0px;margin:0px;font-size:12px;text-align:left;"></div>');
	}

	/**
	 * 隐藏：幻灯、平铺、UBB
	 */
	function hiddenPage(params)
	{
		var idx = params['idx'];
		var type = params['type'];

		/* ubb */
		if( type == 'ubb' || type == 'all' )
		{
			jQuery('#qcomic_ubb_'+idx).css('display','none');
		}

		/* slide */
		if( type == 'slide' || type == 'all' )
		{
			jQuery('#qcomic_slide_'+idx).css('display','none');
		}

		/* thread */
		if( type == 'thread' || type == 'all' )
		{
			jQuery('#qcomic_thread_'+idx).css('display','none');
		}

		/* relate */
		if( type == 'relate' || type == 'all' )
		{
			jQuery('#qcomic_relate_'+idx).css('display','none');
		}
	};

	/**
	 * 显示幻灯
	 */
	function displaySlide(params)
	{
		qcomic_utils.debug('enter','displaySlide');

		//
		var idx = params['idx'];

		//
		hiddenPage({'idx':idx,'type':'all'});

		/* conf */
		var auto	= _js_config[idx]['auto'] ? _js_config[idx]['auto'] : 0;
		var ipos	= _js_config[idx]['ipos'] ? _js_config[idx]['ipos'] : 0;
		var level	= _js_config[idx]['level'] ? _js_config[idx]['level'] : 0;
		var fwidth	= _js_config[idx]['fwidth'] ? _js_config[idx]['fwidth'] : 700;
		var fheight = _js_config[idx]['fheight'] ? _js_config[idx]['fheight'] : 550;

		/* data */
		var sid 	= _js_cache[idx]['sid'];
		var code 	= _js_cache[idx]['code'];
		var code	= qcomic_utils.replaceCode(code);

		/* slide container */
		if( !jQuery('#qcomic_slide_'+idx).html() )
		{
			/* assign flashVars */
			var flash_vars = 'sid='+sid;
			flash_vars+= '&code='+code;
			flash_vars+= '&auto='+auto;
			flash_vars+= '&idx='+idx;
			flash_vars+= '&ipos='+ipos;
			flash_vars+= '&ver=dz_2';
			qcomic_utils.debug('flash_vars='+flash_vars,'displaySlide');

			/* assign html */
			var flash_url = 'http://p.qihoo.com/flash/pic_slide.swf';
			flashTagIns.setNew(flash_url,fwidth,fheight);
			flashTagIns.setVersion('7,0,19,0');
			flashTagIns.setId('qcomic_slide_flash_'+idx);
			flashTagIns.wmode = null;
			flashTagIns.flashVars = flash_vars;
			flashTagIns.swLiveConnect = 'true';
			flashTagIns.allowFullScreen = 'true';
			flashTagIns.allowScriptAccess = 'always';
			qcomic_utils.debug('flashTagIns='+flashTagIns.toString(),'displaySlide');

			jQuery('#qcomic_slide_'+idx).html(flashTagIns.toString());
		}
		jQuery('#qcomic_slide_'+idx).css('display','');

		/* jump to ipos */
		if( ipos )
		{
			var flash_id = 'qcomic_slide_flash_'+idx;
			var flash_obj = qcomic_utils.getFlashObj({'id':flash_id});
			qcomic_utils.debug('flash_id='+flash_id+',flash_obj='+flash_obj);
			if( typeof(flash_obj.dataToSlide) != 'undefined' )
			{
				flash_obj.dataToSlide({'ipos':ipos,'auto':auto});
			}
		}
	};

	/**
	 * 停止幻灯播放
	 */
	function stopSlide(params)
	{
		var idx = params['idx'];
		var flash_id = 'qcomic_slide_flash_'+idx;
		var flash_obj = qcomic_utils.getFlashObj({'id':flash_id});
		qcomic_utils.debug('flash_id='+flash_id+',flash_obj='+flash_obj,'stopSlide');
		if( flash_obj )
		{
			if( typeof(flash_obj.isAutoPlay) != 'undefined' )
			{
				flash_obj.isAutoPlay({'auto':0});
			}
		}
	};

	/**
	 * 显示平铺
	 */
	function displayThread(params)
	{
		qcomic_utils.debug('enter','displayThread');

		//
		var idx = params['idx'];
		var start = params['start'] ? params['start'] : 0;
		qcomic_utils.debug('idx='+idx+',start='+start,'displayThread');

		//
		_js_config[idx]['start'] = start;

		//
		hiddenPage({'idx':idx,'type':'all'});
		stopSlide({'idx':idx});

		/* conf */
		var flag 		= _js_config[idx]['flag']; //
		var width 		= _js_config[idx]['width']; //图片宽
		var height 		= _js_config[idx]['height']; //图片高
		var istyle		= _js_config[idx]['istyle']; //图片显示：大中小
		var maxnum		= _js_config[idx]['maxnum']; //每次加载图片数
		var nav_width	= _js_config[idx]['nav_width']; //导航宽度
		var percent		= _js_config[idx]['percent']; //图片按照导航宽度开关
		if( percent == 1 ) width = nav_width;

		/* data */
		var sid 		= _js_cache[idx]['sid'];
		var sname 		= _js_cache[idx]['sname'];
		var surl 		= _js_cache[idx]['surl'];
		var gid 		= _js_cache[idx]['gid'];
		var code 		= _js_cache[idx]['code'];
		var data 		= _js_cache[idx]['data'];

		/* type */
		switch( istyle )
		{
			case 1:
			case 's': //small
				istyle = 's';
				break;
			case 2:
			case 'm': //middle
				istyle = 'm';
				break;
			case 3:
			case 'b': //big
				istyle = 'b';
				break;
			case 'a': //自动选择
				if( data.length <= 10 )
					istyle = 'b';
				else
					istyle = 'm';
				break;
			default:
				istyle = 'b';
				break;
		}

		//[图片列表]+[更多图片]结构
		var ilist_id = 'qcomic_thread_ilist_'+idx;
		if( !jQuery('#qcomic_thread_'+idx).html() )
		{
			jQuery('#qcomic_thread_'+idx).append('<div id="'+ilist_id+'" style="padding:3px;"></div>');
			jQuery('#qcomic_thread_'+idx).append('<div style="clear:both;"></div>');

			var ilist_more_id = 'ilist_img_'+idx+'_more';
			jQuery('#qcomic_thread_'+idx).append('<div id="'+ilist_more_id+'" style="cursor:pointer;"></div>');
			jQuery('#'+ilist_more_id).click(function(e){
				var id_arr = this.id.split('_');
				var idx = id_arr[2]+'_'+id_arr[3]+'_'+id_arr[4];
				var start = _js_config[idx]['start'];
				var maxnum = _js_config[idx]['maxnum'];
				if( start+maxnum >= _js_cache[idx]['data'].length ) return;
				displayThread({'idx':idx,'start':start+maxnum,'more':1});
			});
		}

		//修改[更多图片]文字
		if( jQuery('#ilist_img_'+idx+'_more').length > 0 )
		{
			var loadnum = start + maxnum;
			loadnum = (loadnum>data.length) ? data.length : loadnum;

			var html = '';
			html+= '共'+data.length+'张，显示'+parseInt(loadnum)+'张';
			if( loadnum < data.length )
				html+= '，查看更多>>';
			jQuery('#ilist_img_'+idx+'_more').html(html);
		}

		var html = '';
		/* thread datas container */
		for( var i=start;i<start+maxnum;i++ )
		{
			if( !data[i] ) continue;
			qcomic_utils.debug(data[i],'displayThread');
			var active	= data[i]['active'];
			var surl 	= data[i]['surl'];
			var surl_w 	= data[i]['surl_w'];
			var surl_h 	= data[i]['surl_h'];
			var murl 	= data[i]['murl'];
			var murl_w 	= data[i]['murl_w'];
			var murl_h 	= data[i]['murl_h'];
			var burl 	= data[i]['burl'];
			var burl_w 	= data[i]['burl_w'];
			var burl_h 	= data[i]['burl_h'];
			var rurl 	= data[i]['rurl'];
			var rurl_w 	= data[i]['rurl_w'];
			var rurl_h 	= data[i]['rurl_h'];
			var qurl	= data[i]['qurl'];
			var qurl_w 	= data[i]['qurl_w'];
			var qurl_h 	= data[i]['qurl_h'];
			var desc 	= data[i]['desc'];

			var d_url,d_width,d_height,d_border_width,d_border_height;
			if( istyle == 's' )
			{
				d_url = surl;
				d_width = surl_w;
				d_height = surl_h;
				d_border_width = '80';
				d_border_height = '80';
			}
			else if( istyle == 'm' )
			{
				d_url = murl ? murl : burl;
				d_width = murl_w ? murl_w : '200';
				d_height = murl_h ? murl_h : '200';
				d_border_width = '200';
				d_border_height = '200';
			}
			else if( istyle == 'b' )
			{
				if( active == 1 )
				{
					d_url = qurl.replace(/yp.qihoo.com/,'gp.qihoo.com');
					d_width = qurl_w;
					d_height = qurl_h;
				}
				else
				{
					d_url = burl;
					d_width = burl_w;
					d_height = burl_h;
				}

				if( d_width=='' || d_height=='' )
				{
					d_width = width;
					d_height = height;
				}
				else
				{
					var __width = parseInt(d_width);
					var __height = parseInt(d_height);
					if( __width > width )
					{
						d_height = Math.ceil(__height/(__width/width));
						d_width = width;
						qcomic_utils.debug('__width > width','displayThread');
					}
					else if( __height > height )
					{
						d_width = Math.ceil(__width/(__height/height));
						d_height = height;
						qcomic_utils.debug('__height > height','displayThread');
					}
					qcomic_utils.debug('before,d_width='+__width+',d_height='+__height+';after,d_width='+d_width+',d_height='+d_height,'displayThread');
				}

				d_border_width = 0;
				d_border_height = 0;
			}

			if( d_width!='' && d_height!='' )
			{
				//div start
				html+= '<div style="';
				if( d_border_width ) html+= 'width:'+d_border_width+'px;';
				if( d_border_height ) html+= 'height:'+d_border_height+'px;';
				html+= 'float:left;margin:4px;text-align:center;">';

				/* 图片 */
				html+= '<div style="position:relative;">';
					//menu
					html+= '<div id="ilist_menu_'+idx+'_'+i+'" style="position:absolute;top:0px;right:0px;font-size:12px;background:#ffffff;color:#000000;text-align:right;"></div>';
					//img
					html+= '<img id="'+'ilist_img_'+idx+'_'+i+'" title="点击鼠标左键查看原图" src="'+d_url+'"';
					if( d_width ) html+= ' width="'+d_width+'"';
					if( d_height ) html+= ' height="'+d_height+'"';
					html+= ' style="cursor:pointer;" />';
				html+= '</div>';

				/* 描述 */
				if( istyle=='b' && desc )
				{
					html+= '<p style="text-align:left;font-size:14px;line-height:18px;">'+desc+'</p>';
				}

				//div end
				html+= '</div>';

				//大图时，每张图片一行
				if( istyle == 'b' )
				{
					html+= '<div style="clear:both;"></div>';
				}
			}

			//if( i >= maxnum-1 ) break;
		}
		if( params['more'] ) jQuery('#'+ilist_id).append(html);
		else jQuery('#'+ilist_id).html(html);
		jQuery('#qcomic_thread_'+idx).css('display','');

		//绑定图片事件
		for( var i=start;i<start+maxnum;i++ )
		{
			var img_id = 'ilist_img_'+idx+'_'+i;
			if( jQuery('#'+img_id).length > 0 )
			{
				jQuery('#'+img_id)
				.click(function(e){
					var id_arr = this.id.split('_');
					var idx = id_arr[2]+'_'+id_arr[3]+'_'+id_arr[4];
					var img_id = id_arr[5];
					qcomic_utils.debug('id='+this.id+',idx='+idx+',img_id='+img_id,'click img');

					var img_data = _js_cache[idx]['data'][img_id];
					//openUrl({'idx':idx,'url':img_data['rurl'],'img_id':img_id});
					showFloatImg({'idx':idx,'img_id':img_id});
				})
				.mouseover(function(e){
					var id_arr = this.id.split('_');
					var idx = id_arr[2]+'_'+id_arr[3]+'_'+id_arr[4];
					var img_id = id_arr[5];
					//qcomic_utils.debug('id='+this.id+',idx='+idx+',img_id='+img_id,'mouseover img');
					//showImgMenu({'show':1,'idx':idx,'img_id':img_id});
				})
				if( typeof(jQuery('#'+img_id)[0].attachEvent) != 'undefined' )
				{
					//屏蔽鼠标右键
					jQuery('#'+img_id)[0].attachEvent('oncontextmenu',function(e){
						e.cancelBubble = true;
						e.returnValue = false;
						return false;
					});
				}
			}

			var menu_id = 'ilist_menu_'+idx+'_'+i;
			if( jQuery('#'+menu_id).length > 0 )
			{
				jQuery('#'+menu_id)
				.mouseout(function(e){
					var id_arr = this.id.split('_');
					var idx = id_arr[2]+'_'+id_arr[3]+'_'+id_arr[4];
					var img_id = id_arr[5];
					//qcomic_utils.debug('id='+this.id+',idx='+idx+',img_id='+img_id,'mouseover menu');
					showImgMenu({'show':0,'idx':idx,'img_id':img_id});
				});
			}
		}
	};

	function displayUBB(params)
	{
		qcomic_utils.debug('enter','displayUBB');

		//
		var idx = params['idx'];

		//
		hiddenPage({'idx':idx,'type':'all'});
		stopSlide({'idx':idx});

		/* data */
		var sid 	= _js_cache[idx]['sid'];
		var surl	= _js_cache[idx]['surl'];
		var code 	= _js_cache[idx]['code'];
		var code	= qcomic_utils.replaceCode(code);
		var proxy	= _js_cache[idx]['proxy'];

		var flash_vars = 'sid='+sid+'&code='+code+'&local=0&auto=1';
		var flash_url = 'http://p.qihoo.com/flash/pic_slide.swf?'+flash_vars;
		var url = surl+'/'+proxy+'?action=proxy&sid='+sid+'&code='+code+'&url='+escape(flash_url);
		var width = 430;
		var height = 320;
		var site = {
			'blog.163.com':{
				'name':'网易博客',
				'code':'<EMBED src="'+url+'" width="'+width+'" height="'+height+'" allowScriptAccess="true" allowFullScreen="true" type="application/x-shockwave-flash"></EMBED>'
			},
			'blog.sina.com':{
				'name':'新浪博客',
				'code':'<EMBED src="'+url+'" width="'+width+'" height="'+height+'" allowScriptAccess="true" allowFullScreen="true" type="application/x-shockwave-flash"></EMBED>'
			},
			'blog.sohu.com':{
				'name':'搜狐博客',
				'code':'<EMBED src="'+flash_url+'" width="'+width+'" height="'+height+'" allowScriptAccess="true" allowFullScreen="true" type="application/x-shockwave-flash"></EMBED>'
			},
			'qzone.qq.com':{
				'name':'QQ空间',
				'code':'[flash,'+width+','+height+']'+url+'[/flash]'
			},
			'blog.tianya.cn':{
				'name':'天涯博客',
				'code':'<EMBED src="'+url+'" width="'+width+'" height="'+height+'" allowScriptAccess="true" allowFullScreen="true" type="application/x-shockwave-flash"></EMBED>'
			},
			'blog.hexun.com':{
				'name':'和讯博客',
				'code':'<EMBED src="'+url+'" width="'+width+'" height="'+height+'" allowScriptAccess="true" allowFullScreen="true" type="application/x-shockwave-flash"></EMBED>'
			},
			'bbs':{
				'name':'论坛代码',
				'code':'[pp=pic_slide,'+width+','+height+',0]'+flash_vars+'[/pp]'
			}
		};

		var html = '';
		if( !jQuery('#qcomic_ubb_'+idx).html() )
		{
			html+= '<div style="color:#ff0000;">把下面的代码复制到你的博客或个人空间，就可以把这组幻灯嵌到你的博客上。</div>';
			html+= '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
			var site_url;
			for( site_url in site )
			{
				var site_id = 'qcomic_ubb_'+idx+'_'+site_url.replace(/\./g,'_');
				html+= '<tr>';
					html+= '<td width="150" style="margin:0;padding:5px;border:none;font-size:14px;vertical-align:top;">'+site[site_url]['name']+'<br>'+site_url+'</td>';
					html+= '<td style="margin:0;padding:5px;border:none;font-size:14px;vertical-align:top;">';
						html+= '<textarea id="'+site_id+'" style="border:solid #999;border-width:1px;width:400px;height:30px;color:#666;font-size:12px;margin:0;background:#FFC;overflow:hidden;"">'+site[site_url]['code']+'</textarea>';
					html+= '</td>';
				html+= '</tr>';
			}
			html+= '</table>';
			qcomic_utils.debug('html[length]='+html.length,'displayUBB');
			jQuery('#qcomic_ubb_'+idx).html(html);
			//bind event
			for( site_url in site )
			{
				var site_id = 'qcomic_ubb_'+idx+'_'+site_url.replace(/\./g,'_');
				jQuery('#'+site_id).click(function(){
					if( jQuery.browser.msie )
					{
						qcomic_utils.copyToClip(this);
						alert('代码已复制到粘贴板');
					}
					jQuery(this).select();
				});
			}
		}
		jQuery('#qcomic_ubb_'+idx).css('display','');
	};

	/**
	 * 相关组图
	 */
	function displayRelate(params)
	{
		qcomic_utils.debug('enter','displayRelate');

		//
		//hiddenPage({'idx':idx,'type':'all'});
		stopSlide({'idx':idx});

		//
		var idx	= params['idx'];
		if( !_js_relate[idx] )
		{
			_js_relate[idx] = params['data'];
		}

		//kw
		_js_config['kw'] = params['kw'].split(' ');
		//phid
		var phid_t	= params['phid'].split('_');
		var phid	= phid_t[0];
		_js_config['phid'] = phid;
		//relate
		_js_config['relate'] = params['relate'];

		/* data */
		var sid			= _js_cache[idx]['sid'];
		var kw_arr		= _js_config[idx]['kw'];
		var phid		= _js_config[idx]['phid'];
		var level		= _js_config[idx]['level'];
		var relate		= _js_config[idx]['relate'];
		var data 		= _js_relate[idx];

		if( level > 1 ) return;
		else if( relate == -1 ) return;
		else if( data.length == 0 ) return;

		var html = '';
		/* nav */
		html+= '<div style="margin:4px 0px 0px 0px;">相关组图：';
		for( var i=0;i<kw_arr.length;i++ )
		{
			html+= '<a href="http://www.xkoo.com/index.php?uid='+sid+'&title='+(kw_arr[i])+'&isSubmit=true&a=search" target="_blank"><b style="margin:4px 0px 0px 4px;">'+kw_arr[i]+'</b></a> ';
		}
		html+= '</div>';
		/* thumb image */
		var rnd = Math.random() * _data.length;
		rnd = Math.ceil(rnd);
		html+= '<div>';
		for( var i=0;i<_data.length;i++ )
		{
			surl 	= _data[i]['surl'];
			title 	= _data[i]['title'];
			phid 	= _data[i]['phid'];
			turl	= (i == rnd-1) ? 'http://www.xkoo.com/index.php?uid='+sid+'&phid='+phid+'&isSubmit=true&a=search' : _data[i]['turl'];
			qcomic_utils.debug('surl='+surl+',title='+title+',phid='+phid+',turl='+turl);
			if( phid == cur_phid ) continue;
			html+= '<a href="'+turl+'" target="_blank"><img src="'+surl+'" alt="'+title+'" title="'+title+'" style="border:1px solid #686A6B;margin:4px;" /></a>';
		}
		html+= '</div>';
		jQuery('#qcomic_relate_'+idx).html(html);
		jQuery('#qcomic_relate_'+idx).css('display','');
	};

	//显示原图弹出层
	function showFloatImg(params)
	{
		//
		var idx = params['idx'];
		var show = params['show'];
		var img_id = params['img_id'];
		var img_data = _js_cache[idx]['data'][img_id];
		qcomic_utils.debug(img_data,'showFloatImg');

		//
		if( show == 0 )
		{
			jQuery('#ilist_float_mask').remove();
			jQuery('#ilist_float_img').remove();
			return;
		}

		//计算遮罩和浮动图片的位置和宽高
		var body_w = 0;
		var body_h = 0;
		if( jQuery.browser.mozilla )
		{
			body_w = document.body.clientWidth;
			body_h = document.body.clientHeight;
		}
		else if( jQuery.browser.msie )
		{
			body_w = document.body.scrollWidth;
			body_h = document.body.scrollHeight;
		}
		//alert(body_w+','+body_h);
		qcomic_utils.debug('body_w='+body_w+',body_h='+body_h,'showFloatImg');

		//top and left
		var float_top = qcomic_utils.getScrollTop();
		var float_left = 0;
		if( body_w > img_data['rurl_w'] )
		{
			float_left = (body_w - img_data['rurl_w']) / 2;
		}
		//alert(float_top+','+float_left);
		qcomic_utils.debug('float_top='+float_top+',float_left='+float_left,'showFloatImg');

		//
		if( jQuery('#ilist_float_mask').length == 0 )
		{
			qcomic_utils.debug('body_w='+body_w+',body_h='+body_h,'showFloatImg');
			qcomic_utils.debug('rurl_w='+img_data['rurl_w']+',rurl_h='+img_data['rurl_h'],'showFloatImg');

			var html = '';
			if( body_h > 1500 )
			{
				body_h = 1500;
				html+= '<div id="ilist_float_mask" style="z-index:100;position:absolute;top:'+float_top+'px;left:0px;width:'+body_w+'px;height:'+body_h+'px;background:#000000;filter:alpha(opacity=80);opacity:0.8;" />';
			}
			else
			{
				html+= '<div id="ilist_float_mask" style="z-index:100;position:absolute;top:0px;left:0px;width:'+body_w+'px;height:'+body_h+'px;background:#000000;filter:alpha(opacity=80);opacity:0.8;" />';
			}
			jQuery('#qcomic_thread_'+idx).append(html);
		}

		//
		if( jQuery('#ilist_float_img').length == 0 )
		{
			var html = '';
			html+= '<div id="ilist_float_img" style="z-index:100;position:absolute;top:'+float_top+'px;left:'+float_left+'px;width:'+img_data['rurl_w']+'px;height:'+(parseInt(img_data['rurl_h'])+20)+'px;background:#F7FBFE;padding:5px;"></div>';
			jQuery('#qcomic_thread_'+idx).append(html);
			//浮动层事件
			if( typeof(jQuery('#ilist_float_img')[0].attachEvent) != 'undefined' )
			{
				//屏蔽鼠标右键
				jQuery('#ilist_float_img')[0].attachEvent('oncontextmenu',function(e){
					e.cancelBubble = true;
					e.returnValue = false;
					return false;
				});
			}

			var html = '';
			html+= '<div style="padding:0px;font-size:12px;line-height:14px;background:#ffffff;">';
				html+= '&nbsp;<img id="ilist_float_img_close" src="http://img.qihoo.com/images/2008/gpic/o_close.gif" style="cursor:pointer;" title="关闭" />';
				//html+= '&nbsp;<img id="ilist_float_img_save" src="http://img.qihoo.com/images/2008/gpic/o_save.gif" style="cursor:pointer;" title="下载" />';
				html+= '&nbsp;<img id="ilist_float_img_new" src="http://img.qihoo.com/images/2008/gpic/o_new.gif" style="cursor:pointer;" title="在新窗口打开" />';
				html+= '&nbsp;<img id="ilist_float_img_link" src="http://img.qihoo.com/images/2008/gpic/ico/quoto.gif" style="cursor:pointer;" title="复制外链图片地址" />';
				html+= '&nbsp;&nbsp;&nbsp;&nbsp;';
				html+= '&nbsp;<img id="ilist_float_img_left" src="http://img.qihoo.com/images/2008/gpic/ico/left.gif" style="cursor:pointer;" title="查看上一张原图" />';
				html+= '&nbsp;<img id="ilist_float_img_right" src="http://img.qihoo.com/images/2008/gpic/ico/right.gif" style="cursor:pointer;" title="查看下一张原图" />';
			html+= '</div>';
			jQuery('#ilist_float_img').append(html);
			//功能按钮事件
			jQuery('#ilist_float_img_close').click(function(e){
				showFloatImg({'show':0,'idx':idx,'img_id':img_id});
			});
			jQuery('#ilist_float_img_save').click(function(e){
				var img_data = _js_cache[idx]['data'][img_id];
				saveImg({'idx':idx,'url':img_data['rurl']});
			});
			jQuery('#ilist_float_img_new').click(function(e){
				var img_data = _js_cache[idx]['data'][img_id];
				openUrl({'idx':idx,'url':img_data['rurl'],'img_id':img_id});
			});
			jQuery('#ilist_float_img_link').click(function(e){
				var img_data = _js_cache[idx]['data'][img_id];
				if( jQuery.browser.mozilla )
					openUrl({'idx':idx,'url':img_data['lurl'],'img_id':img_id});
				else
					copyUrl({'idx':idx,'url':img_data['lurl'],'img_id':img_id});
			});
			jQuery('#ilist_float_img_left').click(function(e){
				if( img_id <= 0 ) return;
				jQuery('#ilist_float_img').remove();
				var prev_img_id = parseInt(img_id) - 1;
				qcomic_utils.debug('prev_img_id='+prev_img_id,'float img:click left');
				var img_data = _js_cache[idx]['data'][prev_img_id];
				showFloatImg({'idx':idx,'img_id':prev_img_id});
			});
			jQuery('#ilist_float_img_right').click(function(e){
				if( img_id >= _js_cache[idx]['data'].length-1 ) return;
				jQuery('#ilist_float_img').remove();
				var next_img_id = parseInt(img_id) + 1;
				qcomic_utils.debug('next_img_id='+next_img_id,'float img:click right');
				var img_data = _js_cache[idx]['data'][next_img_id];
				showFloatImg({'idx':idx,'img_id':next_img_id});
			});
		}

		//
		if( jQuery('#ilist_float_img').length > 0 )
		{
			var rurl = img_data['rurl'];
			rurl = rurl.replace(/yp.qihoo.com/,'gp.qihoo.com');

			var html = '';
			html+= '<div id="ilist_float_img_instance" style="text-align:center;"><img src="'+rurl+'" title="点击图片关闭浮动层" /></div>';
			jQuery('#ilist_float_img').append(html);

			//图片实例事件
			jQuery('#ilist_float_img_instance').click(function(e){
				showFloatImg({'show':0,'idx':idx,'img_id':img_id});
			});
		}
	}

	/* 下载原图 */
	function saveImg(params)
	{
		qcomic_utils.debug('enter','saveImg');
		var idx = params['idx'];
		var url = params['url'];

		if( idx )
		{
			var flash_id = 'qcomic_flash_' + idx;
			var flash_obj = qcomic_utils.getFlashObj({'id':flash_id});
			qcomic_utils.debug('flash_id='+flash_id+',flash_obj='+flash_obj,'saveImg');
			flash_obj.download(url);
		}

		//showThreadMenu({'flag':2});
	};

	/* 查看原图 */
	function openUrl(params)
	{
		//
		var idx = params['idx'];
		var url = params['url'];
		var img_id = params['img_id'];

		//
		qcomic_utils.debug('enter','openUrl');
		window.open(url,'_blank');
		showImgMenu({'show':0,'idx':idx,'img_id':img_id});
	};

	/* 拷贝外链图地址 */
	function copyUrl(params)
	{
		//
		var idx = params['idx'];
		var url = params['url'];
		var img_id = params['img_id'];

		//
		if( !jQuery.browser.mozilla )
		{
			qcomic_utils.debug('enter','copyUrl');
			window.clipboardData.setData('Text',params['url']);
			alert('地址已经复制到粘贴板!');
		}

		//
		showImgMenu({'show':0,'idx':idx,'img_id':img_id});
	};

	//显示|隐藏图片导航
	/*function showImgMenu(params)
	{
		//
		var idx = params['idx'];
		var show = params['show'];
		var img_id = params['img_id'];

		//
		if( show == 0 )
		{
			jQuery('#ilist_menu_'+idx+'_'+img_id).css('display','none');
		}
		else
		{
			var html = '';
			html+= '<div id="ilist_menu_rurl_'+idx+'_'+img_id+'">查看原图</div>';
			html+= '<div id="ilist_menu_lurl_'+idx+'_'+img_id+'">查看外链图</div>';
			html+= '<div id="ilist_menu_copy_lurl_'+idx+'_'+img_id+'">复制外链图</div>';
			jQuery('#ilist_menu_'+idx+'_'+img_id).html(html);
			jQuery('#ilist_menu_'+idx+'_'+img_id).css('display','');

			//原图
			jQuery('#ilist_menu_rurl_'+idx+'_'+img_id).click(function(e){
				//
				var id_arr = this.id.split('_');
				var idx = id_arr[3]+'_'+id_arr[4]+'_'+id_arr[5];
				var img_id = id_arr[6];
				qcomic_utils.debug('id='+this.id+',idx='+idx+',img_id='+img_id,'click menu rurl');

				//
				var img_data = _js_cache[idx]['data'][img_id];
				openUrl({'idx':idx,'url':img_data['rurl'],'img_id':img_id});
			});

			//外链图
			jQuery('#ilist_menu_lurl_'+idx+'_'+img_id).click(function(e){
				//
				var id_arr = this.id.split('_');
				var idx = id_arr[3]+'_'+id_arr[4]+'_'+id_arr[5];
				var img_id = id_arr[6];
				qcomic_utils.debug('id='+this.id+',idx='+idx+',img_id='+img_id,'click menu lurl');

				//
				var img_data = _js_cache[idx]['data'][img_id];
				openUrl({'idx':idx,'url':img_data['lurl'],'img_id':img_id});
			});
			jQuery('#ilist_menu_copy_lurl_'+idx+'_'+img_id).click(function(e){
				//
				var id_arr = this.id.split('_');
				var idx = id_arr[4]+'_'+id_arr[5]+'_'+id_arr[6];
				var img_id = id_arr[7];
				qcomic_utils.debug('id='+this.id+',idx='+idx+',img_id='+img_id,'click menu copy lurl');

				//
				var img_data = _js_cache[idx]['data'][img_id];
				copyUrl({'idx':idx,'url':img_data['lurl'],'img_id':img_id});
			});
		}
	}*/

	/* 下载进度 */
	function downloadMessage(params)
	{
		qcomic_utils.debug('enter','downloadMessage');
		if( params['width'] == 100 )
		{
			alert('下载完成');
			return;
		}
	};

	this.init = init;
	this.displayUBB = displayUBB;
	this.displaySlide = displaySlide;
	this.displayThread = displayThread;
	this.displayRelate = displayRelate;
}
var qcomic_output = new QComicOutput();
