$datepicker.setDefaults({
	changeMonth: true,
	changeYear: true,
	closeText: 'Закрыть',
	prevText: '&#x3c;Пред',
	nextText: 'След&#x3e;',
	currentText: 'Сегодня',
	monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
	'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
	monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
	'Июл','Авг','Сен','Окт','Ноя','Дек'],
	dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
	dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
	dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
	dateFormat: 'dd.mm.yy',
	firstDay: 1,
	isRTL: false
});

$(function(){
	window.setInterval(function (){$.get("../session.php");}, 1000*60);
});


function word(selector){// if(test!=1) alert(selector);
	/*
	if(CSSPATH==""){
		var csspath = "../engine/data/system_skin/style1.css";
	} else {
		var csspath = CSSPATH;
	}/**/
	//var csspath = "../engine/data/system_skin/style1.css";
	
	
	$(selector).tinymce({
		// Location of TinyMCE script
		script_url : '../js/tiny_mce/tiny_mce.js',
		language : 'ru',

		// General options
		theme : "advanced",
		//plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		plugins : "safari,pagebreak,advhr,advimage,advlink,emotions,iespell,inlinepopups,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect,|,fullscreen",
		theme_advanced_buttons2 : "pastetext,pasteword,|,bullist,numlist,|,outdent,indent,|,link,unlink,image,cleanup,code,|,forecolor,backcolor,|,hr,removeformat,|,charmap,|,print",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true

		// Example content CSS (should be your site CSS)
		//content_css : csspath
	});
	$(selector).addClass("tinymce");
}

$(function(){
	/*if(allword){
		word('textarea',1);
	} else {
		word('textarea.word',1);
	}*/
	
	$(".list").addClass("odd");
	$(".list tr").addClass("oddnob");
	$(".list tr:nth-child(odd)").addClass("odd");
	
	/*
	setTimeout(function(){
		$("textarea").each(function(){
			var ths = $(this);
			if(!ths.hasClass("tinymce")){
				if(ths.attr("id")==""){
					ths.attr("id",ths.attr("name"));
				}
				ths.after("<a class='tinymce' href='' rel='"+ths.attr("id")+"'>x</a>");
				ths.parent().children("a.tinymce").click(function(){
					word('#'+ths.attr("id"));
					ths.parent().children("a.tinymce").hide();
					return false;
				});
			}
		});
	},3000);*/
	
	$('textarea').each(function(){
		var textarea = $(this);
		if(textarea.attr("id")==""){
			textarea.attr("id",textarea.attr("name"));
		}
		
		textarea.after("<div><a href='#' id='"+textarea.attr("id")+"_ex'><small>Включить расширенный редактор</small></a></div>");
		$("#"+textarea.attr("id")+"_ex").click(function(){
			word("#"+textarea.attr("id"));
			$(this).parent().fadeOut(function(){
				$(this).html("<a href=\"javascript:;\" onmousedown=\"\$('#"+textarea.attr("id")+"').tinymce().hide();\$(this).fadeOut();\">Убрать редактор</a> ");
				$(this).fadeIn();
			});
		});
	});
	
	
	
	
	window.setInterval(function(){$('a#anews').fadeOut().fadeIn()},2000);
	$('a#anews').click(function(){
		$("body").append("<div id='bnews' style='display:none'></div>");
		var lnk = $(this);
		
		$.get($(this).attr("href"),function(data){
			$('#bnews').html(data);
			
			var ttl = $('#bnews').children("h2").html();
			$('#bnews').children("h2").html("").remove();
			
			$('#bnews').dialog({
				title:ttl,
				bgiframe:true,width:450,height:300,modal:true,
				overlay:{backgroundColor:'#000',opacity:0.8},
				buttons: {
					'OK': function() {
						$(this).dialog('close');
					},
					'Прочитал, больше не показывать': function() {
						$.get(lnk.attr("href")+"&readed",function(){
							var txt = $('a#anews').html();
							$('a#anews')
								.html(txt.substr(0,txt.length-3))
								.css({"color":"white","font-weight":"100"})
								.attr("id","");
						});
						$(this).dialog('close');
					}
				},
				close:function(){
					$(this).dialog('destroy');
				}
			});
		});

		return false;
	});
	
	
});
