
var tid = 0;
var uid = 0;
var jx = null;
var hbx = null;

// cloud
var clUserTO = null;
var clUserDelay = 0;
var clrendFlag = 0;
var clTF = 'last_7_days';

// strm

var typeflag = 0;
var typeTimeOut = null;
var seq = 0;

// newmsg

var nmto = null;
var nms = 0;

var msgs = 0;
var opx = null;
var tx = null;
var tloop = 60;
var floop = 120;
var nloop = 1; 
var timeOut = 5000;
var tSlowStep = 1000;
var t;
var marker = 0;
var extraCount = 0;
var timenow = Date;
var strSuspended = 0;

var uohideTimer = null;
var uohideDelay = 500;  

var tkthid = 0;


var nmLI = '<div class="nmLI"><img src="/imgs/waiting_ani.gif" width="16" height="16"></div>';
var loadIcon = '<div class="loadIcon"><img src="/imgs/waiting_ani.gif" title="loading..." width="16" height="16"></div>';
var userOpinion = $('<div id="uop"><div id="uophead"></div><div id="uopword"></div><div id="uopdate"></div></div>');
 
function rnumb()
{
	return Math.round(new Date().getTime() / 1000);
}

function refreshStream()
{
	clearTimeout(tx);
	strCall(0, 1);
	$('#str_opinion_wrap').html(loadIcon);
}

function updateStream()
{
	$(".str_ucode").empty().remove();

	strCall(1,1);

	var numTalk = $("#str_opinion_wrap > div").size();
	
	if (numTalk>100)
	{
		$("#more_talk").remove();
	}
	
	while (numTalk>100)
	{
		$(".str_op:last").empty().remove();
		numTalk = $("#str_opinion_wrap > div").size();
	}

	$(".str_op[rel='last']").css('border-bottom', '1px solid #EEEEEE');
	$(".str_op[rel='last']").attr('rel', '');

	$(".str_op[rel='fade']").css('border-bottom', '1px dashed #C8CEB3');
	$(".str_op[rel='fade']").attr('rel', 'last');
	
	$(".str_op[rel='new']").css('border-bottom', '1px dashed #AEB88F');
	$(".str_op[rel='new']").attr('rel', 'fade');
}


function userAction(ax, dx, loc, elem)
{
	if (jx)
	{
		jx.abort();
		jx = null;
	}
	 var r = rnumb();
      jx = $.ajax({
          type: 'GET',
          url: '/s/useraction',
         data: 'a=' + ax + '&d=' + dx + '&rnd=' + r,
          success: function(data)
          {
			  
			  if (data.length > 10)
			  {
				  if (loc == 1)
				  {
				    $('#str_wmessage').html(data);
					$('#str_wmessage').slideDown("fast");
					setTimeout(function(){ $('#str_wmessage').slideUp("fast");}, 8000); 
				  }
				else
				  {
					$('.topt_m[rel=' + elem + ']').html(data);	
				  }

			  }
		  }
      });

	 
}



function time_ago(seconds)
{
	var temp = '';
	var temp2 = '';

	if (seconds == 1)
	{
		temp = "1 second ago";
	}
	else if (seconds < 60)
	{
		temp = seconds + " seconds ago";
	}
	else if (seconds < 120)
	{
		temp = "1 minute ago";
	}
	else if (seconds < 3600)
	{
		temp2 = Math.round(seconds/60);
		temp = temp2 + " minutes ago";
	}
	else if (seconds < 7200)
	{
		temp = "1 hour ago";
	}
	else if (seconds < 86400)
	{	
		temp2 = Math.round(seconds / 3600);
		temp = temp2 + " hours ago";
	}
	else if (seconds < 172800)
	{
		temp = "1 day ago";
	}
	else
	{
		temp2 = Math.round(seconds/86400);
		temp = temp2 + " days ago"; 
	}

	return temp;
}


function callback() 
{
	var tSlow;
	var numTalk = $("#str_opinion_wrap > div").size();

	$.each($(".str_subtext"), function(){       
		$(this).html(time_ago((timenow-$(this).attr('rel'))));
		if ((numTalk>40) && ((timenow-$(this).attr('rel'))>300))
		{
			$(this).attr('class','str_subtext_static'); 
			//$(this).html('+5 minutes ago');
		}
	});

	nloop++;
	
	if (strSuspended == 2)
	{
		// then stop
		$('#str_wmessage').html('Stream has been temporarily suspended due to a technical or other problem. Sorry');
		$('#str_wmessage').slideDown("fast");
		
		// disable
		$('#talk').attr('disabled', 'disabled');
		$('#submit').attr('disabled', 'disabled');
		$('#tsu_submit').attr('disabled', 'disabled');
	}
	else
	{
		if (strSuspended == 1)
		{
			$('#talk').attr('disabled', 'disabled');
			$('#submit').attr('disabled', 'disabled');
			$('#tsu_submit').attr('disabled', 'disabled');
			$('#str_wmessage').html('Talking has been temporarily suspended for administrative or technical reasons.');
			$('#str_wmessage').slideDown("fast");
		}
		
		if (nloop < tloop)
		{
			// for x period, refresh quickly
			tx = setTimeout("updateStream();", timeOut);
		}
		else if (nloop < floop)
		{
			// for y period, slow down
			tSlow = timeOut + (tSlowStep*(nloop-tloop));
			tx = setTimeout("updateStream();", tSlow);
		}
		else
		{
			// then stop
			$('#str_wmessage').html('Stream has been paused. Refresh page or talk to restart streaming.');
			$('#str_wmessage').slideDown("fast");
		}
	}
}


	

//	----------- STREAM FUNCTIONS ---------------

