/*
 * jQuery UI Effects Bounce 1.8.9
 *
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Effects/Bounce
 *
 * Depends:
 *	jquery.effects.core.js
 */
(function(e){e.effects.bounce=function(b){return this.queue(function(){var a=e(this),l=["position","top","bottom","left","right"],h=e.effects.setMode(a,b.options.mode||"effect"),d=b.options.direction||"up",c=b.options.distance||20,m=b.options.times||5,i=b.duration||250;/show|hide/.test(h)&&l.push("opacity");e.effects.save(a,l);a.show();e.effects.createWrapper(a);var f=d=="up"||d=="down"?"top":"left";d=d=="up"||d=="left"?"pos":"neg";c=b.options.distance||(f=="top"?a.outerHeight({margin:true})/3:a.outerWidth({margin:true})/
3);if(h=="show")a.css("opacity",0).css(f,d=="pos"?-c:c);if(h=="hide")c/=m*2;h!="hide"&&m--;if(h=="show"){var g={opacity:1};g[f]=(d=="pos"?"+=":"-=")+c;a.animate(g,i/2,b.options.easing);c/=2;m--}for(g=0;g<m;g++){var j={},k={};j[f]=(d=="pos"?"-=":"+=")+c;k[f]=(d=="pos"?"+=":"-=")+c;a.animate(j,i/2,b.options.easing).animate(k,i/2,b.options.easing);c=h=="hide"?c*2:c/2}if(h=="hide"){g={opacity:0};g[f]=(d=="pos"?"-=":"+=")+c;a.animate(g,i/2,b.options.easing,function(){a.hide();e.effects.restore(a,l);e.effects.removeWrapper(a);
b.callback&&b.callback.apply(this,arguments)})}else{j={};k={};j[f]=(d=="pos"?"-=":"+=")+c;k[f]=(d=="pos"?"+=":"-=")+c;a.animate(j,i/2,b.options.easing).animate(k,i/2,b.options.easing,function(){e.effects.restore(a,l);e.effects.removeWrapper(a);b.callback&&b.callback.apply(this,arguments)})}a.queue("fx",function(){a.dequeue()});a.dequeue()})}})(jQuery);

/*
 * jQuery UI Effects Explode 1.8.9
 *
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Effects/Explode
 *
 * Depends:
 *	jquery.effects.core.js
 */
(function(j){j.effects.explode=function(a){return this.queue(function(){var c=a.options.pieces?Math.round(Math.sqrt(a.options.pieces)):3,d=a.options.pieces?Math.round(Math.sqrt(a.options.pieces)):3;a.options.mode=a.options.mode=="toggle"?j(this).is(":visible")?"hide":"show":a.options.mode;var b=j(this).show().css("visibility","hidden"),g=b.offset();g.top-=parseInt(b.css("marginTop"),10)||0;g.left-=parseInt(b.css("marginLeft"),10)||0;for(var h=b.outerWidth(true),i=b.outerHeight(true),e=0;e<c;e++)for(var f=
0;f<d;f++)b.clone().appendTo("body").wrap("<div></div>").css({position:"absolute",visibility:"visible",left:-f*(h/d),top:-e*(i/c)}).parent().addClass("ui-effects-explode").css({position:"absolute",overflow:"hidden",width:h/d,height:i/c,left:g.left+f*(h/d)+(a.options.mode=="show"?(f-Math.floor(d/2))*(h/d):0),top:g.top+e*(i/c)+(a.options.mode=="show"?(e-Math.floor(c/2))*(i/c):0),opacity:a.options.mode=="show"?0:1}).animate({left:g.left+f*(h/d)+(a.options.mode=="show"?0:(f-Math.floor(d/2))*(h/d)),top:g.top+
e*(i/c)+(a.options.mode=="show"?0:(e-Math.floor(c/2))*(i/c)),opacity:a.options.mode=="show"?1:0},a.duration||500);setTimeout(function(){a.options.mode=="show"?b.css({visibility:"visible"}):b.css({visibility:"visible"}).hide();a.callback&&a.callback.apply(b[0]);b.dequeue();j("div.ui-effects-explode").remove()},a.duration||500)})}})(jQuery);

/*====================================================
 Author: RooTM
------------------------------------------------------
 Web-site: http://weboss.net/
=====================================================*/

function iChatAdd()
{

if(document.iChat_form.message.value == ''){ 

DLEalert(iChat_lang_null, iChat_lang_title); 

}else{

if(stacksize(document.iChat_form.message.value) >= iChat_max_text){ 

DLEalert(iChat_lang_max, iChat_lang_title); 

}else{

	var message = document.getElementById('message').value;

	ShowLoading('');

	$.post(dle_root + "engine/modules/iChat/ajax/add.php", { message: message }, function(data){

		HideLoading('');

	$("#iChat-messages").fadeOut(500, function() {
			$(this).html(data);
			$(this).fadeIn(500);
	});

	});

	return false;
};

};

};

