var TintMCE_loaded = false;
var TintMCE_settings = {
	// Location of TinyMCE script
	script_url : 'http://www.dovolenkasdetmi.sk/application/editor/tiny_mce.js',

	// General options
	disk_cache : true,  
	debug : false,  
	language : "sk",
	mode : "none",
	theme : "advanced",
	skin : "o2k7",
	skin_variant : "silver",
	entity_encoding : "raw",
	forced_root_block : false,
	force_br_newlines : false,
	force_p_newlines : true,
	add_unload_trigger : true,
	nonbreaking_force_tab : true,
	apply_source_formatting : true,
	plugin_insertdate_dateFormat : "%d.%m.%Y",
	plugin_insertdate_timeFormat : "%H:%M:%S",
	plugins : "save,pagebreak,style,layer,table,advhr,advlink,emotions,inlinepopups,insertdatetime,searchreplace,contextmenu,paste,visualchars,nonbreaking,xhtmlxtras,template,advlist,fullscreen,preview,print,iespell,directionality,noneditable,safari,spellchecker",
	extended_valid_elements : "iframe[align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width|id|class],div[class|id|title|align|style|onclick],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],form[name|id|action|method|enctype|accept-charset|onsubmit|onreset|target],input[id|name|type|value|title|size|maxlength|checked|accept|src|width|height|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|onclick|class|style],textarea[id|name|rows|cols|title|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|style|class],option[name|id|value],select[id|name|type|value|size|maxlength|checked|accept|src|width|height|class|style|disabled|readonly|tabindex|accesskey|onfocus|onblur|onchange|onselect|length|options|selectedIndex],script[src|type|language],fieldset[style],legend[style],img[src|alt|width|height|border|rel|style|class],fb:fan[fan|profile_id|stream|connections|logobar|width]",
	entities : "160,nbsp,38,amp,34,quot,162,cent,8364,euro,163,pound,165,yen,169,copy,174,reg,8482,trade,8240,permil,60,lt,62,gt,8804,le,8805,ge,176,deg,8722,minus",

	// Theme options
	theme_advanced_buttons1 : "",
	theme_advanced_buttons2 : "link,unlink,|,hr,advhr,charmap,nonbreaking,|,bullist,numlist,|,tablecontrols",
	theme_advanced_buttons3 : "styleprops,|,bold,italic,underline,sub,sup,|,styleselect,formatselect,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,|,forecolor,backcolor",
	theme_advanced_buttons3_add : "jmformcontrols",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : false,
	theme_advanced_resize_horizontal : false,

	// Example content CSS (should be your site CSS)
	content_css : "../templates/defaults.css",

	// Drop lists for link/image/media/template dialogs
	template_external_list_url : "lists/template_list.js",
	external_link_list_url : "lists/link_list.js",
	external_image_list_url : "lists/image_list.js",
	media_external_list_url : "lists/media_list.js",
	flash_external_list_url : "lists/flash_list.js",

	file_browser_callback : "fileBrowserCallBack",

	// Replace values for the template plugin
	template_replace_values : {
		username : "Some User",
		staffid : "991234"
	}
};

function fileBrowserCallBack(field_name, url, type, win) {
		var connector = "../../../manager/file_manager.php";

		my_field = field_name;
		my_win = win;

		switch (type) {
			case "image":
				connector += "?type=image";
				break;
			case "media":
				connector += "?type=media";
				break;
			case "file":
				connector += "?type=file";
				break;
		}

		window.open(connector, "file_manager", "width=700,height=520");
}

function init_editor(id, w, h, tp) {
	if (typeof(tp) == 'undefined') {
		tp = 'editor';
	}
	w = (typeof(w) != 'undefined' ? (w < 570 ? 570 : w) : 570);
	h = (typeof(h) != 'undefined' ? (h < 300 ? 300 : h) : 300);
	if (tp == 'module') {
		TintMCE_settings.theme_advanced_buttons1 = "undo,redo,|,cut,copy,paste,pastetext,pasteword,|,search,replace,|,cleanup,removeformat,|,visualaid,visualchars,|,fullscreen,|,code";
	} else {
		TintMCE_settings.theme_advanced_buttons1 = "save,newdocument,|,undo,redo,|,cut,copy,paste,pastetext,pasteword,|,search,replace,|,cleanup,removeformat,|,visualaid,visualchars,|,fullscreen,|,code";
	}
	remove_editors();
	$("#"+id).addClass('mceEditor');
	$("#"+id).css("width", w);
	$("#"+id).css("height", h);
	$("#"+id).tinymce(TintMCE_settings);
	TintMCE_loaded = true;
}
function remove_editors() {
//	$('.mceEditor').tinymce('remove');
//	$('.mceEditor').removeClass('mceEditor');
	$('.mceEditor').each(function() {
		id = $(this).attr('id');
		if (id.indexOf('_parent') == -1) {
			tinyMCE.execCommand('mceRemoveControl',false,id);
			$("#"+id).addClass('mceEditor');
		}
	});
}