function strCall(strf, cb)
{
	if (hbx)
	{
		hbx.abort();
		hbx = null;
	}

	var r = rnumb();
	var dp;
	var dx;

	hbx = $.ajax({
		type: 'GET',
		url: '/s/stream',
        data: 'tid=' + tid + '&strf=' + strf + '&uid=' + uid + '&sr=' + timeOut + '&seq=' + seq + '&tp=' + typeflag + '&nms=' + nms + '&rnd=' + r,
		success: function(data)
		{
			dp = data.split('<<-');
			for ( var x in dp )
			{
				if (dp[x])
				{
					dp[x] = jQuery.trim(dp[x]);
					dx = dp[x].split('->>');
					switch(dx[0])
					{
						case 'talksm':
							talksm(dx[1]);
						break;
						case 'talkut':
							talkut(dx[1]);
						break;
						case 'talkuv':
							talkuv(dx[1]);
						break;
						case 'timeset':
							timeset(dx[1]);
						break;
						case 'seqnce':
							seqnce(dx[1]);
						break;
						case 'talkst':
							talkst(dx[1]);
						break;
						case 'talktio':
							talktio(dx[1]);
						break;
						case 'talkmsg':
							talkmsg(dx[1]);
						break;
						case 'newmsg':
							newmsg(dx[1]);
						break;
					}
				}
			}			
		
			if (msgs)
			{
				msgs = 0;
				$("#submit").attr('value','say');
				$('#submit').removeAttr('disabled');				
			}

			if (cb)
			{
				$('.loadIcon').remove();
				callback();
				
			}
			
		}
	});
}

function talksm(d)
{
	$('#str_opinion_wrap').prepend(d);	
	$('.str_op').slideDown(400);

	if ($('div#str_opinion_wrap div.str_op_t').size() > 0)
	{
		$('.str_op_t').each(function() 
		{
			var that = this; 
			setTimeout(function(){
				$('#str_opinion_wrap').prepend($(that));
				$(that).attr('rel', 'new');										
			},30000);
				
			$('#str_op_wrap_p').prepend($(this));
			$(this).attr("class", 'str_op');
			$(this).slideDown(400);
				  
		});
	}
}

function seqnce(d)
{
	seq = d;
}

function timeset(d)
{
	timenow = d;
}

function talkmsg(d)
{
	$('#str_gmessage').html(d);
	$('#str_gmessage').slideDown("fast");
	setTimeout(function(){ $('#str_gmessage').slideUp("fast");}, 20000);
}

function talkst(d)
{
	strSuspended = d;
}

function talktio(d)
{
	timeOut = d;
}

function talkuv(d)
{
	var vt = '';
	var vr;
	var dx;
	var dp = d.split('&');
	for ( var x in dp )
	{
		if (!dp[x]){ continue; }
		dx = dp[x].split(',');
		vt += '<div class="u_icon">';
		vr = '';
		if (dx[0]!='anonymous')
		{
			vt += '<a href="/u/' + dx[0] + '" class="u_img" title="' + dx[0] + '">';
			vr = '</a>';
		}
		vt += '<img class="userimg"  alt="' + dx[0] + '" title="' + dx[0] + '" src="/pp/' + dx[1] + '" height="24" width="24" />' + vr + '</div>';		
	}

	$("#view_sbx").empty().html(vt);
}

function talkut(d)
{
	if (!d)
	{
		$('#str_typing').slideUp("fast");	
	}
	else
	{
		var vt = '<span class="str_t_text">Currently Typing : </span>';
		var dx;
		var dp = d.split('&');
		for ( var x in dp )
		{
			if (!dp[x]){ continue; }
			dx = dp[x].split(',');
			vt += '<div class="str_t_icon"><img src="/pp/' +  dx[1] + '" width="24" height="24" title="' +  dx[0] + '" /></div>';			
		}
		$("#str_typing").empty().html(vt);
		$('#str_typing').slideDown("fast");
	}
}

function newmsg(d)
{	
	$('#nma_bm').html(d);
	if(!$('#nma_am').is(":visible"))
	{
		$('#nma_am').slideDown("fast");
		nms = 1;
	}
}




