
$('a[qtip]').live('mouseover', function(event) {
   // Bind the qTip within the event handler
	$(this).qtip({
		overwrite: false, // Make sure the tooltip won't be overridden once created
		content: {
			// Set the text to an image HTML string with the correct src URL to the loading image you want to use
			text: 'Loading...', // Loading text...
			ajax: {
				url: '/wp-content/themes/glimstedt/json_respond_popup.php' + window.location.search, // URL to the JSON script
				type: 'POST', // POST or GET
				data: { id: $(this).attr('id'), name: $(this).attr('name') , office: $(this).attr('office'), officephone: $(this).attr('officephone')}, // Data to pass along with your request
				dataType: 'json', // Tell it we're retrieving JSON
				once: true,
				cache: false,
				success: function(data, status) {
					/* Process the retrieved JSON object
					*	Retrieve a specific attribute from our parsed
					*	JSON string and set the tooltip content.
					*/
														
					var staffName = (!data.name) ? "" : data.name;
					var worktitle_sv = (!data.gertrud_staff_worktitle_sv) ? "" : data.gertrud_staff_worktitle_sv;
					var worktitle_en = (!data.gertrud_staff_worktitle_en) ? "" : data.gertrud_staff_worktitle_en;
					var privatePhone = (!data.gertrud_staff_privatephone) ? "" : data.gertrud_staff_privatephone;
					var cellPhone = (!data.gertrud_staff_cellphone) ? "" : data.gertrud_staff_cellphone;
					var officePhone = (!data.officephone) ? "" : data.officephone;
					var staffEmail = (!data.gertrud_staff_email) ? "" : data.gertrud_staff_email;
					var staffPhoto = (!data.gertrud_staff_onephoto) ? "" : '<img src="'+ data.thephoto[0] +'" alt="" width="'+data.thephoto[1]+'px" height="'+data.thephoto[2]+'"/>';
					
					
					var lang = window.location.search;
					var worktitle = (lang == "?lang=en") ? worktitle_en : worktitle_sv;
					var cellPhoneLabel = (lang == "?lang=en") ? "Mobile: " : "Mobil: ";
					var phoneLabel = (lang == "?lang=en") ? "Phone direct: " : "Telefon direkt: ";
					var officePhoneLabel = (lang == "?lang=en") ? "Phone: " : "Växel: ";
					var emailLabel = (staffEmail == "") ? "" : "E-mail: ";
					
					cellPhoneLabel = (cellPhone == "") ? "" : cellPhoneLabel;
					phoneLabel = (privatePhone == "") ? "" : phoneLabel;
					officePhoneLabel = (officePhone == "") ? "" : officePhoneLabel;

					var content = '<div class="ui-tip-textbox"><p class="textboxtitle purpletext">' + staffName + '</p>'+ worktitle + '<br /> <br />' + officePhoneLabel + officePhone + '<p> ' + phoneLabel  + privatePhone + '</p><p>' + cellPhoneLabel + cellPhone +  '</p><p>' + emailLabel + staffEmail + '</p><p>' + data.office + '</p></div> <div class="ui-tip-photobox">' + staffPhoto + '</div>';

					this.set('content.text', content);
				}
			}
		},
		
		position: {
			at: 'bottom left', 
			my: 'top right',
			/*target:'mouse',*/
			viewport: $(window) 
		},
		
		style: {
			classes: 'ui-tooltip-light ui-tooltip-shadow ui-tooltip-rounded',
			tip: {
				
			}
		},
		
		
		
		show: {
			solo: true,
			delay: 500,
			event: event.type, // Use the same show event as the one that triggered the event handler
			ready: true // Show the tooltip as soon as it's bound, vital so it shows up the first time you hover!
		}
		
		
		
		
	}, event); // Pass through our original event to qTip
})
 

.each(function(i) {
   //$.attr(this, 'oldtitle', $.attr(this, 'title'));
   //this.removeAttribute('title');
});
