//sn
var im_session_id = set_sessid(get_kehu_cn_sn(im_mid));
var im_nickname = get_nickname();
im_status_url = im_status_url + '&sn=' + im_session_id;
im_url = im_url + '&sn=' + im_session_id;;


//&#33258;&#21160;&#26816;&#27979;
var auto_check_time_limit = 10 * 1000;//30000
var auto_check_time_number = 1;

write_invite_div();
write_list_skin();
//fly skin
function write_fly_skin(){
	im_online=true;
	document.write("<style>");
	document.write(".im_fly_div_over{border:#A4B2BD dashed 1px;}");
	document.write(".im_fly_div_out{border:0px;}");
	document.write("</style>");
	if(im_online == true)
	{
		var im_button_skin_image = im_button_skin_url + (style_icon.length > 0 ? style_icon : 'default') + '.gif';
		if(style_icon == 'default' && typeof(im_online_image) != 'undefined' && im_online_image.length > 5)
		{
			im_button_skin_image = im_online_image;
		}
	}
	if(im_button_skin_url.lenght < 1)im_button_skin_image = im_button_skin_url + (style_icon.length > 0 ? style_icon : 'default') + '.gif';
	//document.write("<img id=\"im_fly_div\" onclick='style_icon_open(0, 2);' src='" + im_button_skin_image + "' onmouseout='this.className=\"im_fly_div_out\"'  onMouseOver='this.className=\"im_fly_div_over\"'  style=\"POSITION: absolute;top:200px;left:300px;display:none; cursor:pointer; z-index:3000; \">");
	document.write("<img id=\"im_fly_div\" onclick='style_icon_open(0, 2);' style=\"display:none\" src='" + im_button_skin_image + "' onmouseout='this.className=\"im_fly_div_out\"'  onMouseOver='this.className=\"im_fly_div_over\"'  style=\"POSITION: absolute;top:200px;left:300px;display:none; cursor:pointer; z-index:3000; \">");
}
write_fly_skin();
//button skin
function write_button(){
	document.write("<style>");
	document.write(".im_fly_div_over{border:#A4B2BD dashed 1px;}");
	document.write(".im_fly_div_out{border:0px;}");
	document.write("</style>");
	
	if(im_online == true){
		var im_button_skin_image = im_button_skin_url + (style_icon.length > 0 ? style_icon : 'default') + '.gif';
		if(style_icon == 'default' && typeof(im_online_image) != 'undefined' && im_online_image.length > 5){
			im_button_skin_image = im_online_image;
		}


	}else{
		var im_button_skin_image = im_button_skin_url + (style_icon.length > 0 ? style_icon : 'default') + '_offline.gif';
		if(style_icon == 'default' && typeof(im_offline_image) != 'undefined'  && im_offline_image.length > 5){
			im_button_skin_image = im_offline_image;
		}
	}
	if(im_button_skin_url.lenght < 1)im_button_skin_image = im_button_skin_url + (style_icon.length > 0 ? style_icon : 'default') + '.gif';

	document.write("<img id=\"im_fly_div\"  onclick='style_icon_open(0, 2);' src='" + im_button_skin_image + "' onmouseout='this.className=\"im_fly_div_out\"'  onMouseOver='this.className=\"im_fly_div_over\"'  style=\" cursor:pointer;  \">");
	
}




//fun<<<

var im_list_load_status = false;
var im_fly_load_status = false;
function im_type_fly(style_icon_mode){
	
	if(typeof(im_fly_load_status) == 'undefined' || !im_fly_load_status){ 

		var move_status = true;
		if(style_valign == 'abs'){
			//move_status = false;
		}
		

		imFlyFloat = new Float(); 

		
		if(typeof(style_icon_mode) == 'undefined') var style_icon_mode='fly';

		if(style_icon_mode == 'fly'){
			//imFlyFloat.left = style_left;
			//imFlyFloat.top = style_top;
			//imFlyFloat.width = 100;
			imFlyFloat.align = 'right';//
			imFlyFloat.valign = 'bottom';//
			imFlyFloat.init('imFlyFloat', 'im_fly_div', style_align, false, false);
			
			//var im_invite_display = false;
			//if(typeof(inviteFloat) == 'object')im_invite_display = inviteFloat.display;

			if(im_member_id_list.length > 0 && (style_list_style == 'list' || style_list_style == 'rand')){
				imFlyFloat.show();
			}
			imFlyFloat.flyStart();

		}else if(style_icon_mode == 'button'){
			//var im_invite_display = false;
			//if(typeof(inviteFloat) == 'object')im_invite_display = inviteFloat.display;

			if(im_member_id_list.length > 0 && (style_list_style == 'list' || style_list_style == 'rand')){
				write_button();
			}
		}else{
			imFlyFloat.left = style_left;
			imFlyFloat.top = style_top;
			imFlyFloat.width = style_width;
			imFlyFloat.align = style_align;
			imFlyFloat.valign = style_valign;
			imFlyFloat.init('imFlyFloat', 'im_fly_div', style_align, false, true);
			
			//var im_invite_display = false;
			//if(typeof(inviteFloat) == 'object')im_invite_display = inviteFloat.display;

			if(im_member_id_list.length > 0 && (style_list_style == 'list' || style_list_style == 'rand')){
				imFlyFloat.show();
			}
		}
		

		var im_fly_load_status = true;

	}
}