function iChatEdit(id)
{

ShowLoading('');

$.post(dle_root + "engine/modules/iChat/ajax/edit.php", { id:id, action: "show" }, function(data){

		HideLoading('');

	old_message = data;

DLEprompt(iChat_lang_new_text_msg, old_message, iChat_lang_edit_msg, function (r) {
				if (old_message != r) {

     ShowLoading('');

$.post(dle_root + "engine/modules/iChat/ajax/edit.php", { id:id, action: "save", new_message: r }, function(data){

		HideLoading('');

		$("#iChat-messages").html(data);

	});


				}
	
			});

	});
	
return false;

};


function iChatEditHistory(id)
{

ShowLoading('');

$.post(dle_root + "engine/modules/iChat/ajax/edit.php", { id:id, action: "show" }, function(data){

		HideLoading('');

	old_message = data;

DLEprompt(iChat_lang_new_text_msg, old_message, iChat_lang_edit_msg, function (r) {
				if (old_message != r) {

     ShowLoading('');

$.post(dle_root + "engine/modules/iChat/ajax/edit.php", { id:id, action: "save", new_message: r,place:"history" }, function(data){

		HideLoading('');

		$("#history_c").html(data);

	});

iChatRefresh();
				}
	
			});

	});
	
return false;

};

function iChatDelete(id)
{

DLEconfirm( dle_del_agree, dle_confirm, function () {

	ShowLoading('');

	$.post(dle_root + "engine/modules/iChat/ajax/delete.php", { id: id, place: "site" }, function(data){

	     HideLoading('');

	     $("#iChat-messages").hide('slide',{ direction: "left" }, 500).html(data).show('slide',{ direction: "right" }, 500);

	});

	return false;

} );

};


function iChatDeleteHistory(id)
{

DLEconfirm( dle_del_agree, dle_confirm, function () {

	ShowLoading('');

	$.post(dle_root + "engine/modules/iChat/ajax/delete.php", { id: id, place: "history" }, function(data){

	     HideLoading('');

	     $("#history_c").hide('slide',{ direction: "left" }, 500).html(data).show('slide',{ direction: "right" }, 500);

iChatRefresh();

	});

	return false;

} );

};


function iChatRefresh()
{
	
	$.post(dle_root + "engine/modules/iChat/ajax/refresh.php", { action: "refresh" }, function(data){

		HideLoading('');

		$("#iChat-messages").html(data);

	});

	return false;
};


function iChatPopUpRules( r )
{
	var b = {};

	b["Принимаю"] = function() { 
					$(this).dialog("close");							
			    };

	$("#rules").remove();

	$("body").append(r);

	$('#rules').dialog({
		autoOpen: true,
		show: 'bounce',
		hide: 'explode',
		buttons: b,
		width: 400
	});
	
	return false;
};

function iChatRules()
{
	ShowLoading('');

	$.get(dle_root + "engine/modules/iChat/ajax/rules.php", { action: "rules" }, function(data){

		HideLoading('');

		iChatPopUpRules( data );

	});

	
	return false;
};

function iChatPopUpHistory( r )
{
	$("#history").remove();

	$("body").append(r);

	$('#history').dialog({
		autoOpen: true,
		show: 'blind',
		hide: 'blind',
		width: 300,
           height:410
	});
	
	return false;
};

function iChatHistory()
{
	ShowLoading('');

	$.get(dle_root + "engine/modules/iChat/ajax/history.php", { action: "history" }, function(data){

		HideLoading('');

		iChatPopUpHistory( data );

	});

	
	return false;
};


function iChatPopUpAdmin( r )
{
	var b = {};

	     b["Проверить обновления"] = function() { 
					CheckUpdates(); return false;						
			    };


		b["Очистить БД"] = function() { 
					iChatClearBd(); return false;							
				};


		b["Сохранить настройки"] = function() {
				      SaveCfg(); return false;				
			    };

	$("#ECPU").remove();

	$("body").append(r);

	$('#ECPU').dialog({
		autoOpen: true,
		show: 'slide',
		hide: 'slide',
		buttons: b,
		width: 500
	});
	
	return false;
};

function iChatAdmin()
{

	ShowLoading('');

	$.get(dle_root + "engine/modules/iChat/ajax/admin.php", { action: "show" }, function(data){

		HideLoading('');

		iChatPopUpAdmin( data );

	});

	return false;
};
