var chat_interval;
var md;
function modal_alert(a,b){
	clearTimeout(md);
		$('#modal_win').animate({'top':'-80px'},300,function(){
		$('#modal_win').animate({'top':'0px'});
		$('#modal_img').attr('src','/ico/'+b+'.png');
		$('#modal_text').html(a);
		});
		md=setTimeout("hide_modal_alert();",4000);
}
function hide_modal_alert(){
		
		$('#modal_win').animate({'top':'-80px'});
}
function show_loader(){
		$('#modal_bg_loader').fadeIn(100);
		$('#glob_loader').fadeIn(100);
}
function hide_loader(){
		$('#modal_bg_loader').hide();
		$('#glob_loader').hide();
}
function get_chat_online(){
		$.post('/index.php','get_chat_online=1',function(data){
				$('.onl_chat').text(data.chat_online);
				$('#total_online').text(data.total_online);
				$('.ind_online').text(data.total_online);
		},'json');
}


function chat(){
		$.post('/index.php','get_chat=1',function(data){
			
			
			$("#chat_here").html(data);
		});
}
function chat_send(){
	$('#chat_but').hide();
	$('#chat_but_loader').show();
	var text=$('#chat_text').val();
	$('#chat_text').val('');
	$.post('/index.php','chat_send='+text,function(data){
			if(data=='success'){
					chat();
					$('#chat_scroll').mCustomScrollbar('scrollTo','bottom',{scrollInertia:200});
			}else{
				modal_alert(data,'status_error');
				$.post('/index.php','check_ban=1',function(data){
						if(data=='banned'){
								$('#chat_send_form').html("<center><img src='/ico/banned.png' width=auto height=100><BR><BR><b>à?àÁá?àÅàÍàÈàÅ àÂ à¯à?à€àÅ à?àÀàÌ àÇàÀàÁàËàÎàÊàÈá?àÎàÂàÀàÍàÎ!</b></center><BR><BR>");
						}
				});
			}
	$('#chat_but_loader').hide();
	$('#chat_but').show();

	});
}
function chat_to_us(a){

	nowtext=$('#chat_text').val();
	if(nowtext==''){
			$('#chat_text').val(a+', ');
	}else{
		if(nowtext==a+', ') return false;
		$('#chat_text').val(nowtext+' '+a+', ');
	}

	
}
function open_smilesm(){
		$('#smilesm').fadeIn(500);
}
function close_smilesm(){
		$('#smilesm').fadeOut(300);
}
function open_smiles(){
		$('#smiles').fadeIn(500);
}
function close_smiles(){
		$('#smiles').fadeOut(300);
}
function remove_chat(a){
		$.post('/index.php','remove_chat='+a);
}

		
function open_chat(){
	
	var date = new Date(new Date().getTime() + 86400 * 1000)
	document.cookie = "see_chat=1; path=/; expires=" + date.toUTCString();
	
	$('#chat_scroll').mCustomScrollbar({
				axis: 'y',
				
			});
	$('#chat_here').html('<center><img src="/loader_2.gif"></img></center>');
		$('#chat_button').fadeOut(100,function(){
				$('#chat_block').animate({'margin-left':'-312px'},800);
		});
		
		
		
		$.post('/index.php','get_chat=1',function(data){
			
			
			$("#chat_here").html(data);
			setTimeout("$('#chat_scroll').mCustomScrollbar('scrollTo','bottom',{scrollInertia:200})",1500);
		});
		
		
		chat_interval=setInterval("chat();",2500);
		
				$('#chat_scroll').mCustomScrollbar('scrollTo','bottom',{scrollInertia:200}); 
		
}
	function close_chat(){
		
	var date = new Date(0)
	document.cookie = "see_chat=0; path=/; expires=" + date.toUTCString();
			$('#chat_block').animate({'margin-left':'10px'},400,function(){
					$('#chat_button').fadeIn(100);
			});
			clearInterval(chat_interval);
	}
$(document).ready(function(){
		get_chat_online();
		setInterval("get_chat_online();",120000);
});