function __(){try{console.log(__.caller,arguments);}catch(e){}}
function ucfirst(s){return s.charAt(0).toUpperCase()+s.substr(1).toLowerCase();}
function strlimit(_s,_l,_p){
	var s = _s.toString() || '';
	var l = _l || 12;
	var p = _p || '..';
	if( s.length <= l )
		return s;
	return s.substr(0,l-2)+p;
}

function printDate(v, f) {
	var date = f || '%d.%m.%y %H:%M';
	var d = new Date(v*1000);
	var format = {
		'%d': function(){return (d.getDate()<10?'0'+d.getDate():d.getDate())},
		'%m': function(){return (d.getMonth()<9?'0'+(d.getMonth()+1):(d.getMonth()+1))},
		'%y': function(){return d.getFullYear().toString().substr(2)},
		'%Y': function(){return d.getFullYear().toString()},
		'%H': function(){return (d.getHours()<10?'0'+d.getHours():d.getHours())},
		'%M': function(){return (d.getMinutes()<10?'0'+d.getMinutes():d.getMinutes())},
	}
	for (var k in format)
		date = date.replace(new RegExp(k), format[k]());
	return date;
}

function cmsPreview(src, module){return src==''?'/i/cms/no-foto.png':'/f/i/'+module+'/'+src.replace(/\.([a-z]{1,4})$/,'_cms.$1');}
function cmsPicture(icon, module, request){return icon==''?'/i/cms/no-foto.png':'/f/p/'+module+'/'+request+'/'+icon.replace(/\.([a-z]{1,4})$/,'_cms.$1');}

function count( x ) {
	if( typeof x == 'string' )
		return x.length;
	if( typeof x == 'object' ) {
		if( x instanceof Array )
			return x.length;
		else
			return Object.keys(x).length;
	}
	return null;
}


(function($){
	// Atribute REL
	$.fn.rel = function(value){if(value===undefined){return $(this).attr('rel');}else{return $(this).attr('rel', value);}}
})(jQuery);


var getTinyMCE = function(){
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
	    editor_selector : "tinyMCE",
		plugins : "autolink,lists,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,wordcount,advlist,images",
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,print,cleanup,code,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media,images,image",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft,|,insertdate,inserttime,|,preview,fullscreen,|,undo,redo",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		theme_advanced_resize_horizontal : false,
		convert_newlines_to_brs: false,
		//forced_root_block : false,
		//force_br_newlines : true,
		//force_p_newlines : false,
		verify_html : true,
		
		plugin_insertdate_dateFormat : "%Y-%m-%d",
		plugin_insertdate_timeFormat : "%H:%M:%S",
		content_css : "/css/style.css",
		language : "ru",
		remove_linebreaks : true, // удаление лишних пробелов
		doctype : '<!DOCTYPE html>',
		//relative_urls : false,
		convert_urls : false
		//width : '100%',
		//height : '300px'
	});
}
function removeTinyMCE( $p ) {
	$p.find('.tinyMCE').each(function(){
		tinyMCE.get( $(this).attr('id') ).remove();
	});
}