//	----------- END STREAM FUNCTIONS ---------------




	
$(document).ready(function()
{
		
	uid = ($('#uid').val())? $('#uid').val() : 0;
	tid = ($('#tid').val())? $('#tid').val() : 0;
	
	if (tid || uid)
	{
		refreshStream();
	}





$("#submit").click(function(){

	clearTimeout(tx);

	if (jx)
	{
		jx.abort();
		jx = null;
	}
	
	var r = rnumb();
	var text = document.getElementById("talk").value;

	if (text == '')
	{
		$('#str_wmessage').html('You need to say something !');
		$('#str_wmessage').slideDown("fast");
		setTimeout(function(){ $('#str_wmessage').slideUp("fast");}, 8000);
	}
	else
	{

		$('#submit').attr('disabled', 'disabled');
		$("#submit").attr('value','sending...');
	

	  jx = $.ajax({
          type: 'GET',
          url: '/s/newtalk',
         data: 'tid=' + tid + '&text=' + encodeURIComponent(text) + '&tkthid=' + tkthid + '&rnd=' + r,
          success: function(data)
          {
			typeflag = 0;
			$('#talk').val('');
			$('.charRem').html('You have 250 characters remaining');
			msgs = 1;
			updateStream();

		
			if (data.length > 10)
			{
				
				$('#str_wmessage').html(data);
				$('#str_wmessage').slideDown("fast");
				setTimeout(function(){ $('#str_wmessage').slideUp("fast");}, 8000); 
			}
			else
			{
				
				$('#str_wmessage').slideUp("fast");
				nloop = 1;
			}

			$('#talk').focus();
			tkthid = 0;
	      }
      });


	}

		

});

$('.str_username').live('mouseover', function()   
{ 
		
	clearTimeout(uohideTimer);
	
	var s = $(this).attr('rel').split(',');

	if (s[0] != '_')
	{
		var pos = $(this).offset();
		var ppy = pos.top-112;
		var ppx = pos.left-40;
				
		userOpinion.css({
				 left: ppx + 'px',
					 top: ppy + 'px'
					});

			
			if (s[0]=='_')
			{
				$('#uophead').html('no opinion given yet');
				$('#uopword').html('');
				$('#uopdate').html('');
			}
			else
			{
				var tago = timenow - s[1];
				$('#uophead').html('gave opinion');
				$('#uopword').html(s[0]);
				$('#uopdate').html(time_ago(tago));
			}
		 
		 userOpinion.css('display', 'block');
	}
});

$('.str_username').live('mouseout', function()   
{ 
	clearTimeout(uohideTimer);
	    
	uohideTimer = setTimeout(function()
	{
		userOpinion.css('display', 'none');	  
	}, uohideDelay);
});

$('#more_talk').live('click', function()   
{ 
	if (hbx)
	{
		hbx.abort();
		hbx = null;
	}
    
	var r = rnumb();
	var seq_f = $(this).attr('rel');
	var numTalk = $("#str_opinion_wrap > div").size();
	
	hbx = $.ajax({
          type: 'GET',
          url: '/s/stream',
         data: 'tid=' + tid + '&strf=2&uid=' + uid + '&seq_f=' + seq_f + '&seq=' + seq + '&dp=' + numTalk + '&rnd=' + r,
          success: function(data)
          {
			$("#more_talk").remove(); 
			$('#str_opinion_wrap').append(data);	
           	$('.str_op').slideDown("slow");
			callback();
          }
	});

	$('#more_talk').html('');	
	$('#more_talk').append(loadIcon);
  
});


$('.topt_r').live('click', function()   
{ 
	var rp = $(this).attr('rel').split(',');
	
	if (!$(this).attr('str_tid'))
	{
		var rpu = rp[0] + ' ';
		$('#talk').focus();
		$('#talk').val(rpu);
		tkthid = rp[1];
	}
	else
	{
		window.location.replace($(this).attr('str_tid') + rp[1]); 
	}
});

$('.topt_th').live('click', function()   
{ 
	if (jx)
	{
		jx.abort();
		jx = null;
	}
    
	var d = $(this).attr('thdest');
	var r = rnumb();

	if ($(this).attr('rel'))
	{
		var dtx = $(this).attr('rel').split(',');

		jx = $.ajax({
          type: 'GET',
          url: '/s/thread',
         data: 'tkthid=' + dtx[0] + '&tid=' + tid + '&rnd=' + r,
          success: function(data)
          {
			$('.' + d + '[rel=' + dtx[1] + ']').html(data);
			$('.topt_th[rel=' + dtx[0] + ',' + dtx[1] + ']').attr('rel', '');
		  }
		});

		$('.' + d + '[rel=' + dtx[1] + ']').html(loadIcon);
		$('.' + d + '[rel=' + dtx[1] + ']').slideDown("fast");
		
		tkthid = 0;
	}	
	
});

$('.topt_mr').live('click', function()   
{ 
	if ($(this).attr('rel'))
	{
		$('.topt_m[rel=' + $(this).attr('rel') + ']').html('Report this message as : <span class="topt_mrs" rel="' + $(this).attr('rel') + '">spam</span> or <span class="topt_mrs" rel="' + $(this).attr('rel') + '">abusive</span> ').slideDown("fast");
	}
});


$('.topt_mrs').live('click', function()   
{ 
		userAction($(this).text(), $(this).attr('rel'), 2, $(this).attr('rel'));
		$('.topt_mr[rel=' + $(this).attr('rel') + ']').attr('rel', '');
});


$('.topt_sh').live('click', function()   
{ 	
	if ($(this).attr('rel'))
	{
		userAction('shine', $(this).attr('rel'), 2, $(this).attr('rel'));
		$('.topt_m[rel=' + $(this).attr('rel') + ']').html('sending...').slideDown("fast");
		$(this).attr('rel', '');		
	}
});


$('.topt_ig').live('click', function()   
{
	if ($(this).attr('tkid'))
	{
		$('.topt_m[rel=' + $(this).attr('tkid') + ']').html('If you ignore this user, you will no longer see any messages from this user and this user will be blocked from following you. <span class="topt_igs" tkid="' + $(this).attr('tkid') + '">ignore</span> or <span class="topt_igs" tkid="' + $(this).attr('tkid') + '">cancel</span>').slideDown("fast");
	}
});

$('.topt_igs').live('click', function()   
{ 
	if ($(this).text() == 'cancel')
	{
		$('.topt_m[rel=' + $(this).attr('tkid') + ']').slideUp("fast").html('');	
	}
	else
	{
		userAction('ignore', $(this).attr('tkid'), 2, $(this).attr('tkid'));
		$('.topt_ig[tkid=' + $(this).attr('tkid') + ']').attr('tkid', '');
	}
});

$('.topt_ur').live('click', function()   
{ 
	$('#str_gmessage').html('You need to register or login to use this feature.');
	$('#str_gmessage').slideDown("fast");
	setTimeout(function(){ $('#str_gmessage').slideUp("fast");}, 5000); 
});


$('.topt_f').live('click', function()   
{ 
	var y =  $(this).html(); 
	var x = $(this).attr('rel');
	var tkid = $(this).attr('tkid');

	var act = 'af';
	var t = 'following';
	var fw = 'normal';
	var c = '#008800';
	var m = 'You are now following this user';

	if (y == 'following')
	{
		t = 'follow';
		fw = 'normal';
		c = '#777777';
		act = 'rf';
		m = 'You are no longer following this user';
	}

	if (y == 'follow request')
	{
		t = 'follow requested';
		m = 'You have requested to follow this user';
	}

	if (y == 'follow requested')
	{
		t = 'follow request';
		fw = 'normal';
		c = '#777777';
		act = 'rf';
		m = 'You are no longer requesting to follow this user';
	}
	
	$('.topt_f[rel=' + x + ']').html(t);
	$('.topt_f[rel=' + x + ']').css('font-weight', fw);
	$('.topt_f[rel=' + x + ']').css('color', c);
	
	$('.topt_m[rel=' + tkid + ']').html(m);
	$('.topt_m[rel=' + tkid + ']').slideDown("fast");

	userAction(act, x, 1, 0);
});


$('.topt_d').live('click', function()   
{ 
	var x = $(this).attr('rel');

	// action delete
	userAction('del', x, 1, 0);

	// remove from screen anyway
	$('#' + x).fadeOut("slow", function(){$('#' + x).remove();});

});


$('.str_op').live('mouseover', function()   
{ 
	$('.topt_wrap', this).css('display','inline');
	$(this).css('background-color','#FFFFFE');
});

$('.str_op').live('mouseout', function()   
{ 
	$('.topt_wrap', this).css('display','none');
	$(this).css('background-color','transparent');
});



$('#talk').keyup(function()
{ 
	var max = 250; 
	clearTimeout(typeTimeOut);
	
	if($(this).val().length > max)
	{ 
		// disable submit

		$('.charRem').html('You have ' + (max - $(this).val().length) + ' characters remaining'); 
		$('.charRem').css('color','#ff3333');
		$('#submit').attr('disabled', 'disabled');
		$('#tsu_submit').attr('disabled', 'disabled');
	}
	else
	{
		// enable submit
		$('.charRem').html('You have ' + (max - $(this).val().length) + ' characters remaining');
		$('.charRem').css('color','#507282');
		$('#submit').removeAttr('disabled');
		$('#tsu_submit').removeAttr('disabled');
	}

	typeflag = 1;
	typeTimeOut = setTimeout(function(){ typeflag=0;}, 8000); 

});



 $('body').append(userOpinion);



	// ------------ NEW MESSAGE CODE -----------------

	$("#nma_am").mouseover(function(){
		if(!$('#nma_bm').is(":visible"))
		{
			$('#nma_bm').empty().html('');	
			$('#nma_bm').append(nmLI);
			$('#nma_bm').slideDown(100);
			
			if (jx)
			{	
				jx.abort();
				jx = null;
			}

			var r = rnumb();
		
			jx = $.ajax({
				type: 'GET',
				url: '/s/nm_check',
				data: 'tid=' + tid + '&nmt=' + $(this).attr('nmt') + '&r=' + r,
				success: function(data)
				{	
					$('#nma_bm').empty().html(data);
				}
			});	



		}
		clearTimeout(nmto);		
	});	

	$("#nma_am,#nma_bm").mouseout(function(){
		nmto = setTimeout(function()
		{ 
			$('#nma_am').slideUp(100); 
			$('#nma_bm').slideUp(100); 
			nms = 0; 
		}, 1000); 
	});

	$("#nma_bm").mouseover(function()
	{
		clearTimeout(nmto);		 
	});


	// ------------ END NEW MESSAGE CODE -------------






	//	----------- STREAM CODE ---------------
	
	$('.str_stgs').live('mousedown', function(){  
		
		var d = $(this).attr('ststg_d');
		var a = $(this).attr('ststg_a');
		var x = $(this).parent();
		
		if (a == 'pause')
		{
			clearTimeout(tx);
			x.attr('class','apr_m_std_sel');
			$(this).attr('ststg_a', 'unpause');
		}
		else if (a == 'unpause')
		{
			callback();
			x.attr('class','apr_m_std');
			$(this).attr('ststg_a', 'pause');
		}
		else
		{
			if (jx)
			{
				jx.abort();
				jx = null;
			}
			jx = $.ajax({
				type: 'POST',
				url: '/s/str_stgs',
				data: 'a=' + a + '&d=' + d,
				success: function(data)
				{	
					refreshStream();
					if (x.attr('class') == 'apr_m_std')
					{
						x.attr('class','apr_m_std_sel');
					}
					else
					{
						x.attr('class','apr_m_std');
					}
				}
			});
		}
	});


	//	----------- END STREAM CODE ---------------




	//	----------- DYNAMIC ACTION CODE ---------------
	
	$('.dyn_action').live('mousedown', function(){  
		if (jx)
		{
			jx.abort();
			jx = null;
		}

		var d = $(this).attr('dyn_var');
		var a = $(this).attr('dyn_type');

		jx = $.ajax({
			type: 'POST',
			url: '/s/dyn_action',
			data: 'a=' + a + '&d=' + d,
			success: function(data)
			{	
				var x = jQuery.trim(data).split("---");
				if (x[0] == 'favs')
				{
					$('#dyn_fav_w').html(x[1]);
					$('#atop_title').html('hello');
				}
				else if (x[0] == 'follow')
				{
					
					$('#dyn_fol_w').html(x[1]);
				}
			}
		});
	});




	//	----------- END DYNAMIC ACTION CODE ---------------
	


	//	----------- POLL CODE ---------------
	
	$('.poll_op_t').live('mousedown', function()
	{  
		if (jx)
		{
			jx.abort();
			jx = null;
		}

		var d = $(this).parent().attr('pvar');

		if (!d)
		{
			$('#poll_nl').slideDown(200);
			return false;
		}

		var x = $(this);
					
		jx = $.ajax({
			type: 'POST',
			url: '/s/poll_cdata',
			data: 'tid=' + tid + '&d=' + d,
			success: function(data)
			{	
				var y = jQuery.trim(data);
				if (y)
				{
					var z = jQuery.trim(y).split("&");
					for ( var a in z )
					{
						if (!z[a]){ continue; }
						var b = jQuery.trim(z[a]).split("-");	
						$('.poll_op_bart[pvar=' + b[0] + ']').html(b[1]);	
						$('.poll_op_bar[pvar=' + b[0] + ']').width(b[2] + 'px');
					}
					
					$('.poll_op_ts').attr('class','poll_op_t');
					$('.poll_op_t').css('background-color','#ffffff');
					x.attr('class','poll_op_ts');
					x.css('background-color','#E4E4CB');
				}			
			}
		});
	});
	
	$('.poll_op_t').live('mouseover mouseout',  function()
	{
		if (event.type == 'mouseover')
		{
			$(this).css('background-color','#E4E4CB');
		} else {
			$(this).css('background-color','#ffffff');		
		}
	});

	//	----------- END POLL CODE ----------


	//	----------- GRAPH CODE ---------------
	
	$('.apr_sp_w').live('mousedown', function(){  
		$('.apr_sp_w[cht=' + $(this).attr('cht') + ']').parent().attr('class','apr_m_std');	
		$(this).parent().attr('class','apr_m_std_sel');
		
		chartData($(this).attr('cht'), $(this).attr('chtf'));			
	});


	function chartData(in_cht, in_chtf)
	{
		var r = rnumb();

		if (jx)
		{
			jx.abort();
			jx = null;
		}
		
		jx = $.ajax({
			type: 'GET',
			url: '/s/' + in_cht,
			data: 'tid=' + tid + '&tf=' + in_chtf + '&rnd=' + r,
			success: function(data)
			{
				var chartObj = getChartFromId(in_cht + '_id');
				//Update it's XML 
			    chartObj.setDataXML(jQuery.trim(data));
			}
		});
	}
   

	//	----------- END GRAPH CODE ---------------
	

	//	----------- CLOUD CODE ---------------

	
	$('.cloudWord').live('mouseover', function()     
	{
		var x = $(this).attr('rel');

		$(this).css('color','#F9A01B');
			
		var r = rnumb();
		
		$('#cwoWrap').css('display', 'none');
		$('#cwoContent').empty();
		 
		clearTimeout(clUserTO);
		clearTimeout(clUserDelay); 

		 var ppwidth = $('#cwoWrap').width();
		 var ppheight = $('#cwoWrap').height()+10;
		 
		 var cwoffset = $('.word_cloud').offset();
		 var cwbottom = cwoffset.top + $('.word_cloud').height();
		 var cwleft = cwoffset.left;
		 var cwright = cwoffset.left + $('.word_cloud').width();

		  var pos = $(this).offset();
		  var width = $(this).width();
		  var height = $(this).height();


		var ppy = 300;
		var ppx = pos.left;

		// if word is too close to bottom then flip to top 
		ppy=(pos.top+height+ppheight < cwbottom)? pos.top + height : pos.top - ppheight; 

		ppx = Math.round((pos.left + (width/2))-(ppwidth/2));
		
		// if word is too close to left or right then bring closer to center
		ppx=(ppx < cwleft)? cwleft : ppx;
		ppx=((ppx+ppwidth) > cwright)? cwright-ppwidth : ppx;

		  $('#cwoWrap').css({
		 left: ppx + 'px',
		 top: ppy + 'px'
		  });
		
		clUserDelay = setTimeout(function()
		 {


		if (jx)
		{
			jx.abort();
			jx = null;
		}
		  
		  jx = $.ajax({
			  type: 'GET',
			  url: '/s/clouduser',
			 data: 'tid=' + tid + '&wmid=' + x + '&rnd=' + r,
			  success: function(data)
			  {
				$('#cwoContent').html(data);		
			  }
		  });

		  
	   $('#cwoWrap').css('display', 'block');
		 $('#cwoContent').html(loadIcon);

		 }, 1000);	
		  
	});

	  


		$('.cloudWord').live('mouseout', function()
		{
			clearTimeout(clUserTO);
			clearTimeout(clUserDelay); 
			
			$(this).css('color','#' + $(this).attr('wcol'));	
			clUserTO = setTimeout(function()
			{
				$('#cwoWrap').css('display', 'none');				  
			}, 500);
		});



		$('.cloudWord').live('mousedown', function()
		{

			var newword = $(this).attr('wval');

			if (jx){
				jx.abort();
				jx = null;
			}
			  
			jx = $.ajax({
				  type: 'POST',
				  url: '/s/cloudaction',
				 data: 'tid=' + tid + '&word=' + encodeURIComponent($(this).attr('wval')),
				  success: function(data)
				  {
				dispMessage(data, 'op_cloud_msg');				
				renderCloud();
				$('#cl_cur_op').html(newword);
			  }
			  });
		});



		$('#cwoWrap').live('mouseover', function()
		{
			clearTimeout(clUserTO);
		});


		$('#cwoWrap').live('mouseout', function()
		{
			clearTimeout(clUserTO);
			clUserTO = setTimeout(function()
			{
				$('#cwoWrap').css('display', 'none');
			}, 500);
		});

		$('.cloud_timeline').live('mousedown', function()
		{
			clTF = $(this).attr('rel');
			$('.cloud_timeline').parent().attr('class','apr_m_std');
			$(this).parent().attr('class','apr_m_std_sel');
			renderCloud();
		});



		$('#cloud_nw_sub').live('mouseover', function()
		{
			$('#cloud_nw_sub').css('background-color','#f7f7f7');
		});
		$('#cloud_nw_sub').live('mouseout', function()
		{
			$('#cloud_nw_sub').css('background-color','#E2E7D8');
		});

		$('#cloud_nw_sub').live('mousedown', function()
		{
			if (jx)
			{
				jx.abort();
				jx = null;
			}
			  
			jx = $.ajax({
				  type: 'POST',
				  url: '/s/cloudaction',
				 data: 'tid=' + tid + '&word=' + encodeURIComponent($('#cloud_nw_inp_f').val()),
				  success: function(data)
				  {
						dispMessage(data, 'op_cloud_msg');
						renderCloud();
						var dataIn = jQuery.trim(data).split("--",2);
						if (dataIn[0] == 'gm')
						{
							$('#cl_cur_op').html($('#cloud_nw_inp_f').val().toLowerCase());
						}
						
				  }
			  });


		});



		function renderCloud() 
		{
			if (jx)
			{
				jx.abort();
				jx = null;
			}
			clearTimeout(clUserTO);
			clearTimeout(clUserDelay); 
			clearTimeout(clrendFlag);
		 
			$('#cwoWrap').css('display', 'none');
			
			var r = rnumb();

			$('.word_cloud').css('min-height', $('.word_cloud').height());

			jx = $.ajax({
				  type: 'GET',
				  url: '/s/cloudrender',
				 data: 'tid=' + tid + '&tf=' + clTF + '&rnd=' + r,
				  success: function(data)
				  {
						clrendFlag = setTimeout(function()
						{
							 $('.word_cloud').html(data);
							
						},500);
				  }
			  });

			$('.word_cloud').html(loadIcon);
		}

	//	----------- END CLOUD CODE ---------------


	// ------------ APP CODE ------------------

	$(".app_link").click(function()
	{
		var x = $(this).attr('app_id');
		var k = $(this).attr('app_type');
		var kv = $(this).attr('app_var');
		
		if ($('#'+x).length == 0)
		{
			var r = rnumb();

			if (jx)
			{
				jx.abort();
				jx = null;
			}
			
			jx = $.ajax({
				type: 'GET',
				url: '/s/app_wrapper',
				data: 'tid=' + tid + '&uid=' + uid + '&x=' + x + '&rnd=' + r,
				success: function(data)
				{
					$('#'+x).html(data);
					if (k=='ch')
					{	
						setTimeout(function()
						{							
							chartData(kv, 'default');							
						},500);						
					}
					else if (k=='cl')
					{
						renderCloud();
					}
					
				}
			});
			
			$('#nw_appblock').css('display','block');
			$('#nw_appblock').prepend('<div class="nw_app_wrapper" id="' + $(this).attr('app_id') + '"><img style="margin:10px" src="/imgs/waiting_ani.gif" title="loading..."  width="16" height="16"></div>');
			$('.nw_app_wrapper').slideDown(200);
			$(this).parent().attr('class','sel_menu');

		}
	});


	$('.app_close').live('click', function()   
	{ 
		var x = $(this).attr('app_id');
		$('#' + x).fadeOut("fast", function()
		{
			$('#' + x).empty().remove();
			if ($("#nw_appblock > div").size() == 0)
			{
				$('#nw_appblock').css('display','none');
			}
		});
		$(".app_link[app_id='" + x + "']").parent().attr('class','std_menu');
	});


	// ------------ END APP CODE ------------------


	// ------------ HOMEPAGE CODE -----------------

	$("#hp_srch_sub").click(function(){
		var x = encodeURIComponent($('#hp_srch_inp_f').val());
		window.location.replace("http://clouwd.com/t/search/0/" + x);
	});	

	$('#hp_srch_sub').hover(function()
	{
		$(this).css('background-color','#f7f7f7');
	}, function()
	{
		$(this).css('background-color','#E2E7D8');		
	});

	// ------------ END HOMEPAGE CODE -------------


	// ----------- GENERIC CODE ------------------
	
	function dispMessage(textIn, textWhere)
	{
		
		var data = jQuery.trim(textIn).split("--",2);
		$('#' + textWhere).css('display','none');
		$('#' + textWhere).html(data[1]);
		
		if (data[0]=='gm')
		{
			$('#' + textWhere).attr('class','gm_wrap');
		}
		else if (data[0]=='bm')
		{
			$('#' + textWhere).attr('class','bm_wrap');
		}
		else
		{
			$('#' + textWhere).attr('class','im_wrap');
		}

		$('#' + textWhere).slideDown(100);
	}


	// ------------- END GENERIC CODE -------------



// end doc ready
});