var im_invite_load_status = false;
function im_init(){

	if(typeof(im_invite_load_status) == 'undefined' || !im_invite_load_status){

		
		parse_member_array();
		parse_service_array();
		
		if(typeof(im_account) != 'undefined' && my_strlen(im_account) > 0) {
			im_attachToEvent(window, 'onload', function (){go_chat( im_account); invite_clean();});
			
		}else{
			if(im_invite_active){
					if(style_invite_type == 'KEEPLIVE' && im_keep_live_active){
						keep_live_invite();
					}else{
						window.setTimeout('check_invite()', auto_check_time_limit);
					}	
			}

			style_invite_visit = parseInt(style_invite_visit);
			
			
			if(style_invite_once == 'N'){
				window.setTimeout("auto_invite()", 1000);
			}
		
		}
		var im_invite_load_status = true;
	}

}
function check_right(r){
	var _right = "," + style_limit_right + ",";
	r = "," + r + ",";

	if(_right.indexOf(r) > 0)return true;
	return false;
}

function go_agent_domain(){
	//if(im_agent_url.indexOf("kehu.com.cn") > 0 || im_agent_url.indexOf("kehu.cn") > 0 )return;
	if(im_agent_url.length<4)return;
	window.open(im_agent_url);
}

//check_invite
function init_invite(){
	if(style_invite_type == 'KEEPLIVE' && im_keep_live_active){
		keep_live_invite();
	}else{
		window.setTimeout('check_invite()', auto_check_time_limit);
	}

}
function keep_live_invite(){
	var sn = readCookie('_kehutone_sn_');
	//if(typeof(im_http_url) == 'undefined')var im_http_url = 'http://222.41.52.147:443/k8/http.html';
	
	var url = im_http_url 
			+ '?sn=' + sn 
			+ '&action=invite'
			+ '&mid=' + im_mid
			+ '&charset=' + im_charset
			+ '&style=' + im_style
			;
	//alert(url);
	window.setInterval(function() {window.status=' '}, 800);
	//window.setInterval(function() {window.status='&#23436;&#27605;.'}, 800);
	//window.status=url;
	check_keep_live_invite();
	document.write('<iframe src="' + url + '" name="kehu_cn_invite_frame" width="0" height="0"  frameborder="0" id="kehu_cn_invite_frame"></iframe>');

}

function check_keep_live_invite()
{
	try{
		var obj = document.kehu_cn_invite_frame;
		if(typeof(obj.invite) != "undefined"  )
		{
			if(!keep_live_invite_status){
				var d = new Date();
				// document.write(im_status_url + "&_t=" + d.getTime());return;
				load_script(im_invite_url + "?_t=" + d.getTime(), get_invite_msg);
				keep_live_invite_status = true;
				obj.document.body.innerHTML="";
			}

		}
	}catch(E)
	{
		
	}
	window.setTimeout("check_keep_live_invite()",2000);
}

function stop_check_invite(){
	invite_display = true;
	
}
function start_check_invite(){
	invite_display = false;
}
//&#33258;&#21160;&#36992;&#35831;
function auto_invite(){
	if(style_invite_once == 'H' || style_invite_once == 'D' || !im_online)return '';
	show_invite();
}
//&#25163;&#21160;&#36992;&#35831;
function check_invite(read){//style_invite_once == 'H' || 
	
	if(style_invite_once == 'D' || !im_online)return '';
	
	//if(style_invite_once == 'D')return '';
	//if(auto_check_lock)return true;
	var sn = readCookie('_kehutone_sn_');
	//window.status=auto_check_time_number;

	if(typeof(style_limit_invite) == 'undefined')var style_limit_invite = 0;

	if(style_invite_type != 'KEEPLIVE' || !im_keep_live_active){
		//!invite_display && 
		if(sn.length == 32 && read != 'N'){
			auto_check_time_number++;
			var d = new Date();
			load_script(im_invite_url + "?_t=" + d.getTime(), get_invite_msg);
		}
		
		window.setTimeout('check_invite()', auto_check_time_limit);

	}

}
//&#26174;&#31034;&#36992;&#35831;&#20869;&#23481;
function get_invite_msg(){
	var sn = readCookie('_kehutone_sn_');
	try{
		if(im_invite[sn]){
			
			show_invite(im_invite[sn][0], im_invite[sn][1]);
			im_invite = new Array();
			close_invite();
		}
	}catch(e){
		//alert(e);
	}
}

