//*******************************************
//动态取得模板JS
//用法：
//	var tpl = new template('movie_shoucan',callback_function_obj);
//	tpl.setparam('title',title);
//	tpl.setparam('msg',this.msg);
//	tpl.get();
// 如果要弹出DIV 那么就：movie_tpl.div('divid',html);
//关闭弹出的DIV：movie_tpl.div('divid');
//********************************************/
var old_y_position = 200;
var old_id = '';
var gf_position_handle = '';
function template(k,fun){
	this.url = 'http://movie.xunlei.com/template.php';
	this.param = 'key='+k;
	this.html = false;
	this.key = k;
	this.callback = fun;
	//this.old_id='';
	//this.old_y_position = 200;
	//this.gf_position_handle = '';
//	this.old_y_position = 200;
}
//设置模板的参数
template.prototype.setparam = function(key,value){
	this.param +='&'+key+'='+encodeURI(value); 
}

template.prototype.get = function(){
	var t = new Date();
	this.param +='&adfsdffsdf='+t;
	var obj = xlAjax(this.url,this.param,this.callback);
	obj.get();
}

template.prototype.gethtml = function(obj){
	return this.html;
}
//弹出DIV
template.prototype.div = function(id,html){
	if($obj(id)){
		return true;
	}
	old_id = id;
	old_y_position = gettop();
	create_global_opacity_div('suopingdiv');
	var div = document.createElement("div");
	div.setAttribute('id', id);
	div.className = 'box4 favOPLayer movie_col_box_id';
	div.innerHTML = html;
	div.style.top = old_y_position;
	document.body.appendChild(div);
	gf_position_handle = setInterval('template_init();', 1);
}
function template_init(id){
	try{
	   	var b = $obj(old_id);//定位是相当于父div的
	   	if(!b){
	   		return '';
	   	}
		var top = gettop();
        var step = 0.1*(top-old_y_position);
        if(step>0){
            step = Math.ceil(step);
        }else{
            step = Math.floor(step);
        }
        old_y_position = old_y_position + step;
        b.style.top = old_y_position + "px";
	}
	catch(e){}
}
function gettop(){
	return (parseInt((screen.availHeight - 60) / 4 )+document.documentElement.scrollTop);
}
//取消弹出DIV
template.prototype.cancel_div = function(id){
	template_cancel_div('suopingdiv');
	template_cancel_div(id);
	try{
		clearInterval(gf_position_handle);
	}
	catch(e){}
}
var movie_tpl = new template();