/* MTW JS */


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/; domain=.clouwd.com";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}





function write_mail(m)
{
	var f = m.replace(/snail/, '&#64;');
	document.write("<a href='&#109;a&#105;&#108;&#116;&#111;&#58;" + f + "'>" + f + "</a>");
}





function sendMessage(towho, what)
{
	document.getElementById(towho).innerHTML = what;	
}



function validateLogin()
{
	var username = document.account_login.username.value;
	var password = document.account_login.password.value;
	var allowed = /[^0-9a-z_@\.\-]/gi;
	var login_message = document.getElementById("login_message");

	if (allowed.test(username))
	{
		login_message.innerHTML="The Username Provided Is Invalid";
		return false;
	}	

	if (username.length === 0)
	{
		login_message.innerHTML="Please Enter A Username";
		return false; 
	}

	if (username.length < 5)
	{
		login_message.innerHTML="The Username Provided Is Too Short";
		return false; 
	}

	if (password.length === 0)
	{
		login_message.innerHTML="Please Enter A Password";
		return false;
	}

	if (password.length < 6 && password != 'lost')
	{
		login_message.innerHTML="The Password Provided Is Too Short";
		return false;
	}

	return true;

}




function validateReset()
{
	var pw1 = document.reset_password.password1.value;
	var pw2 = document.reset_password.password2.value;
	var s_message = document.getElementById("reset_message");
	var spaces = /\s+/;

	if (pw1 != pw2)
	{
		s_message.innerHTML="Passwords Do Not Match !";
		return false;
	}

	if (pw1.length === 0)
	{
		s_message.innerHTML="Please Enter A Password";
		return false;
	}

	if (pw1.length < 6)
	{
		s_message.innerHTML="Password Is Too Short";
		return false;
	}

	if (spaces.test(pw1))
	{
		s_message.innerHTML="No Spaces In The Password Please";
		return false;
	}

	return true;	

}