function close_invite(){
	var d = new Date();
	
	load_script(im_status_url + "&_t=" + d.getTime(), false);
}
function style_icon_open(account ){
	if(account == '' ) account = '';
	go_chat(account );
}
//&#36827;&#20837;&#27965;&#35848;
function go_chat(account, service_id){
	if(typeof(account) == 'undefined' ){
		account = '';
	}
	if(typeof(service_id) == 'undefined' ){
		service_id = '';
	}

	var status = '';
	try{
		var member = get_member_row(account);
		status = member['status'];
	}catch(e){

	}
	var type = 'chat';
	try{
		var service = get_service_row(service_id);
		if(service['mode'] == 'NOTE'){
			type = 'note';
		}
		
	}catch(e){

	}
	if(!im_online)type = 'note';
	var sn = readCookie('_kehutone_sn_');
	var accept_url = im_chat_url + "?mid=" + im_mid
			+ "&sn=" + sn 
			+ "&service_id=" + service_id 
			+ "&account=" + account 
			+ "&status=" + status
			+ "&type=" + type
			+ "&style=" + im_style
			+ "&url=" + im_page_url
			;
	
	stop_check_invite();
	keep_live_invite_status = false;
	im_open(style_brand, accept_url, style_open_width, style_open_height);
	
}
 
 
function im_pay(){
	
	im_open( style_brand, im_pay_url, style_open_width, style_open_height);

}
function kehu_search(frm){
	//window.open(im_search_url + "&style=1&q=" + frm.q.value);
	im_open( style_brand, im_search_url + "&style=1&q=" + frm.q.value, style_open_width, style_open_height);
	//im_open_frame
	return false;
}
function parse_member_array(){
	im_member_total = 0;
	for(i in im_member_list){
		im_member_id_list[i] = i;
		im_member_total += 1;
	}


	arr = im_online_list;
	
	if(typeof(arr) == 'object'){
		for(i in arr){
			switch(arr[i]['status']){
				case '2': 
				case '3': 
				case '4': im_online_member_total++;
				try{
					var b = arr[i]['business'].split(',');
					for(j in b){
						im_service_status[b[j]] = 'online';
						
					}
				}catch(e){}
				break;
			}
			im_member_status[arr[i]['account']] = arr[i];
		}
	}

	

}
function parse_service_array(){
	im_service_total = 0;
	for(i in im_service_list){
		im_service_total += 1;

		try{
			if(im_service_status[im_service_list[i]['id']] != 'online'){
				im_service_list[i]['mode'] = "NOTE";
			}
		}catch(e){}
	}
}

function get_member_row(account){
	for(i in im_member_id_list){
		line = im_member_list[im_member_id_list[i]];
		if(line['account'] == account)return line;
	}
}
function get_service_row(id){
	for(i in im_service_list){
		line = im_service_list[i];
		if(line['id'] == id)return line;
	}
}

function format_cn(str){
	str = escape(str);
	
	str =  str.replace(/%/g,'*');
	return str;
}



inviteFloat = new Float(); 

inviteFloat.init("inviteFloat", 'msg_invite', 'center', true, true);
if(style_invite_pos == 'right'){
	inviteFloat.align = 'right';
	inviteFloat.valign = 'bottom';
}else{
	inviteFloat.align = 'center';
	inviteFloat.valign = 'middle';
}

style_invite_wait = parseInt(style_invite_wait);
var invite_wait_timer = null;

function show_invite(account, msg){
	//if(typeof(imFloat) == 'object' && typeof(im_open_float) == 'object')imFloat.hide();
	if(typeof(imFlyFloat) == 'object' && imFlyFloat.display == true)imFlyFloat.hide();
	stop_check_invite();
	style_invite_title = style_invite_title.length > 1 ? style_invite_title : im_lang['invite_title'];
	var default_msg = im_lang['invite_message']; 
	var _msg = style_invite_msg.length > 2 ? style_invite_msg : default_msg;
	if(msg)_msg = msg;
	if(account)_msg = msg;

	get_id("msg_invite_title").innerHTML = style_invite_title;
	get_id("msg_invite_body").innerHTML = _msg;
	get_id("msg_invite_ok").onclick = function (){
		hide_invite();go_chat(account);return false;
		};
	get_id("msg_invite_cancel").onclick = function (){
		hide_invite();return false;
		};	

	inviteFloat.show();
	try{window.focus();}catch(e){}
	if(parseInt(style_invite_wait) >= 1) invite_wait_timer=window.setTimeout("hide_invite()",parseInt(style_invite_wait) * 1000); 

}
function hide_invite(){
	//if(inviteFloat.display)close_invite();
	try{
			inviteFloat.hide();
		
		if(invite_wait_timer){
			window.clearTimeout(invite_wait_timer);
			invite_wait_timer = null;
		}
		keep_live_invite_status = false;
		
		if(typeof(imFlyFloat) == 'object' && imFlyFloat.display == false)imFlyFloat.show();
		if(typeof(imFloat) == 'object' && typeof(im_open_float) == 'object'){
			//if(!im_open_float.display)imFloat.show();
		}
		start_check_invite();
	}catch(e){};
}

