

var headID = document.getElementsByTagName("head")[0];         
var dock_scrollwidth = dock_getScrollBarWidth();
var dock_deep = 40;
var dock_cao = null;
var dock_mail_popup = null;
var dock_ab_popup = null;
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = 'http://www.heeloo.net/css/dockwhite.css';
cssNode.media = 'screen';
headID.appendChild(cssNode);
var jsNode = document.createElement("script");
jsNode.src = "/xg/xg-popup2.js";
jsNode.type = "text/javascript";
headID.appendChild(jsNode);
dock_check();

var dock_db = document.getElementById("doc_background");
var dock_isTablet = false;

var ua = "CCBot/1.0 (+http://www.commoncrawl.org/bot.html)";
        ua = ua.toLowerCase();

if (ua.indexOf("ipad")==-1){
    document.body.style.overflow = "hidden";
}else{
    dock_isTablet = true;
 //   document.body.style.overflow = "auto";    
}

if (dock_isTablet == false && dock_db != null){
	dock_db.style.overflow = "auto";
	var child = document.getElementById("doc_background_fchild");
	if (child != null) child.style.height = "30px";
}

var dock_menu_hidden = false;
var dock_menu_working = false;
var dock_hide_time = 2;
var dock_sh_timer = null;

var dock_menu = document.createElement("DIV");
dock_menu.style.position = "absolute";
if (dock_isTablet) dock_menu.style.position = "fixed";
dock_menu.style.visibility = "hidden";
dock_menu.style.backgroundColor = "transparent";

	var dock_html = "<table  border='0' cellspacing='0' cellpadding='0' width='100%' height='100%'>";
	dock_html +="<tr>";
		dock_html += "<td class='dock_mnu_start_na' width='1%'>";
			dock_html +="<div>";
				dock_html += "&nbsp;"
			dock_html +="</div>";
		dock_html +="</td>"
		dock_html +="<td class='dock_mnu_center'  width='99%' valign='middle'>";
			dock_html +="<table class='dock_table' border='0' cellspacing='2' cellpadding='2' width='100%'>";
				dock_html += "<tr>";
					dock_html += "<td width='1%' valign='middle'>";
						dock_html +="<div class='dock_nickname'>&nbsp;</div>";
					dock_html +="</td>";
					dock_html += "<td width='98%' align='left'>";
						dock_html += "<div style='margin-left:50px'>";
							dock_html += "&nbsp;";
						dock_html += "</div>";
					dock_html +="</td>";
					dock_html += "<td width='1%' valign='middle' align='right' style='white-space:nowrap'>";
						dock_html += "Online in Heeloo:<span id='dock_total_users'></span>";
					dock_html+="</td>";
					dock_html += "<td width='1%' valign='middle'>";
					dock_html+="</td>";
					dock_html +="</tr>";
					dock_html +="</table>";
		dock_html +="<td>";
		dock_html+="<td class='dock_mnu_center_na'>";
			dock_html +="<div style='width:300px;'>";
				dock_html+="<div style='float:left;margin-top:12px;height:30px;margin-left:10px;'>";
					dock_html +="<b><a href='javascript:_createUser()' target='_top' class='dock_white_a'>no resource found for [login.dock.createuser,-1]</a></b>";
				dock_html +="</div>";
				dock_html += "<div style='float:left;margin-left:10px;margin-top:10px;'><a href='javascript:_startShowLogin()' class='hbtn_blue' onclick='this.blur()'><span>no resource found for [login.dock.login,-1]</span></a></div>";
			dock_html+="</div>";			
		dock_html+="</td>";
		dock_html +="<td class='dock_mnu_end_na' width='1%'>";
			dock_html +="<div style='width:39px;height:77px;'></div>";			
		dock_html +="<td>";
	dock_html += "</tr>";
dock_html +="</table>";
dock_menu.style.visibility = "visible";	

dock_menu.innerHTML = dock_html;
document.body.appendChild(dock_menu);
dock_menu.style.zIndex =9000;


dock_menu_resize();

if (!dock_isTablet){
    dock_sh_timer = window.setTimeout("dock_menu_hide()",5*1000);
}

function dock_app_mover(id){
	var obj = document.getElementById("dock_app_"+id);
	obj.className = "dock_app_container_over";
}

function dock_app_mout(id){
	var obj = document.getElementById("dock_app_"+id);
	obj.className = "dock_app_container";
}

