function wpaq_add(c, d) {
    if (!window.comments) window.comments = {};
    var i, e, a, b;
    for (i in c) {
        comments[i] = c[i];
        e = document.getElementById(i);
        if (e) {
            a = i.indexOf('_') + 1;
            if (a > 0) b = i.indexOf('_', a);
            if (b > -1) i = i.substring(a, b);
            e.style.backgroundImage = 'url(' + (d[i] ? avatars_path + i + '-t.jpg' : default_image_t) + ')';
        }  
        e = document.getElementById(i+"_eventView")
        if (e) {
            a = i.indexOf('_') + 1;
            if (a > 0) b = i.indexOf('_', a);
            if (b > -1) i = i.substring(a, b);
            e.style.backgroundImage = 'url(' + (d[i] ? avatars_path + i + '-t.jpg' : default_image_t) + ')';
        }  
    }
} 

function wpaq_onmouseover(elm, avatarlist, displaylist,textlist) {
    var e = window.viewelm;

    if (!window.viewelm) {
        e = window.viewelm = document.createElement('div');
        e.id = 'wpaq_view';
        document.body.appendChild(e);
    }
    var id = elm.id.replace("_eventView","");
    var text = comments[id];
    if (text) {
        var x = 0, y = 0;
        for (var p = elm; p; p = p.offsetParent) { x += p.offsetLeft, y += p.offsetTop; }
        e.style.left = (x + 15) + 'px';
        e.style.top = (y + 15) + 'px';
        e.style.visibility = 'visible';
        e.innerHTML = "";
        
        var close_onclick = function() { 
        	e.style.visibility = 'hidden';
        }
        dc = document.createElement('div');
        dc.style.textAlign = "right";
        dc.onclick = close_onclick;
        dc.id = 'wpaq_close_button';

        e.appendChild(dc);
        
        var comment_original = window.comments[id];
			comment_original = comment_original.split("|*|");
			for (i = 0; i < comment_original.length; i++) {
			  	 d = document.createElement('div');
			     var content = comment_original[i].split("@", 2);
				 img = document.createElement('img');
				 img.src = avatarlist[content[0].split("_")[0]] ? (avatars_path + content[0].split("_")[0] + '-s.jpg') : default_image_s,
				 img.width = img.height = '32';
				 d.appendChild(img);
                 s = document.createElement('span');
                 s.innerHTML = displaylist[content[0].split("_")[0]] + ":&nbsp;" + (content[1] ? content[1] : ""),
                 d.appendChild(s);
			     e.appendChild(d);
	       
		         if (i == 0 && comment_original.length > 1) {
		        	ds1 = document.createElement('div');
		        	ds1.className = 'wpaq_btns_seperator';
		        	ds1.innerHTML = textlist["recent_response"];
		        	e.appendChild(ds1);
		         } 
		    }
		    if (typeof(is_single) != 'undefined' && user_id) {
		        var submit_inlineRemark = function() {
			     	updateAvatar = function (resp) {
			     	    if (resp.val[0]) {
			     		    var avatar_exist = resp.val[0]['avatar_exist'];
	                        if (avatar_exist) {
                                avatarlist[user_id] =1; 
	                        }
			     		}
			     	 } 
			     	 var comments_id = id;
                     comments[comments_id] = window.comments[comments_id] + "|*|" + user_id + "_" + (new Date()).getTime() + "@" + document.getElementById("submit_inlineRemark").value;
                     var p = "";
                     for (var i in comments) {
                          if (!p) p = "{"; else p += ",";
                          p += '\"' + i + '\":\"' + comments[i].replace(/\"/g, '\\\\\"').replace(/\\n/g, '\\\\n').replace(/\\r/g, '\\\\r').replace(/\\t/g, '\\\\t') + '\"';                                                      
                     }
                     if (p) p += "}";   
                     xmlrpc("gaga.updateInlineRemark",[current_postid,p,user_id], 1, updateAvatar);
                     window.viewelm.style.visibility = 'hidden';
				}
		    	response_seperator = document.createElement('div');
	            response_seperator.className = 'wpaq_btns_seperator';
			    response_seperator.innerHTML = textlist["your_response"];
		        send = 	document.createElement('div');
		        send.id = 'inlineRemark_response';	    
		        send.innerHTML = "<input type='text' id='submit_inlineRemark' />";    
		        submit_btn = document.createElement('span');
		        submit_btn.className = 'wpaq_editimgbtn';
		        submit_btn.onclick = submit_inlineRemark;
		        submit_btn.innerHTML = textlist["sendtext"];
		        send.appendChild(submit_btn);
		        e.appendChild(response_seperator);
		        e.appendChild(send);
		    }
    }
}