/*
TinyMCE jQuery plug-in
*/
(function(b){var e,d,a=[],c=window;b.fn.tinymce=function(j){var p=this,g,k,h,m,i,l="",n="";if(!p.length){return p}if(!j){return tinyMCE.get(p[0].id)}function o(){var r=[],q=0;if(f){f();f=null}p.each(function(t,u){var s,w=u.id,v=j.oninit;if(!w){u.id=w=tinymce.DOM.uniqueId()}s=new tinymce.Editor(w,j);r.push(s);if(v){s.onInit.add(function(){var x,y=v;if(++q==r.length){if(tinymce.is(y,"string")){x=(y.indexOf(".")===-1)?null:tinymce.resolve(y.replace(/\.\w+$/,""));y=tinymce.resolve(y)}y.apply(x||tinymce,r)}})}});b.each(r,function(t,s){s.render()})}if(!c.tinymce&&!d&&(g=j.script_url)){d=1;h=g.substring(0,g.lastIndexOf("/"));if(/_(src|dev)\.js/g.test(g)){n="_src"}m=g.lastIndexOf("?");if(m!=-1){l=g.substring(m+1)}c.tinyMCEPreInit=c.tinyMCEPreInit||{base:h,suffix:n,query:l};if(g.indexOf("gzip")!=-1){i=j.language||"en";g=g+(/\?/.test(g)?"&":"?")+"js=true&core=true&suffix="+escape(n)+"&themes="+escape(j.theme)+"&plugins="+escape(j.plugins)+"&languages="+i;if(!c.tinyMCE_GZ){tinyMCE_GZ={start:function(){tinymce.suffix=n;function q(r){tinymce.ScriptLoader.markDone(tinyMCE.baseURI.toAbsolute(r))}q("langs/"+i+".js");q("themes/"+j.theme+"/editor_template"+n+".js");q("themes/"+j.theme+"/langs/"+i+".js");b.each(j.plugins.split(","),function(s,r){if(r){q("plugins/"+r+"/editor_plugin"+n+".js");q("plugins/"+r+"/langs/"+i+".js")}})},end:function(){}}}}b.ajax({type:"GET",url:g,dataType:"script",cache:true,success:function(){tinymce.dom.Event.domLoaded=1;d=2;if(j.script_loaded){j.script_loaded()}o();b.each(a,function(q,r){r()})}})}else{if(d===1){a.push(o)}else{o()}}return p};b.extend(b.expr[":"],{tinymce:function(g){return g.id&&!!tinyMCE.get(g.id)}});function f(){function i(l){if(l==="remove"){this.each(function(n,o){var m=h(o);if(m){m.remove()}})}this.find("span.mceEditor,div.mceEditor").each(function(n,o){var m=tinyMCE.get(o.id.replace(/_parent$/,""));if(m){m.remove()}})}function k(n){var m=this,l;if(n!==e){i.call(m);m.each(function(p,q){var o;if(o=tinyMCE.get(q.id)){o.setContent(n)}})}else{if(m.length>0){if(l=tinyMCE.get(m[0].id)){return l.getContent()}}}}function h(m){var l=null;(m)&&(m.id)&&(c.tinymce)&&(l=tinyMCE.get(m.id));return l}function g(l){return !!((l)&&(l.length)&&(c.tinymce)&&(l.is(":tinymce")))}var j={};b.each(["text","html","val"],function(n,l){var o=j[l]=b.fn[l],m=(l==="text");b.fn[l]=function(s){var p=this;if(!g(p)){return o.apply(p,arguments)}if(s!==e){k.call(p.filter(":tinymce"),s);o.apply(p.not(":tinymce"),arguments);return p}else{var r="";var q=arguments;(m?p:p.eq(0)).each(function(u,v){var t=h(v);r+=t?(m?t.getContent().replace(/<(?:"[^"]*"|'[^']*'|[^'">])*>/g,""):t.getContent()):o.apply(b(v),q)});return r}}});b.each(["append","prepend"],function(n,m){var o=j[m]=b.fn[m],l=(m==="prepend");b.fn[m]=function(q){var p=this;if(!g(p)){return o.apply(p,arguments)}if(q!==e){p.filter(":tinymce").each(function(s,t){var r=h(t);r&&r.setContent(l?q+r.getContent():r.getContent()+q)});o.apply(p.not(":tinymce"),arguments);return p}}});b.each(["remove","replaceWith","replaceAll","empty"],function(m,l){var n=j[l]=b.fn[l];b.fn[l]=function(){i.call(this,l);return n.apply(this,arguments)}});j.attr=b.fn.attr;b.fn.attr=function(n,q,o){var m=this;if((!n)||(n!=="value")||(!g(m))){return j.attr.call(m,n,q,o)}if(q!==e){k.call(m.filter(":tinymce"),q);j.attr.call(m.not(":tinymce"),n,q,o);return m}else{var p=m[0],l=h(p);return l?l.getContent():j.attr.call(b(p),n,q,o)}}}})(jQuery);