///<<<im_open
function im_open(title, url, width, height){

	width = parseInt(width);
	height = parseInt(height);
	try{	//top=1,left=1,width=1,height=1,location=no,resizable=0,scrollbars=0,status=no,toolbar=no,menu=no	
		var o = window.open(url, "www_kehu_cn", "left=10,top=10,width=" + width + ",height=" + height + ",scrollbars=0,menubar=0,location=no,status=no");
		o.focus();
		im_window_id = o;
	}catch(e){	
		window.location=url;	
	}

}

function im_type_url(){
	im_attachToEvent(window, 'onload', function (){style_icon_open(im_account); invite_clean();});
}


//fun>>>




//lib<<<
function get_system_info(){
	var cookieEnabled=(navigator.cookieEnabled)? true : false;
	if(!cookieEnabled)return false;
	//var d = new Date();
	//var unix_time = Math.round(d.getTime()/1000);
	unix_time = im_now_time;

	im_page_url = escape(window.top.location.href);
	im_page_title = escape(window.top.document.title);
	im_referer = window.top.document.referrer;
	//writeCookie('im_referer',top.document.referrer, 1);
	var referer_test = im_referer.toLowerCase();
	if(referer_test.indexOf('google.') > 1){
		try{
			im_referer = decodeURI(im_referer);
		} catch(e){
			//alert(e);
		}
		
	}
	im_referer = escape(im_referer);



	im_color = screen.colorDepth;
	im_screen_size = screen.width + '*' + screen.height;
	im_first_time = parseInt(readCookie('im_first_time'), 10);
	im_last_time = parseInt(readCookie('im_last_time'), 10);
	

	im_browser_count = parseInt(readCookie('im_browser_count'), 10);

	im_cookie = "";
		
	if(isNaN(im_first_time))im_first_time = 0;
	if(isNaN(im_last_time))im_last_time = unix_time;
	if(isNaN(im_browser_count))im_browser_count = 1;
	
	if(unix_time-im_first_time < 0){
		im_first_time = unix_time;
		im_last_time = unix_time;
		im_browser_count = 1;
	}
	
	if( im_first_time == 0 || (unix_time - im_last_time > 5*60))
	{
		im_first_time = unix_time;
		im_last_time = unix_time;
		im_browser_count = 1;
		writeCookie('im_first_time', im_first_time, 12);
		writeCookie('im_last_time', im_last_time, 12);
		writeCookie('im_browser_count', im_browser_count, 12);
	}
	else
	{
		im_browser_count++;
		writeCookie('im_browser_count', im_browser_count, 12);
		writeCookie('im_last_time', unix_time, 12);
	}
	

	//window.status = "first=" + im_first_time + ",last=" + im_last_time + ",count=" + im_browser_count+ ",online=" + im_online_time;
	var limit_time = 60;
	var im_page = readCookie('im_page');
	var im_page_time = parseInt(readCookie('im_page_time'), 10);
	//window.status=unix_time - im_page_time;
	if(isNaN(im_page_time) || unix_time - im_page_time > limit_time || im_page != im_page_url){
		writeCookie('im_page', im_page_url, 12);
		writeCookie('im_page_time', unix_time, 12);
	}else{
		return false;
	}
	im_online_time = im_last_time - im_first_time;
	
	var info = 
		 '&browser_count=' + im_browser_count
		+ '&systemlanguage=' + im_system_language
		+ '&first_time=' + im_first_time
		+ '&last_time=' + im_last_time
		+ '&online_time=' + im_online_time
		+ '&charset=' + im_charset
		+ '&title=' + im_page_title
		+ '&pageurl=' + im_page_url
		+ '&referer=' + im_referer
		;

	return info;
}



function set_sessid(s){
	//sid
	var sn = readCookie('_kehutone_sn_');
	if(!sn || sn.length != 32){
		writeCookie('_kehutone_sn_', s, 86400);
		sn = s;
	}
	return sn;
}
function get_nickname(){
	//sid
	var sn = readCookie('_kehutone_nickname_');
	return sn;
}
function set_nickname(n){
	if(n){
		writeCookie('_kehutone_nickname_', n, 86400);
		im_nickname = n;
	}
}

