if (!$) {
	var $ = function (tagId){
		return document.getElementById(tagId);
	}
}


//login
var login_is_running = false;
var origin_url='';
var login_refresh=0;
String.prototype.trim=function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function refresh_page(){
	location.href = location.href;
	window.parent.location.href = window.parent.location.href;
}

function cancel_div(div_id){
	var o = document.getElementById(div_id);
	o.parentNode.removeChild(o);
}

//获取元素的纵坐标
function getTop(e){
	var offset=e.offsetTop;
	if(e.offsetParent!=null){ offset+=getTop(e.offsetParent);}
	return offset;
}
//获取元素的横坐标
function getLeft(e){
	var offset=e.offsetLeft;
	if(e.offsetParent!=null){ offset+=getLeft(e.offsetParent);}
	return offset;
}

//获取滚动条的位置
function getScroll(){
	var t, l, w, h;
	if (document.documentElement && document.documentElement.scrollTop) {
		t = document.documentElement.scrollTop;
		l = document.documentElement.scrollLeft;
		w = document.documentElement.scrollWidth;
		h = document.documentElement.scrollHeight;
	} else if (document.body) {
		t = document.body.scrollTop;
		l = document.body.scrollLeft;
		w = document.body.scrollWidth;
		h = document.body.scrollHeight;
	}
	return { t: t, l: l, w: w, h: h };
} 
function get_login_frm_html(){
	var code ='<div class="box4 loginLayer" id="login_box" style="position:absolute; top:80px; left:120px; z-index:1999; padding-bottom:3px; padding-right:3px; overflow:hidden;left:37%;">'
		+'<iframe id="login_frame" src="http://user.movie.xunlei.com/login_v2.html" SCROLLING="no" FRAMEBORDER="no"></iframe></div>';
	return code;
}

function global_login_frm_show(click_obj, is_top_click,o_url,refresh,type){
	if(!o_url)
		origin_url='http://www.xunlei.com';
	else
		origin_url=o_url;

	if(refresh)
		login_refresh=1;
	else
		origin_url=o_url;
	if(document.getElementById('global_login_frm') == null){
		
		create_login_opacity_div();
		
		$('login_box').style.display="";
		//$('loading_img').src='http://images.movie.xunlei.com/user/images/loading2.gif';
		$('login_frame').src='http://user.movie.xunlei.com/login_v2.html';
		if(type=='movie'){
			$('login_box').style.width='241px';
			$('login_frame').src='http://user.movie.xunlei.com/login_v2_movie.html';
		}
		var top = 0;
		top = ((screen.availHeight - 60) / 4 +document.documentElement.scrollTop);
		//alert(top);
		document.getElementById('login_box').style.top = top + 'px';
	}
}

function global_login_frm_unshow(){
	cancel_div('login_half_opacity_div');
	$('login_box').style.display="none";
	try {
		login_close_callback();
	}catch(e){};
}

function global_login_success(){
	global_login_frm_unshow();
	try {
		login_success_callback();
	}catch(e){};
	if(login_refresh){
		refresh_page();
	}
}

function create_login_opacity_div(){
	var div = document.createElement("div");
	div.setAttribute('id', 'login_half_opacity_div');
	div.style.left = '0px';
	div.style.height = document.body.clientHeight;
	document.body.appendChild(div);
}

var login_check_callback_func = null;

function global_login_check(callback){
	login_check_callback_func = callback;
	var url = 'http://usercp.movie.xunlei.com/interface/glogin.php?action=check&callback='+login_check_callback_func;
	//JSONscriptQuery(url);
	setTimeout("JSONscriptQuery('"+url+"');", 1);
}

document.write('<div class="login_box4 loginLayer" id="login_box" style="display:none;position:absolute; top:80px; left:120px; z-index:1999; padding-bottom:3px; padding-right:3px; overflow:hidden;left:37%;"><div id="loading_frame" style="position:absolute;margin-top:5px;margin-left:5px"><img id="loading_img" alt="" src="http://misc.web.xunlei.com/user/images/loading2.gif"/></div><div id="loading_frame2" style="margin-top: 5px; margin-right: 5px; position: absolute; right: 10px;"><a target="_self" href="javascript:void(0);" onclick="global_login_frm_unshow();">关闭</a></div><iframe id="login_frame" src="" SCROLLING="no" FRAMEBORDER="no"></iframe></div>');
