if(!baseUrl) {
	var baseUrl = '';
}

var Tiny = {
	pathToTiny : baseUrl + '/scripts/tinymce',
	pathToKfm : baseUrl + '/scripts/kfm',
	_loaded : false,
	options : {
		theme_advanced_blockformats : 'p,h3,h4,blockquote',
		theme : 'advanced',
		mode: 'exact',
		media_strict : false,
		elements : '',
		content_css : baseUrl + '/styles/tiny.css',
		extended_valid_elements : 'embed[quality|type|pluginspage|width|height|src|align],object[classid|codebase|width|height|align],param[name|value]',
		plugins : 'table,advimage,inlinepopups,contextmenu,paste,media,noneditable',
		noneditable_leave_contenteditable : false,
		paste_create_paragraphs : true,
		paste_create_linebreaks : true,
		paste_auto_cleanup_on_paste : true,
		paste_convert_middot_lists : true,
		paste_convert_headers_to_strong : true,
		paste_strip_class_attributes : true,
		paste_remove_styles : true,
		paste_remove_spans : true,	
		paste_use_dialog : true,
		theme_advanced_toolbar_location : 'top',
		theme_advanced_toolbar_align : 'left',
		theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect',
		theme_advanced_buttons2 : 'pastetext,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,image,media,cleanup,code,|,forecolor,backcolor',
		theme_advanced_buttons3 : 'hr,removeformat,visualaid,|,sub,sup',
		theme_advanced_buttons4 : '',
		height:'350px',	
		width:'550px',
		language : 'nl',
	    external_image_list_url : this.pathToKfm + '/index.php',
	    file_browser_callback : 'Tiny.kfmWindow',
	    relative_urls : false,
		setup: function(ed) {
			ed.onPaste.add( function(ed, e, o) {
				ed.execCommand('mcePasteText', true);
				return tinymce.dom.Event.cancel(e);
			});
		}
	},
	initialize : function(id, options) {
		if(options) {
			for (attrname in options) {
				this.options[attrname] = options[attrname]; 
			}
		}
		this.options.elements = id;
		
		if (window.addEventListener) {
			window.addEventListener('load', function(){Tiny._loadScript();}, false);
		} else if (window.attachEvent) {
			window.attachEvent('onload', function(){Tiny._loadScript();});
		}
	},
	kfmWindow : function(field_name, url, type, win) {
		window.SetUrl=function(url,width,height,caption){
			win.document.forms[0].elements[field_name].value = url;
			if(caption){
				win.document.forms[0].elements['alt'].value=caption;
				win.document.forms[0].elements['title'].value=caption;
			}
		}
		window.open(Tiny.pathToKfm + '/index.php?mode=selector&type='+type,'kfm','modal,width=800,height=600');
	},
	_loadScript : function() {
		head = document.getElementsByTagName('head').item(0);
		script= document.createElement('script'); 
		script.type= 'text/javascript';
		script.src= this.pathToTiny + '/tiny_mce.js';
		script.onload = function() { Tiny._setIsLoaded(); } 
		script.onreadystatechange = function() { 
			if (this.readyState == 'complete' || this.readyState == 'loaded') { 
				Tiny._setIsLoaded();
			}
		};
		head.appendChild(script);
	},
	_setIsLoaded : function() {
		if(this._loaded === true) {
			return;
		}
		this._loaded = true;
		tinymce.dom.Event.domLoaded = true;
		tinyMCE.init(this.options);
	}
};

window.onload = function() {
	var logo = new SWFObject(baseUrl + '/assets/flash/logo.swf','logo_flash','214','68','9','#');
	logo.addParam('allowfullscreen','false');
	logo.addParam('allowscriptaccess','never');
	logo.addParam('wmode','transparent');
	logo.write('logo_wrap');
};

function showReferrerFormBox() {
	$('body').append('<a id="referrer_link" href="' + baseUrl + '/referrer"></a>');
	$('#referrer_link').fancybox({
			hideOnOverlayClick : false,
			hideOnContentClick : false,
			frameWidth : 400,
			frameHeight : 200,
			overlayColor : '#2C1504',
			padding : 20
			
	}).trigger('click');
}