function readCookie(name)
{
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0)
	{ 
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{ 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
				cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}
// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
	var expire = "";
	if(hours != null)
	{
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + expire;
}
function get_kehu_cn_sn(mid){
	var kehu_cn_mid = kehu_cn_strpad(mid, 6) ;
	var o = new Date();
	var d = kehu_cn_strpad(o.getFullYear())  + kehu_cn_strpad(parseInt(o.getMonth())+1)  + kehu_cn_strpad(o.getDate());
	var t = kehu_cn_strpad(o.getHours()) + kehu_cn_strpad(o.getMinutes()) + kehu_cn_strpad(o.getSeconds());
	
	var kehu_cn_date = d  + t;
	var microtime = o.getTime() + ' ';
	microtime = microtime.substr(9,4);
	var sn = kehu_cn_mid + kehu_cn_date + microtime + rand_number(10000000, 99999999);
	sn =  sn.replace(' ','0');
	return sn;
}
function kehu_cn_strpad(v, l){
	if(typeof(l) == 'undefined')var l = 2;
	var s = v + '';
	if(s.length < l){
		for(var i = s.length; i < l;i++){
			s = '0' + s;
		}
	}
	return s;
}
function array_rand(Arr){
	Arr.sort(function(){return Math.random()>0.5?-1:1;});
	return Arr;
}
function rand_number(min, max){
	var r = 0;
	switch(arguments.length){ 
		case 1: r = parseInt(Math.random()*min+1); 
		case 2: r = parseInt(Math.random()*(max-min+1) + min);  
	}
	return r > min && r < max ? r : 0;
} 
function debug(type, str){
	if(type == 1){
		document.write(str);
	}else if(type == 2){
		alert(str);
	}else{
		alert(str);
	}
}
function get_id(obj)
{
	var element = null;
	if(document.getElementById)
	{
		element = document.getElementById(obj);
	}
	else if(document.all)
	{
		element = document.all[obj];
	}
	else if(document.layers)
	{
		element = document.layers[obj];
	} 
	return element;

} 

function load_script(url, callback) {
	var f = arguments.callee;
	if (!("queue" in f))
		f.queue = {};
	var queue =  f.queue;
	if (url in queue) { // script is already in the document
		if (callback) {
			if (queue[url]) // still loading
				queue[url].push(callback);
			else // loaded
				callback();
		}
		return;
	}
	queue[url] = callback ? [callback] : [];
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.onload = script.onreadystatechange = function() {
		if (script.readyState && script.readyState != "loaded" && script.readyState != "complete")
			return;
		script.onreadystatechange = script.onload = null;
		while (queue[url].length)
			queue[url].shift()();
		queue[url] = null;
	};
	script.src = url;
	document.getElementsByTagName("head")[0].appendChild(script);
}
function set_html(id, html)
{
	document.getElementById(id).innerHTML=html;
}
function set_text(id, text)
{
	document.getElementById(id).innerTEXT=text;
}
function hide_obj(id){
	document.getElementById(id).style.display='none'
}
function show_obj(id){
	document.getElementById(id).style.display=''
}
function showhide_obj(id){
	if(document.getElementById(id).style.display==''){
		document.getElementById(id).style.display='none';
		return 'close';
	}else{ 
		document.getElementById(id).style.display='';
		return 'open';
	}
}
function set_src(id, value){
	document.getElementById(id).src=value
}
function my_strlen(s){
	var i,str1,str2,str3,nLen;
	str1 = s;
	nLen = 0;
	for(i=1;i<=str1.length;i++){
			str2=str1.substring(i-1,i)
			str3=escape(str2);
			if(str3.length>3){
				nLen = nLen + 2;
			}else{
				nLen = nLen + 1;
			}
	}
	return nLen;
}


//float
function Float(){
	var self = this;
	this.obj = null;
	this.currentX = 0;
	this.currentY = 0;                              
	this.whichIt = null;                                         
	this.lastScrollX = 0; 
	this.lastScrollY = 0;   
	this.tempx = 0;
	this.tempY = 0;
	this.offsetx = 0;
	this.offsety = 0;
	this.IE = (document.getElementById && document.all);
	this.NS = (document.getElementById && !document.all);  
	this.layer_id = null;
	this.dragapproved = false;
	this.mousetrail = false;

	this._oBody = '';
	this._oHelperIframe = '';
	this._iframe = true;

	this.name = '';
	this.frame_style = true;
	this.left = 2 ;
	this.top = 120;
	this.width = 0;
	this.align = 'right';
	this.valign = 'middle';
	this.display = false;
	this.drag_left =0;
	this.drag_top =0;


	this.fly_timer = null;
	this.fly_x = 0;
	this.fly_y = 0;
	this.evt_id = '';

	this.init = function (name, d, align, drag_status, move_status ){
		this.name = name;
		this.layer_id = document.getElementById(d);
		 
		this.layer_id.style.zIndex = 99999;

		this.change_align( align);
		var tmp = function (){
				eval(name + ".add_frame()")
			}
	
		im_attachToEvent (window, 'onload', tmp);		
		
		if(drag_status)im_attachToEvent(this.layer_id, 'onmousedown', this.DragStart );
		if(move_status && (this.NS || this.IE)) action = window.setInterval(this.name + ".heartBeat()",200);
		
		var tmp = function (){
				eval(name + ".change_align()")
			}
		im_attachToEvent(window, 'onresize', tmp);

		this.layer_id.onShow = new Function();
		this.layer_id.onHide = new Function();
		this.layer_id.onDragStart	= new Function();
		this.layer_id.onDragEnd	= new Function();
		this.layer_id.onDrag	= new Function();	


		try{
			this._move_frame = document.getElementById('float_move_frame');
		}catch(e){

		}
	
		
	}
	this.iframe_status = function(s){
		this._iframe = s;
	}
	this.add_frame = function(){
		//if(document.readyState!="complete") this.frame_style=false;
		if(this._iframe && this.frame_style && this.IE && !this._oHelperIframe){ 
			var _layer_id_display = this.layer_id.style.display;
			this._oBody = document.getElementsByTagName("BODY").item(0);

			this._oHelperIframe = document.createElement("IFRAME");
			//this._oHelperIframe.src='about:blank';
			this._oHelperIframe.frameborder = 0;
			this._oHelperIframe.noresize = 0;
			this._oHelperIframe.border = 0;
			this._oHelperIframe.marginwidth = 0;
			this._oHelperIframe.marginheight = 0;
			//this._oHelperIframe.allowTransparency = "true";

			this._oHelperIframe.scrolling="no";
			this._oHelperIframe.style.filter='Alpha(opacity=0)';
			//this._oHelperIframe.style.backgroundColor = 'transparent';
			this._oHelperIframe.style.border = 0;
			this._oHelperIframe.width = 0;
			this._oHelperIframe.height = 0;
			this._oHelperIframe.style.position = "absolute";
			this._oBody.appendChild(this._oHelperIframe);
			this.layer_id.style.display = '';
			
			this._oBody.appendChild(this.layer_id);
			this._oHelperIframe.style.top = this.layer_id.style.top;
			this._oHelperIframe.style.left = this.layer_id.style.left;
			this._oHelperIframe.style.width = parseInt(this.layer_id.offsetWidth) > 0 ? this.layer_id.offsetWidth : this.layer_id.style.width;//.offsetWidth
			this._oHelperIframe.style.height = this.layer_id.offsetHeight;// 

			this._oHelperIframe.style.zIndex = this.layer_id.style.zIndex-1;
			this._oHelperIframe.style.display = _layer_id_display;

			this.layer_id.style.display = _layer_id_display;
		}

	}
	this.close = function () {
		this.hide();

	}
	this.hide = function () {
		//if(this.layer_id.style.display == 'none')return '';
		if(typeof(self._oHelperIframe) == 'object' && self.frame_style && this.IE){
			this._oHelperIframe.style.display = 'none';
			//this._oHelperIframe.style.VISIBILITY = 'hidden';
		}
		this.layer_id.style.display = 'none';
		
		this.layer_id.onHide();
		this.display = false;
	}
	this.show = function () {
		//if(this.layer_id.style.display != 'none')return '';
		if(typeof(self._oHelperIframe) == 'object' && self.frame_style && self.IE){
			//this._oHelperIframe.style.VISIBILITY = 'visible';
			self._oHelperIframe.style.display = '';
		}
		//this.layer_id.style.VISIBILITY = 'visible';
		this.layer_id.style.display = '';
		this.layer_id.onShow();
		this.change_align( );
		this.display =  true;
		
	}

	this.flyStart = function (e){
		if(typeof(e) == 'object'){
			evt = self.fixE(self.NS ? e : event);
			var dx = parseInt(self.layer_id.style.left, 10);
			var dy = parseInt(self.layer_id.style.top, 10);
			var mx = parseInt(evt.mouseX, 10);
			var my = parseInt(evt.mouseY, 10);
			if((my - dy) > self.bodyHeight())self.layer_id.style.top = self.scrollTop();
			if((mx - dx) > self.bodyWidth())self.layer_id.style.left = self.scrollLeft();

			self.fly_x = mx+50;
			self.fly_y = my+50;
		
			self.evt_id = evt.srcElement.id;
		}
		else {
			im_attachToEvent(document, 'onmousemove', this.flyStart );
			window.setInterval(this.name + ".fly()",200);
		}
		
	}
	this.fly = function ( x, y) {
		var percent = 1;
		
		if(self.layer_id.id == self.evt_id && self.evt_id)return;
		var dx = parseInt(self.layer_id.style.left, 10);
		if(self.fly_x != dx) {
			percent = .03 * Math.abs(self.fly_x - dx );
			
			if(percent > 0) percent = Math.ceil(percent);
			else percent = Math.floor(percent);
			
			dx = (self.fly_x - dx > 0) ? dx + percent : dx - percent;
		}
		var dy = parseInt(self.layer_id.style.top, 10);
		if(self.fly_y != dy) {
			percent = .03 * Math.abs(self.fly_y - dy) ;
			if(percent > 0) percent = Math.ceil(percent);
			else percent = Math.floor(percent);
			
			dy = (self.fly_y - dy > 0) ? dy + percent : dy - percent;
		}                       
		self.fix_position(dx, dy);
		//window.status = "(dx)=" + dx + "(dy)=" + dy;
		//window.status += "(self.fly_x)=" + self.fly_x + "(self.fly_y)=" + self.fly_y;
	}


	this.heartBeat = function () {
		var diffX = this.scrollLeft(); 
		var diffY = this.scrollTop(); 
		


		if(diffX != this.lastScrollX) {
			//var percent = .1 * (diffX - this.lastScrollX);
			var percent = diffX - this.lastScrollX;
			if(percent > 0) percent = Math.ceil(percent);
			else percent = Math.floor(percent);
			this.layer_id.style.left = (parseInt(this.layer_id.style.left, 10) + percent + 'px');
			this.lastScrollX = this.lastScrollX + percent;
		}
		if(diffY != this.lastScrollY) {
			//var percent = .1 * (diffY - this.lastScrollY);
			var percent = diffY- this.lastScrollY;
			if(percent > 0) percent = Math.ceil(percent);
			else percent = Math.floor(percent);
			
			this.layer_id.style.top = (parseInt(this.layer_id.style.top, 10) + percent + 'px');
			this.lastScrollY = this.lastScrollY + percent;
			
		}                       
		var x = parseInt(self.layer_id.style.left, 10);
		var y = parseInt(self.layer_id.style.top, 10);
		self.fix_position(x, y);
		
	}
	this.fix_position = function (x, y){
		var w = self.get_width();
		var h = self.get_height();		
		
		var b_w = self.scrollLeft() + self.bodyWidth() - w;
		var b_h = self.scrollTop() + self.bodyHeight() - h;
		
		
		if(x >= b_w){
			x = b_w;
		}
		if(x <= 1){
			x = 1;
		}

		if(y >= b_h){
			y = b_h;
		}


		if(y <= 1){
			y = 1;
		}
		self.layer_id.style.left = x + "px";
		self.layer_id.style.top = y + "px";
		if(typeof(self._oHelperIframe) == 'object' && self.frame_style && self.IE){
			self._oHelperIframe.style.left = self.layer_id.style.left;
			self._oHelperIframe.style.top = self.layer_id.style.top;
		}
		//if(self.name=='inviteFloat')window.status = "width=" + w + ", height=" + h + ", b_w=" + b_w + ", b_h=" + b_h + ", x=" + x + ", y=" + y + "";

	}
	this.fix_size = function (){
		var w = self.get_width();
		var h = self.get_height();
		if(typeof(self._oHelperIframe) == 'object' && self.frame_style && self.IE){
			self._oHelperIframe.style.width =  w + 'px';
			self._oHelperIframe.style.height = h + 'px';
		}
	}


	this.DragStart = function (e){
		var evt = self.NS ? e : event;
		self.offsetx = evt.clientX;
		self.offsety = evt.clientY;
		self.drag_left = parseInt(self.layer_id.style.left, 10);
		self.drag_top = parseInt(self.layer_id.style.top, 10);
		self.width = self.get_width();
		self.height = self.get_height();				
		
		
		self.dragapproved = true;

		document.onmousemove = self.Drag;
		document.onmouseup = self.DragEnd;

		self.layer_id.onDragStart();

		return false;
	}

	this.Drag = function (e){

		if(self.dragapproved){
			
			var evt = self.NS ? e : event;
			var x = self.drag_left + evt.clientX - self.offsetx;
			var y = self.drag_top + evt.clientY - self.offsety;

			self.fix_position(x, y);
			self.layer_id.onDrag();
			self.layer_id.style.cursor="move";
			//window.status = 'x=' + x + ', y=' + y;
			return false;
		}
		
	}

	this.DragEnd = function (e){
		self.dragapproved = false;
		self.layer_id.onDragEnd();
		self.layer_id.style.cursor="default";

	}




	this.fixE = function (e){
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		if (typeof e.srcElement == 'undefined') e.srcElement = e.target;
		if(self.NS){
			e.mouseX  =  e.pageX;
			e.mouseY  =  e.pageY;
		}else if(!self.NS && document.getElementById){
			e.mouseX  =  event.x + self.scrollLeft();
			e.mouseY  =  event.y + self.scrollTop();
		}else{
			e.mouseX  =  event.x;
			e.mouseY  =  event.y;
		}

		return e;
	}

 
	this.get_width = function (){
		var w = parseInt(this.layer_id.style.width, 10);
		if(!w && this.IE){
			 w = parseInt(this.layer_id.offsetWidth, 10);
		}
		if(!w){
			 w = 150;
		}
		return w;
	}
	this.get_height = function (){
		var h = parseInt(this.layer_id.style.height, 10);
		if(!h && this.IE){
			 h = parseInt(this.layer_id.offsetHeight, 10);
		} 
		if(!h){
			 h = 280;
		}
		return h;
	}
	this.scrollTop = function (){
		var s; 
		if (typeof(window.pageYOffset) != 'undefined') { 
			s = window.pageYOffset; 
		} 
		else if (typeof(document.compatMode) != 'undefined' &&document.documentElement.scrollTop > 0) { 
			s = document.documentElement.scrollTop; 
		}  
		else if (typeof(document.body) != 'undefined') { 
			s = document.body.scrollTop; 
		} 
		
		return parseInt(s, 10);
	}
	this.scrollLeft = function (){
		var s; 
		if (typeof(window.pageXOffset) != 'undefined') { 
			s = window.pageXOffset; 
		} 
		else if (typeof(document.compatMode) != 'undefined' &&document.documentElement.scrollLeft > 0) { 
			s = document.documentElement.scrollTop; 
		}
		else if (typeof(document.body) != 'undefined') { 
			s = document.body.scrollLeft; 
		} 
		return parseInt(s, 10);
	}
	this.bodyWidth = function (){ 
		var w = 0;
		if (!document.all) {
			w = document.body.clientWidth > document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
		}
		else{
			w = document.documentElement.clientWidth == 0 ? document.body.clientWidth : document.documentElement.clientWidth;
		}
		return parseInt(w, 10);
		//return parseInt((document.all) ? document.body.clientWidth : window.innerWidth, 10);
	}
	this.bodyHeight = function (){
		var h = 0;
		if (!document.all) {
			h = document.body.clientHeight > document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		}
		else{
			h = document.documentElement.clientHeight == 0 ? document.body.clientHeight : document.documentElement.clientHeight;
		}
		return parseInt(h, 10);
		//return parseInt((document.all) ? document.body.clientHeight : window.innerHeight, 10);
	}
	this.change_align = function (a){
		var bodyWidth = self.scrollLeft() + self.bodyWidth();
		var bodyHeight = self.scrollTop() + self.bodyHeight();
		 
		var offset_top = 120;
		var offset_left = 2;
		var w = this.get_width();
		var h = this.get_height();

		if(this.align.length < 3)this.align = a;
		
		switch(this.align){
			case 'left':
				offset_left = 2;
				break;
			case 'center':
				offset_left = (bodyWidth - w) / 2;
				break;
			case 'right':
				offset_left = (bodyWidth - w);
				break;
			default:
				if(parseInt(this.left) >= 0)offset_left = parseInt(this.left);
				break;
		}
		

		switch(this.valign){
			case 'top':
				offset_top = 2;
				break;
			case 'middle':
				offset_top = (bodyHeight - h) / 2;
				break;
			case 'bottom':
				offset_top = (bodyHeight - h);
				break;
			default:
				if(parseInt(this.top) >= 0)offset_top = parseInt(this.top);
				break;
		}
		offset_top = offset_top < 0 ? 150 : offset_top;
		
		
		self.fix_position(offset_left+self.scrollLeft(), offset_top+ self.scrollTop());
	}
}
function loadScript (url, callback) {
	var script = document.createElement('script');
	script.type = 'text/javascript';
 
	if (callback)
		script.onload = script.onreadystatechange = function() {
			if (script.readyState && script.readyState != 'loaded' && script.readyState != 'complete')
				return;
			script.onreadystatechange = script.onload = null;
			callback();
		};
	script.src = url;
	document.getElementsByTagName('head')[0].appendChild (script);
}


function im_preloadImages() {
	var d=document; 
	if(d.images){ 
		if(!d.im_MM_p) d.im_MM_p=new Array();
		var i,j=d.im_MM_p.length,a=im_preloadImages.arguments; 
		for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ 
			d.im_MM_p[j]=new Image; 
			d.im_MM_p[j++].src=a[i];
		}
	}
}


function im_attachToEvent(obj, name, func) {
	name = name.toLowerCase();
	// Add the hookup for the event.
	if(typeof(obj.addEventListener) != "undefined") {
		if(name.length > 2 && name.indexOf("on") == 0) name = name.substring(2, name.length);
			obj.addEventListener(name, func, false);
		} else if(typeof(obj.attachEvent) != "undefined"){
			obj.attachEvent(name, func);
		} else {
			if(eval("obj." + name) != null){
			// Save whatever defined in the event
			var oldOnEvents = eval("obj." + name);
			eval("obj." + name) = function(e) {
				try{
					func(e);
					eval(oldOnEvents);
				} catch(e){}
			};
		} else {
			eval("obj." + name) = func;
		}
	}
}
//lib>>>
