/**
 * This method calls the webservice to check whether the selected managed stream
 * has a workflow of broadcasting, and if it is registered, then create an 
 * activity record and wait until coast is clear
 */
var delayBeforeRefreshingList = 5000;

function getChatOperators() {
	$.ajax(
		{
			type: 'GET',
			url: 'ws/lookupChatOperators.jsp?v=' + new Date().getTime(),
			dataType: 'xml',
			timeout: 10000,
			success: function(xml) {
						// Check whether an error has occured looking up the token status
						var statusOfResponse = $(xml).find('response').attr('status');					
						if (statusOfResponse == "response") {
							// No error has start processing the girls...
							var $number_girls = 0;
							// Find each node which represents a girl
							$(xml).find('chatoperator').each(function(){
                        		$number_girls = $number_girls + 1;
	                       		if ($number_girls <= 12 ) {
	                        		// get the data and update the elements in the dom		
	                        		var $id_text = $(this).attr('id');
	                         		var $server_text = $(this).attr('server');
	                         		var $name_text = $(this).find('name').text();
	                         		var $img_url_text = $(this).find('image').text();                         		
	                         		var $status_text = $(this).find('status').text();	                         		
									$("#img_"+$number_girls).attr("src", $img_url_text);
									$("#name_"+$number_girls).text($name_text);
									if ($status_text == 'available') {
										$("#status_"+$number_girls).attr("src", "images/available.png");	
									} else if ($status_text == 'busy') {
										$("#status_"+$number_girls).attr("src", "images/busy.png");		
									} else if ($status_text == 'offline') {
										$("#status_"+$number_girls).attr("src", "images/offline.png");	
									} else if ($status_text == 'queue') {
										$("#status_"+$number_girls).attr("src", "images/chatting.png");	
									}
									$("#link_"+$number_girls).attr("href", 'chat.jsp?SUID='+$id_text+'&env='+$server_text);
	                       		}							
							});							
							setTimeout("getChatOperators()", delayBeforeRefreshingList);	//Javascript's delay timer for 5000 miliseconds
						} else {
							// Simply try again later
							setTimeout("getChatOperators()", 15000);	//Javascript's delay timer for 5000 miliseconds
						}
					},
			error: function() {
				setTimeout("getChatOperators()", delayBeforeRefreshingList);	//Javascript's delay timer for 5000 miliseconds
			}
		}
	);	
}

function processSelectionOfRSU(pBlockNumber) {
	
	/**
	 * 		[1 ][2 ][3 ]		Each Block is sized 179x168 px
	 * 		[4 ][5 ][6 ]		Each Block has - a picture sized 176x144 px			   
	 * 		[7 ][8 ][9 ]					   - a caption sized 176x20 px
	 * 		[10][11][12]		- Each block is seperated by 8px wide and 7px high
	 */
	
	if ($.browser.msie && $.browser.version.substr(0,1) <= "7") {
        // Do not fade since IE7 and lower does not do fading very well
	} else {
		switch (pBlockNumber) {
			case 1:
				break;
			case 2:
				$('#div_'+pBlockNumber+'_loading').animate({ left: "185px"}, 0 );
				break;
			case 3:
				$('#div_'+pBlockNumber+'_loading').animate({ left: "370px"}, 0 );
				break;
			case 4:
				$('#div_'+pBlockNumber+'_loading').animate({ top: "210px"}, 0 );
				break;
			case 5:
				$('#div_'+pBlockNumber+'_loading').animate({ top: "210px", left: "185px"}, 0 );
				break;
			case 6:
				$('#div_'+pBlockNumber+'_loading').animate({ top: "210px", left: "370px"}, 0 );
				break;
			case 7:
				$('#div_'+pBlockNumber+'_loading').animate({ top: "420px"}, 0 );
				break;
			case 8:
				$('#div_'+pBlockNumber+'_loading').animate({ top: "420px", left: "185px"}, 0 );
				break;
			case 9:
				$('#div_'+pBlockNumber+'_loading').animate({ top: "420px", left: "370px"}, 0 );
				break;
			case 10:
				$('#div_'+pBlockNumber+'_loading').animate({ top: "635px"}, 0 );
				break;
			case 11:
				$('#div_'+pBlockNumber+'_loading').animate({ top: "635px", left: "185px"}, 0 );
				break;
			case 12:
				$('#div_'+pBlockNumber+'_loading').animate({ top: "635px", left: "370px"}, 0 );
				break;
		}
		
		$('#div_'+pBlockNumber+'_loading').fadeIn('fast');
	}
}

$(function(){
	setTimeout("getChatOperators()", delayBeforeRefreshingList);
});