function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}




function usync(ockid) 
{
	if (ockid != '1')
	{
		createCookie('ck_id', ockid, '365');
	}
	
	createCookie('s_flag', '1', '365');
	createCookie('utc_flag', '1', '365');	
}




$(document).ready(function()
{
	var stTimer = null;
	var r = rnumb();

	$('#simtopics').hover(function()
	{
		var ppx = $(this).offset().left-28;
		var ppy = $(this).offset().top+20;
		var stgs = $(this).attr('rel').split(',');
	
		clearTimeout(stTimer);
			
		$('#stWrap').css({
			left: ppx + 'px',
			top: ppy + 'px'
		});
			
			if (jx)
			{
				jx.abort();
				jx = null;
			}

			 jx = $.ajax({
			  type: 'GET',
			  url: '/s/simtopics',
			 data: 'tid=' + stgs[0] + '&xc=' + stgs[1] + '&r=' + r,
			  success: function(data)
			  {
				$('#stContent').html(data);					
			  }
		  });

			$('#stWrap').css('display', 'block');
			$('#stContent').html(loadIcon);
		
		
	},  
	function()
	{
	  clearTimeout(stTimer);
	 
      stTimer = setTimeout(function()
      {
          $('#stWrap').css('display', 'none');				  
      }, 500);
	});

	
	$('#stWrap').mouseover(function()
	{
		clearTimeout(stTimer);
	});


	$('#stWrap').mouseout(function()
	{
		clearTimeout(stTimer);
		stTimer = setTimeout(function()
		{
			 $('#stWrap').css('display', 'none');			
		}, 500);
	});

	
})


