//alert('bubbles');
var timeWait=200;
var imgLoaderUrl='../wp-content/plugins/cy-custom-types/images/ajax-loader2.gif';
var add_check='bubbleon';
var add_check_set='bubbleset';
var current_bubble_obj=false;
var add_animationDuration=250;
jQuery(document).ready(function(){
//jQuery("img.avatar").livequery('click',function(){alert('test');});
	jQuery("img.avatar").live('mouseover',function(){
		if(!this.id){
			var dataObj=new Date();
			this.setAttribute('id','id_'+dataObj.getTime());
		}
		if(document.getElementById(this.id)!=this){//Duplicates
			var dataObj=new Date();
			this.setAttribute('id',this.id+'_'+dataObj.getTime());
		}
		var this_id=this.id;
		var popup_id="tip_popup_"+this.id;
		var html_append='<div id="'+popup_id+'" style="display:none;overflow:hidden;"></div>';
		jQuery('body').append(html_append);
		var j_popup_obj=jQuery("#"+popup_id);
//alert(j_popup_obj.tagName);
		j_popup_obj.html('<img src="'+imgLoaderUrl+'" />');
		var j_this=jQuery(this);
		j_this.attr(add_check,add_check);
		if(!j_this.attr(add_check_set)){
			//var bubble_obj=j_this.bubbletip(j_popup_obj,{'deltaDirection':'right','calculateOnShow':true,'bindShow':'mouseenter','bindHide':'mouseleave'});
			var bubble_obj=j_this.bubbletip(j_popup_obj,{'deltaDirection':'right','bindShow':'mouseenter','bindHide':'mouseleave'});
			j_this.attr(add_check_set,add_check_set);
			bubble_obj.trigger('mouseenter');//First time to be activated
			//Here j_this mouseover|mouseenter is broken
			j_this.mouseenter(function(){
				jQuery(this).attr(add_check,add_check);
				setTimeout('getBubbleContent("'+this.id+'","'+popup_id+'")',300);
			});
			j_this.mouseleave(function(){
//alert(add_check+' zzz '+j_this.attr(add_check));
				jQuery(this).removeAttr(add_check);
			});
		}
		//j_this.addClass(class_add);//break jQuery live

		setTimeout('getBubbleContent("'+this.id+'","'+popup_id+'")',100);
		
	});
});
function getBubbleContent(this_id,popup_id){
		//var this_id=j_this.attr('rel');
		//var this_id=j_this.attr('id');
		//var this_id=id;
		var j_this=jQuery('#'+this_id);
//console.log(add_check+' zzz '+this_id);
//alert(add_check+' zzz '+j_this.attr(add_check));
		if(!j_this.attr(add_check)){return;}
		if(typeof window['bubble_mouseenter_set_'+this_id]!='undefined'){return;}
		window['bubble_mouseenter_set_'+this_id]=1;
		var j_popup_obj=jQuery("#"+popup_id);
		var m_re=/user\-(\d+)\-avatar/;
		var arr_m;
		var info_id='';
		if(arr_m=this_id.match(m_re)){
			if(arr_m.length){
				info_id=arr_m[1];
			}
		}
		if(!info_id){return;}

		do_action='rel_action';
		do_type='act_profile_info';
		//alert('zzz');
		
		
		jQuery.ajax({
			'url':ajaxurl,
			'data':({
				'action':do_action,
				'id':info_id,
				'cookie':encodeURIComponent(document.cookie),
				'_wpnonce':bubble_wpnonce,
				'do_type':do_type
			}),
			'dataType': "html",
			'success':function(data){
				var j_popup_obj=jQuery("#"+popup_id);
				//var in_popup=j_popup_obj.attr(add_check);
				//j_popup_obj.html(data);
				j_this=jQuery("#"+this_id);
				var found_parent=j_popup_obj.parent();
				//Until found table
				//Can use .parentsUntil( [ selector ] ) from 1.4 version of jQuery
				while(found_parent&&((!found_parent.get(0).tagName)||(found_parent.get(0).tagName.toLowerCase()!='table'&&found_parent.get(0).tagName.toLowerCase()!='body'))){
					found_parent=found_parent.parent();
				}

				found_parent.animate({left:'+=10px','opacity':0},250,'swing',function(){
					j_popup_obj.html(data);
					var left_pos=found_parent.css('left');
					left_pos=(left_pos.replace('px','')-20)+'px';
					found_parent.css({'width':'250px','height':'auto','left':left_pos});
					found_parent.animate({left:'+=10px','opacity':1},250,'swing');
				});

			}
			//,'error':function(XMLHttpRequest, textStatus, errorThrown){
			//	alert(textStatus);
			//}
		});
}

