//*******************************************

//动态取得模板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 = '';

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_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.callback = function(request){

//	this.html = request.responseText;

//	alert('fasdf');

////	f = this.callback;

////	f(this.html);

//}



template.prototype.gethtml = function(obj){

	return this.html;

}

//弹出DIV

template.prototype.div = function(id,html){

	if(document.getElementById(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';

	div.innerHTML = html;

	div.style.top = old_y_position;

	document.body.appendChild(div);

	//template_init();

	var gf_position_handle = setInterval('template_init();', 1);
	
	if(true){
		
		var iframe = document.createElement("iframe");
		iframe.id = 'iframe_opacity';
		iframe.style.position = 'absolute';
		iframe.style.zIndex = 1;
		iframe.style.left=0;
		iframe.style.top=0;
		iframe.style.width='100%';
		iframe.style.height='500px';
		iframe.style.filter='alpha(opacity=0)';
		iframe.style.border='0';
		document.getElementById('suopingdiv').appendChild(iframe);
	}
}

function template_init(id){

	try{

	   	var b = document.getElementById(old_id);//定位是相当于父div的

	   	if(!b){

	   		return '';

	   	}

//	        var top = getScroll().t + 200;

		var top = gettop();

	        var step = 0.1*(top-old_y_position);

	

	        if(step>0){

	            step = Math.ceil(step);

	        }else{

	            step = Math.floor(step);

	        }

	        if(step==0){

//	            return '';

	        }

	        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){
//	if(getCookie('usrname')=='yzmtest'){
//		template_cancel_div('iframe_opacity');
//	}
	template_cancel_div('suopingdiv');

	template_cancel_div(id);

}

var movie_tpl = new template();