function myspace_share(T, C, U, L)
{
    var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T)
    + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
    window.open(targetUrl);
}




/**
 * FusionCharts: Flash Player detection and Chart embedding.
 * Morphed from SWFObject (http://blog.deconcept.com/swfobject/) under MIT License:
 * http://www.opensource.org/licenses/mit-license.php
*/
if(typeof infosoftglobal == "undefined") var infosoftglobal = new Object();
if(typeof infosoftglobal.FusionChartsUtil == "undefined") infosoftglobal.FusionChartsUtil = new Object();
infosoftglobal.FusionCharts = function(swf, id, w, h, debugMode, registerWithJS, c, scaleMode, lang, detectFlashVersion, autoInstallRedirect){
	if (!document.getElementById) { return; }
	
	//Flag to see whether data has been set initially
	this.initialDataSet = false;
	
	//Create container objects
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	
	//Set attributes for the SWF
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }

	debugMode = debugMode ? debugMode : 0;
	this.addVariable('debugMode', debugMode);

	w=w.toString().replace(/\%$/,"%25");
	if(w) { this.setAttribute('width', w); }
	h=h.toString().replace(/\%$/,"%25");
	if(h) { this.setAttribute('height', h); }

	
	//Set background color
	if(c) { this.addParam('bgcolor', c); }
	
	//Set Quality	
	this.addParam('quality', 'high');
	
	//Add scripting access parameter
	this.addParam('allowScriptAccess', 'always');
	
	//Pass width and height to be appended as chartWidth and chartHeight
	this.addVariable('chartWidth', w);
	this.addVariable('chartHeight', h);

	//Whether in debug mode
	//Pass DOM ID to Chart
	this.addVariable('DOMId', id);
	//Whether to registed with JavaScript
	registerWithJS = registerWithJS ? registerWithJS : 0;
	this.addVariable('registerWithJS', registerWithJS);
	
	//Scale Mode of chart
	scaleMode = scaleMode ? scaleMode : 'noScale';
	this.addVariable('scaleMode', scaleMode);
	
	//Application Message Language
	lang = lang ? lang : 'EN';
	this.addVariable('lang', lang);
	
	//Whether to auto detect and re-direct to Flash Player installation
	this.detectFlashVersion = detectFlashVersion?detectFlashVersion:1;
	this.autoInstallRedirect = autoInstallRedirect?autoInstallRedirect:1;
	
	//Ger Flash Player version 
	this.installedVer = infosoftglobal.FusionChartsUtil.getPlayerVersion();
	
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// Only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		infosoftglobal.FusionCharts.doPrepUnload = true;
	}
}

