jQuery(document).ready(function(){		window.skypenames = [];	jQuery('.skypestatus').each(function(index) {		// Collect skypenames. It's actually not only skypenames but "skypename:action"		skypenames[index] = jQuery(this).attr("title");	});		updateTitles();
	updateStatus(window.skypenames);	
});
function updateStatus(skypenames){		//Send skypenames and actions with ajax and get updated HTML in return.
	jQuery.get(SkypeCustomImages.ajaxurl,{
		action:'sci_ajax',
		skypenames:skypenames
	}, function(status_array){
		//Update the icon accordingly		jQuery.each(status_array, function(item) {			var statusHTML_new = status_array[item];			var statusHTML_object = jQuery('[title="'+item+'"]');			jQuery('*',statusHTML_object).removeAttr("title");			var statusHTML_old = statusHTML_object.html();			if (statusHTML_new != statusHTML_old){				statusHTML_object.html(status_array[item]);			}					});		updateTitles();		
		if (SkypeCustomImages.interval >= 0) setTimeout('updateStatus(window.skypenames)', SkypeCustomImages.interval);
	}, "json");		updateIntegrated();	
 
}//Update all titlesfunction updateIntegrated(){	var widget = jQuery('.widget_integrated');	if (widget.exists()) {						var img_skypeme = jQuery('[alt="7"]', widget).first();		var img_online = jQuery('[alt="2"]', widget).first();		var img_away = jQuery('[alt="3"]', widget).first();		var img_dnd = jQuery('[alt="5"]', widget).first();		var img_notavailable = jQuery('[alt="4"]', widget).first();				//Hide what we have currently		jQuery('.sk_widget', widget).hide();		//Now show the one that's online etc.		if (img_skypeme.exists()) img_skypeme.parent().parent().show();		else if (img_online.exists()) img_online.parent().parent().show();		else if (img_away.exists()) img_away.parent().parent().show();		else if (img_dnd.exists()) img_dnd.parent().parent().show();		else if (img_notavailable.exists()) img_notavailable.parent().parent().show();		else jQuery('.sk_widget', widget).first().show();	}}//Update all titlesfunction updateTitles(){	jQuery('.skypestatus').each(function(index) {		var visible_name = jQuery(this).attr("data-visible_name");		//Get action		var a = jQuery(this).children();		if(a.exists()){			a = a.attr("href");			var action = a.substring(a.indexOf('?')+1);						//Get skypename			var skypename = a.substring(6, a.indexOf('?'));						var visible_title = '';						switch (action) {				case 'call': visible_title = "Call "+visible_name+" ("+skypename+")"; break;				case 'chat': visible_title = "Chat with "+visible_name+" ("+skypename+")"; break;				case 'add':  visible_title = "Add "+visible_name+" ("+skypename+") to skype"; break;				case 'userinfo': visible_title = "View "+visible_name+" ("+skypename+") profile info"; break;				case 'voicemail':visible_title = "Leave "+visible_name+" ("+skypename+") a voicemail"; break;				case 'sendfile':visible_title = "Send "+visible_name+" ("+skypename+") a file"; break;			}						jQuery(this).children().attr("title",  visible_title );		}	});}
jQuery.fn.exists = function(){return this.length>0;}

