$(document).ready(function(){
  
	//$("img[title]").tooltip({tip: '#demotip', opacity: 0.8, position: "top center"}); 
	
	//right blocks open-close
	$(".nblock_row").click(function(){
		var bl = $(this).parent().parent().attr("id");
		var expires = new Date();
		expires.setDate(expires.getDate()+365);
		
		if ($(this).hasClass("s5")) {
			
			$(this).removeClass("s5");
			$(this).parent().removeClass("nblock_t_close");
			
			$(this).addClass("s6");
			$(this).parent().addClass("nblock_t_open");
			document.cookie = bl + "=0; expires=" + expires.toGMTString() +  "; path=/";
			
		} else {

			$(this).removeClass("s6");
			$(this).parent().removeClass("nblock_t_open");
			
			$(this).addClass("s5");
			$(this).parent().addClass("nblock_t_close");
			document.cookie = bl + "=1; expires=" + expires.toGMTString() +  "; path=/";
		}
		$(this).parent().next().slideToggle(300);
	});
	
	/*var blClosed = Array({panelsOpen});
	for(i=0; i<blClosed.length; i++){
		$("#bl_" + blClosed[i] + " .nblock_row").trigger('click');
	}*/
	
	getBanner();
	//alert(super_banners.length);
	
	/*
	today=new Date(); 
	Future=new Date('January 1, 2010');
	if (today.getTimezoneOffset() == 0) (a=today.getTime() + (4*60*60*1000))
	else (a=today.getTime())
	today.setTime(a)
	b = (Future.getTime() - today) / (24 * 60 * 60 * 1000); 
	rez = Math.ceil(b);
	if (rez > 1) $("#time").html("Дней до Нового года: " + rez);
	else if (rez == 1) $("#time").html("НОВЫЙ ГОД ЗАВТРА!")
	else if (rez <= 0) $("#time").html("С НОВЫМ ГОДОМ!")
	*/
	
	
	
});

function getBanner(){

	if(super_position >= super_banners.length) super_position = 0;

	$("#header2reklama").fadeOut("slow", function () {
	
		var nextTm = super_banners[super_position]['tm'] * 1000;
		var nextCode = super_banners[super_position]['code'];
		
		$("#header2reklama").html( nextCode );
		$("#header2reklama").fadeIn("slow", function () {
		
			super_position ++;
			setTimeout("getBanner()", nextTm);
		});
	});
		
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


//-----------------------------------
//START COMMENTS RATING
//-----------------------------------
function comRate( rate, id ) {
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "go_rate=" + rate;
	ajax.setVar("comm_id", id);
	ajax.setVar("skin", dle_skin);
	ajax.requestFile = dle_root + "engine/ajax/comm_rating.php";
	ajax.method = 'GET';
	ajax.element = 'cratig-layer-' + id;
	ajax.sendAJAX(varsString);
};
//-----------------------------------
// END COMMENTS RATING
//-----------------------------------


//delete message from control panel
function closeCp(cpId, messId) {
	
	wdata = {mid: messId, user_hash: dle_login_hash};
	$.ajax({
		type: "POST",
		url: dle_root+"engine/ajax/mess_delete.php",
		data: wdata,
		success: function(msg) {
		
			//alert('-'+jQuery.trim(msg)+'-');
			$('#cp'+cpId).hide();
			cpId++;
			$('#cp'+cpId).show();
			
		}	
	})
}


function addFriend(uid, fio) {
	//alert(uid + action);
	var agree = confirm("Вы действительно хотите добавить пользователя \n"+fio+" в свой список друзей???");
    if (agree) {
	
   		$('#addfriends_'+uid).load(dle_root+'engine/ajax/addfriends.php', {useradd: uid, user_hash: dle_login_hash});
		//document.location = document.location;
    }
}

function delFriend(uid, fio) {
	//alert(uid + action);
	var agree=confirm("Вы действительно хотите удалить пользователя\n "+fio+" из своего списка друзей???");
    if (agree)	{
	
   		$('#addfriends_'+uid).load(dle_root+'engine/ajax/addfriends.php', {useradd: uid, user_hash: dle_login_hash});
		//document.location = document.location;
    }
    return false;
}


function addFriendConfirm(cpId, messId, otvet) {
	//alert(cpId + ' '+messId+ ' '+otvet);
   	wdata = {mid: messId, user_hash: dle_login_hash, us_otvet: otvet};
	$.ajax({
		type: "POST",
		url: dle_root+"engine/ajax/addfriends_confirm.php",
		data: wdata,
		success: function(msg)
		{
			//alert('-'+jQuery.trim(msg)+'-');
			$('#cp'+cpId).hide();
			cpId++;
			$('#cp'+cpId).show();
			//document.location = document.location;
			
		}	
	})
}