infosoftglobal.FusionCharts.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { 
			// netscape plugin architecture			
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"  ';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE			
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");			
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	setDataURL: function(strDataURL){
		//This method sets the data URL for the chart.
		//If being set initially
		if (this.initialDataSet==false){
			this.addVariable('dataURL',strDataURL);
			//Update flag
			this.initialDataSet = true;
		}else{
			//Else, we update the chart data using External Interface
			//Get reference to chart object
			var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(this.getAttribute('id'));
			
			if (!chartObj.setDataURL)
			{
				__flash__addCallback(chartObj, "setDataURL");
			}
			
			chartObj.setDataURL(strDataURL);
		}
	},
	//This function :
	//fixes the double quoted attributes to single quotes
	//Encodes all quotes inside attribute values
	//Encodes % to %25 and & to %26;
	encodeDataXML: function(strDataXML){
		
			var regExpReservedCharacters=["\\$","\\+"];
			var arrDQAtt=strDataXML.match(/=\s*\".*?\"/g);
			if (arrDQAtt){
				for(var i=0;i<arrDQAtt.length;i++){
					var repStr=arrDQAtt[i].replace(/^=\s*\"|\"$/g,"");
					repStr=repStr.replace(/\'/g,"%26apos;");
					var strTo=strDataXML.indexOf(arrDQAtt[i]);
					var repStrr="='"+repStr+"'";
					var strStart=strDataXML.substring(0,strTo);
					var strEnd=strDataXML.substring(strTo+arrDQAtt[i].length);
					var strDataXML=strStart+repStrr+strEnd;
				}
			}
			
			strDataXML=strDataXML.replace(/\"/g,"%26quot;");
			strDataXML=strDataXML.replace(/%(?![\da-f]{2}|[\da-f]{4})/ig,"%25");
			strDataXML=strDataXML.replace(/\&/g,"%26");

			return strDataXML;

	},
	setDataXML: function(strDataXML){
		//If being set initially
		if (this.initialDataSet==false){
			//This method sets the data XML for the chart INITIALLY.
			this.addVariable('dataXML',this.encodeDataXML(strDataXML));
			//Update flag
			this.initialDataSet = true;
		}else{
			//Else, we update the chart data using External Interface
			//Get reference to chart object
			var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(this.getAttribute('id'));
			chartObj.setDataXML(strDataXML);
		}
	},
	setTransparent: function(isTransparent){
		//Sets chart to transparent mode when isTransparent is true (default)
		//When no parameter is passed, we assume transparent to be true.
		if(typeof isTransparent=="undefined") {
			isTransparent=true;
		}			
		//Set the property
		if(isTransparent)
			this.addParam('WMode', 'transparent');
		else
			this.addParam('WMode', 'Opaque');
	},
	
	render: function(elementId){
		//First check for installed version of Flash Player - we need a minimum of 8
		if((this.detectFlashVersion==1) && (this.installedVer.major < 8)){
			if (this.autoInstallRedirect==1){
				//If we can auto redirect to install the player?
				var installationConfirm = window.confirm("You need Adobe Flash Player 8 (or above) to view the charts. It is a free and lightweight installation from Adobe.com. Please click on Ok to install the same.");
				if (installationConfirm){
					window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
				}else{
					return false;
				}
			}else{
				//Else, do not take an action. It means the developer has specified a message in the DIV (and probably a link).
				//So, expect the developers to provide a course of way to their end users.
				//window.alert("You need Adobe Flash Player 8 (or above) to view the charts. It is a free and lightweight installation from Adobe.com. ");
				return false;
			}			
		}else{
			//Render the chart
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			// If loaded in IE and scaleMode and width/height specified in %, load the chart using onload event 
			if(  this.getVariable('scaleMode').search(/noscale/i)>=0 &&  
		         ( this.getAttribute('width').search("%")>0 || 
        		    this.getAttribute('height').search("%")>0) )
			{
				//store current object reference
				var obj=this;
				if(window.addEventListener) {
					//add onload event on firefox                                 
			        window.addEventListener("load",function()
                        { n.innerHTML = obj.getSWFHTML(); },false );
				} else if(window.attachEvent) {
					//add onload event on IE
					window.attachEvent("onload", function() 
						{ n.innerHTML = obj.getSWFHTML(); } );
				} else { 
					// if all onload fails fails
					n.innerHTML = this.getSWFHTML();		
				}				
			} else {
				//Normal case. Instantly load the chart
				n.innerHTML = this.getSWFHTML();
			}
			
			//Added <FORM> compatibility
			//Check if it's added in Mozilla embed array or if already exits 
			if(!document.embeds[this.getAttribute('id')] && !window[this.getAttribute('id')])
		      	window[this.getAttribute('id')]=document.getElementById(this.getAttribute('id')); 
				//or else document.forms[formName/formIndex][chartId]			
			return true;		
		}
	}
}

/* ---- detection functions ---- */
infosoftglobal.FusionChartsUtil.getPlayerVersion = function(){
	var PlayerVersion = new infosoftglobal.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new infosoftglobal.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ 
		//If Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
				PlayerVersion = new infosoftglobal.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { 
		// Win IE (non mobile)
		// Do minor version lookup in IE, but avoid Flash Player 6 crashing issues
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new infosoftglobal.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new infosoftglobal.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
infosoftglobal.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
// ------------ Fix for Out of Memory Bug in IE in FP9 ---------------//
/* Fix for video streaming bug */
infosoftglobal.FusionChartsUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// Fixes bug in fp9
if (infosoftglobal.FusionCharts.doPrepUnload) {
	if (!infosoftglobal.unloadSet) {
		infosoftglobal.FusionChartsUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", infosoftglobal.FusionChartsUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", infosoftglobal.FusionChartsUtil.prepUnload);
		infosoftglobal.unloadSet = true;
	}
}
/* Add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}
/* Add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* Function to return Flash Object from ID */
infosoftglobal.FusionChartsUtil.getChartObject = function(id)
{
  var chartRef=null;
  if (navigator.appName.indexOf("Microsoft Internet")==-1) {
    if (document.embeds && document.embeds[id])
      chartRef = document.embeds[id]; 
	else
	chartRef  = window.document[id];
  }
  else {
    chartRef = window[id];
  }
  if (!chartRef)
	chartRef  = document.getElementById(id);
  
  return chartRef;
}
/* Aliases for easy usage */
var getChartFromId = infosoftglobal.FusionChartsUtil.getChartObject;
var FusionCharts = infosoftglobal.FusionCharts;