$(document).ready(function(){
    if($.browser.msie){
        //Configuring ajax
        $.ajaxSetup({
            cache: false
        });
    }
    UpdateTime=1000;

    setInterval(function(){	
			
             getStatusUrl = 'http://www.ekivo.com/getstatus.php?ids='+($('#ids').text());
			 $.ajax({
            url:getStatusUrl,
            dataType: 'json',
            success: function(data){
  lastidvals=($('#lastid').text());
  
  if(data.Clist.id!="0")
  {
 
 $('#lastid').text('');
 $('#lastid').append(data.Clist.id);
  }
 if(lastidvals!=data.Clist.id&&data.Clist.id!="0")
 {
	//$('#classifiedlistlive tbody tr:first').remove();
//	ids=($('#ids').text());
	//$('#ids').text('');
    //$('#ids').html(data.Clist.id+','+ids);
	//$('#classifiedlistlive tbody tr').remove();
	conting="";
	if(data.Clist.contimg)
	{
		conting='<br/><center><img src="classified_attachment/'+data.Clist.contimg+'"  border="0"  width="300" height="300" /> </center>' ;
	}
	var extradata="";
	var favouimg="";
	var repjs="";
	var deljs="";
	if(data.Clist.sessionmid!=0)
	{
		if(data.Clist.lan=='English')
		{
			favouimg='<img src="http://www.ekivo.com/templates/default/images/infav.png"  title="Unfavourite" alt="Unfavourite" width="15" height="15" border="0" />';
			repjs='<img src="http://www.ekivo.com/templates/default/images/reply.png"  title="reply" alt="reply" width="15" height="15" border="0" />';
			deljs='<img src="http://www.ekivo.com/templates/default/images/delete.png"  title="delete" alt="delete" width="15" height="15" border="0" />';
		}
		else
		{
			favouimg='<img src="http://www.ekivo.com/templates/default/images/infav.png"  title="unfavorite" alt="unfavorite" width="15" height="15" border="0" />';
			repjs='<img src="http://www.ekivo.com/templates/default/images/reply.png"  title="Repondre" alt="Repondre" width="15" height="15" border="0" />';
			deljs='<img src="http://www.ekivo.com/templates/default/images/delete.png"  title="Supprimer" alt="Supprimer" width="15" height="15" border="0" />';
			
		}
		
		if(data.Clist.favorites!="")
		{
			extradata='<a href="javaScript:unfavourite('+data.Clist.id+');">'+favouimg+'</a>';
		}
		else
		{
			extradata='<a href="javaScript:favourite('+data.Clist.id+');">'+favouimg+'</a>';
		}
		if(data.Clist.sessionmid!="0")
		{
			extradata=extradata+'<a href="replytoclassified.php?reply='+data.Clist.username+'&replyto='+data.Clist.id+'">'+repjs+'</a>';
			if(data.Clist.sessionmid==data.Clist.mid)
			{
				extradata=extradata+'<a href="javascript:deleteclassified('+data.Clist.id+');"><span class="link_10">'+deljs+'</span></a>';
			}
		}
	}
	
	var row = '<tr><td width="13" align="left" valign="top">&nbsp;</td><td width="661" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top" style="padding-top:36px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="8" align="left" valign="top">&nbsp;</td><td width="67" align="left" valign="top" style="padding-top:5px;"><img src="images/'+data.Clist.image+'" width=51 height=54  border="0"  /></td><td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top" class="Light13 Gray_1 link_2" style="padding:2px 0px 2px 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="100%" align="left" valign="top"><strong><span class="Red">'+data.Clist.username+'</span></strong><span style=" margin-left:3px; margin-right:3px; background-color:'+data.Clist.color+'; color:#FFFFFF; padding-left:5px; padding-right:5px;"><strong>'+data.Clist.classified_type+'</strong></span>'+data.Clist.classified_content+conting+'</td></tr></table></td></tr></table></td></tr><tr><td align="left" valign="top" class="link_3 Light12 Blue_1">'+data.Clist.added_date+'&nbsp;<a href="#">(All replies)</a></td></tr></table></td></tr></table></td></tr><tr><td height="19" align="right" valign="top" class="link_4" style="padding-right:15px;">'+extradata+'&nbsp;<a href="#">Views ('+data.Clist.views+')</a></td></tr><tr><td height="1" align="left" valign="top" class="BgGray"></td></tr></table></td><td width="16" align="left" valign="top">&nbsp;</td></tr>';
	//$('#classifiedlistlive tbody').append(row);
	//$('#classifiedlistlive tbody tr:first').text('');
	
	 $('#classifiedlistlive tr:first').before(row);
	 
	 
 $('#classifiedlistlive tr:first').animate( { backgroundColor: '#D9F0FF' }, 500).animate( { backgroundColor: '#f8f8f8' }, 1000);
 $('#classifiedlistlive tr:last').remove();
 //              
                            
 }}
        });
    }, UpdateTime);
});