function dock_app_click(id,url){
	var no = document.getElementById("dock_app_"+id+"_no");
	if(no.style.visibility == "visible"){
			if(id == "h.mail"){
				if (dock_mail_popup == null){
				dock_mail_popup = new xgPopup("white");
				dock_mail_popup.setContent("<div style='width:350px;height:50px;color:black;background-color:white;'>"+hx_loading+"</div>");
				dock_mail_popup._sindex = -1;
				dock_mail_popup.show(xg.util.getLeft(no)-35,xg.util.getTop(no)+10);	
				dock_mail_popup.setOrientation(2);
				var url =	 myServer +"/ixp/mail/getmails/?content=html&folder=_newemails&limit=0,10&pattern=objects.mailitem_dock";
				xg.xhr.post(url,
					function(resObj){
						dock_mail_popup.setContent(resObj);
						dock_mail_popup.autosize();
				});

				}else{
					dock_mail_popup.show(xg.util.getLeft(no)-35,xg.util.getTop(no)+10);
					dock_mail_popup.setOrientation(2);

				}
		}else
		if (id == "h.ab"){
			if (dock_ab_popup == null){
				dock_ab_popup = new xgPopup("white");
				dock_ab_popup.setContent("<div style='width:350px;height:50px;color:black;background-color:white;'>"+hx_loading+"</div>");
				dock_ab_popup._sindex = -1;
				dock_ab_popup.show(xg.util.getLeft(no)-35,xg.util.getTop(no)+10);	
				dock_ab_popup.setOrientation(2);
				var url =	 myServer +"/apps/procs/users_requests_dock.sc";
				xg.xhr.post(url,
					function(resObj){
						var html="<div style='width:100%;height:20px;text-align:center'><a href='http://n/a/apps#AdressBook' target='_top'>AdressBook</a></div>";
						dock_ab_popup.setContent(resObj+html);
						dock_ab_popup.autosize();
				});

				}else{
					dock_ab_popup.show(xg.util.getLeft(no)-35,xg.util.getTop(no)+10);
					dock_ab_popup.setOrientation(2);

				}
		}
	}else{
		window.open(url,"_self");
	}
}

dock_menu.onmousemove = function(){

	if (dock_menu_hidden){
		if (!dock_menu_working){
			dock_menu_show();
		}
	}

	if (dock_sh_timer != null){
		window.clearTimeout(dock_sh_timer);
		dock_sh_timer = null;
	}
}

dock_menu.onmouseout = function(){
	if (!i_mouseInside(this) && (dock_mail_popup ==null || !dock_mail_popup.visible) 
			&& (dock_ab_popup==null || !dock_ab_popup.visible)){
		dock_sh_timer = window.setTimeout("dock_menu_hide()",dock_hide_time*1000);
	}
}

function dock_menu_resize(){
	var _width = document.body.clientWidth;
	var _height = document.body.clientHeight;
	var swidth = 20;
	_width = _width-(dock_deep*2)-dock_scrollwidth;
	dock_menu.style.width = _width+"px";
	dock_menu.style.height = "70px"
	dock_menu.style.left = dock_deep+"px";
	dock_menu.style.top = "-5px";
	if (!dock_isTablet) {
        dock_db.style.height = _height+"px";
    }else{
        dock_menu.style.left = "-20px";
        dock_menu.style.width = (document.body.clientWidth+45)+"px";
        dock_menu.style.top = "-22px";
    }
}

function dock_img_loaded(){
	dock_menu.style.visibility = "visible";
}

function dock_menu_hide(){
	dock_starthide();
}

function dock_starthide(){
	var t = parseInt(parseFloat(dock_menu.style.top));
	var c = document.getElementById("doc_background_fchild");
	var d = document.getElementById("doc_background");

	if (t > -70){
		t=t-5;
		dock_menu.style.top = t+"px";
		if (d.scrollTop==0){
			try{ if (c != null) c.style.height = (50+t)+"px"; }catch(e){}
		}
		window.setTimeout("dock_starthide()",1);
	}else{
		dock_menu_hidden=true;
		try{ if (c != null) c.style.height = "0px";}catch(e){}
	}
	
}

function dock_menu_show(){
	var d = document.getElementById("doc_background");
	var t = parseInt(parseFloat(dock_menu.style.top));
	var c = document.getElementById("doc_background_fchild");
	if (t < 0){
		dock_menu_working = true;
		t=t+5;
		dock_menu.style.top = t+"px";
		if (d.scrollTop == 0){
			try{ if (c != null) c.style.height = (40+t)+"px"; }catch(e){}
		}
		window.setTimeout("dock_menu_show()",1);
	}else{
		dock_menu_hidden=false;
		dock_menu_working = false;
		dock_menu.style.top = "-5px";
		dock_sh_timer = window.setTimeout("dock_menu_hide()",dock_hide_time*1000);
	}	
}

