window['blztv'] = null;

/* check weather has blaze tv client */
function check_blazetv ()
{
	try
	{
		new ActiveXObject('BLAZETVPLAYER.BlazeTVPlayerCtrl.1');
		window['blztv'] = true;
		return true;
	}
	catch (e)
	{
		return false;
	}
}

function view_mov (mlink)
{
	if (!window['blztv'] && window.ie)
	{
		show_pop_notice();
		return;
	}
	
	var ifm = $('mov_ifm');
	if (!ifm)
	{
		ifm = document.createElement('iframe');
		ifm.id = 'mov_ifm';
		ifm.style.display = 'none';
		document.body.appendChild(ifm);
	}
	
	ifm.src = mlink;
}

function change_vpic (elem)
{
	elem.src = elem.src.match(/.*(?=\?)?/) + '?r=' +Math.random();
}

/* mask */
function show_mask ()
{
	document.lastChild.style.overflow = 'hidden';
	$('scr_mask').setStyles({
		display:'block',
		height:window.getScrollHeight()
	});
}

function close_mask ()
{
	document.lastChild.style.overflowY = 'auto';
	$('scr_mask').setStyle('display', 'none');
}
/* /mask */

/* notice */
function show_top_notice ()
{
	if (Cookie.get('non_notice'))
		return;
	
	var notice = $('notice');
	setTimeout(function ()
	{
		//$(document.body).injectTop(notice);
		document.body.insertBefore(notice, $('header'));
		notice.effect('height', {duration:500}).start(0,30);
	}, 1500);
		
	$('close').onclick = function ()
	{
		Cookie.set('non_notice', 1);
		notice.effect('height', {duration:500}).start(0);
	};
}

function show_pop_notice ()
{
	show_mask();
	var pop_not = $('pop_notice');
	pop_not.setStyle('display','block');
	pop_not.setStyles({
		top:window.getScrollTop() + (window.getHeight() - pop_not.clientHeight) / 2,
		left:(window.getWidth() - pop_not.clientWidth) / 2
	});
}

function close_pop_notice ()
{
	$('pop_notice').setStyle('display','none');
	close_mask();
}
/* /notice */

/* bubble */
function make_tips (info_box, movs_box)
{
	if (!info_box)
		return;
	
	var win_width = window.getWidth();
	for (var j=0; j<movs_box.length; j++)
	{
		hd_movs = movs_box[j];
		for (var i=0; i<hd_movs.length; i++)
		{
			var elem = hd_movs[i].getFirst();
			$(elem).addEvent('mouseenter', function (e)
			{
				var curr_box = this.parentNode;
				e = new Event(e);
				
				info_box.getFirst().innerHTML = $(curr_box).getLast().innerHTML;
				info_box.style.display = 'block';
				
				var left = curr_box.getLeft();
				left = (left + info_box.offsetWidth < win_width) ? left : win_width - info_box.offsetWidth;
				info_box.style.left = left + 'px';
				if (0 > curr_box.getTop() - info_box.offsetHeight)
					info_box.style.top = curr_box.getTop() + this.offsetHeight + 'px';
				else
					info_box.style.top = curr_box.getTop() - info_box.offsetHeight + 'px';
				
				if (!parseInt(curr_box.getAttribute('serial')))
					this.getFirst().style.display = 'inline';
				
				e.stopPropagation();
			});
			
			$(elem).addEvent('mouseleave', function (e)
			{
				info_box.style.display = 'none';
				if (!parseInt(this.parentNode.getAttribute('serial')))
					this.getFirst().style.display = 'none';
			});
		}
	}
}
/* /bubble */

function popup_movie_bug ()
{
	show_mask();
	var pop_not = $('pop_bug_txt');
	pop_not.setStyle('display','block');
	pop_not.setStyles({
		top:window.getScrollTop() + (window.getHeight() - pop_not.clientHeight) / 2,
		left:(window.getWidth() - pop_not.clientWidth) / 2
	});
	
	return false;
}

function close_movie_bug ()
{
	$('pop_bug_txt').setStyle('display','none');
	close_mask();
	
	return false;
}

function send_movie_notice (frm)
{
	var bug = frm.mbug.value.replace(/(^\s+|\s+$)/g, '');
	
	if (0 < frm.mno.value.length && 0 < bug.length)
	{
		var ax = new XHR({mothed:'post'});
		ax.setHeader('content-type', 'application/x-www-form-urlencoded');
		ax.send('/movie/bug', 'mno='+frm.mno.value+'&mbug='+bug);
	}
	
	alert('感谢你发现并提交问题，我们会尽快解决！');
	close_movie_bug();
}