function dock_check(){
	xg.xhr.get("/check/", function (resObj){
		dock_cao = resObj;
		if(dock_menu.style.visibility == "hidden"){
			window.setTimeout("dock_putresults()",100);
		}else{
			dock_putresults();
		}
	});
}

function dock_putresults(){
	if(dock_menu.style.visibility == "hidden"){
			window.setTimeout("dock_putresults()",100);
	}else{
		xg.setValue("dock_total_users",dock_check_get(dock_cao,"users"));
		var newEmails = dock_check_get(dock_cao,"nm");
		var newFriends = dock_check_get(dock_cao,"ab");
		
		var objFriends = xg.obj("dock_app_h.ab_no");
		var objEmails = xg.obj("dock_app_h.mail_no");
		
		if (objFriends != null){
		if (newFriends > 0 ){
			var lastFriends = parseInt(parseFloat(objFriends.innerHTML));
			objFriends.innerHTML = newFriends;
			objFriends.style.visibility = "visible";
			if (lastFriends != newFriends){
				if (dock_menu_hidden) {
					dock_menu_show();
				}
			}
		}else{
				objFriends.innerHTML = "0";
				objFriends.style.visibility = "hidden";
			}
		}
		if (objEmails != null){
		if (newEmails > 0){
			var lastEmails = parseInt(parseFloat(objEmails.innerHTML));
			objEmails.innerHTML = newEmails;
			objEmails.style.visibility = "visible";
			if (lastEmails != newEmails){
				if (dock_menu_hidden) {
					dock_menu_show();
				}
			}
		}else{
			objEmails.innerHTML = "0";
			objEmails.style.visibility = "hidden";
		}
		}
		window.setTimeout("dock_check()",10000);

	}
}

function dock_check_get(xml,str){
	
	try{
		var result = xml.substring(xml.indexOf("<"+str+">")+(str.length+2));
		result = result.substring(0,result.indexOf("</"+str+">"));
		return result;
	}catch(e){alert(e);}

	return -1;
}

    function dock_getScrollBarWidth () {  
        var inner = document.createElement('p');  
        inner.style.width = "100%";  
        inner.style.height = "200px";  
      
        var outer = document.createElement('div');  
        outer.style.position = "absolute";  
        outer.style.top = "0px";  
        outer.style.left = "0px";  
        outer.style.visibility = "hidden";  
        outer.style.width = "200px";  
        outer.style.height = "150px";  
        outer.style.overflow = "hidden";  
        outer.appendChild (inner);  
      
        document.body.appendChild (outer);  
        var w1 = inner.offsetWidth;  
        outer.style.overflow = 'scroll';  
        var w2 = inner.offsetWidth;  
        if (w1 == w2) w2 = outer.clientWidth;  
      
        document.body.removeChild (outer);  
      
        return (w1 - w2);  
    };  


function dock_setUserAccess(av,opid){
	var _myrow = document.getElementById("dock_rqst_row_"+opid);
	_myrow.style.display = "none";
	dock_ab_popup.autosize();
	var url ="/ixp/resolverequest/?rid="+opid+"&val="+av;
	xg.xhr.get(url,function(resObj){
		
	});
}

function _startShowLogin(){
	var wl = window.location.toString();
	wl = replaceStr(wl,"/#/","/!hash!/");
	wl = replaceStr(wl,"#","!hash!");
	
	window.open("https://heeloo.net/login/n/a/?.done="+wl+"&token=B959205332B548A89EA81497BC23269E.heeloo","_self");
}


function _createUser(){
	var wl = window.location.toString();
	wl = replaceStr(wl,"/#/","/!hash!/");
	wl = replaceStr(wl,"#","!hash!");
	window.open("https://heeloo.net/login/n/a/register/?.done="+wl+"&token=B959205332B548A89EA81497BC23269E.heeloo","_self");
}

try{
document.addEventListener('touchmove', function(e){
 //   dock_menu.style.visibility = "hidden";
     });
}catch(e){}

window.onresize = function(){
    dock_menu_resize();
    win_onresize();
}

window.onscroll = function(e){
    if (dock_isTablet){
    }
}

 function dock_tabletResize(){
 var top = parseInt(parseFloat(document.body.scrollTop)-22);
        dock_menu.style.top = top+"px";
}

document.onscroll = function(e){
    if (dock_isTablet){
     //   var top = parseInt(parseFloat(document.body.scrollTop)-22);
     //   dock_menu.style.top = top+"px";
     //   dock_menu.style.visibility = "visible";
    }
}


