// tinyMCE configuration
tinyMCE.init( {
	mode : "specific_textareas",
	editor_selector : /(tiny_mce|image_mce)/,
	theme : "advanced",
	body_class : "cms",
	editor_deselector : "mceNoEditor",
	content_css : "/styles/cms.css",
	plugins : "safari,inlinepopups,media,paste,table",
	theme_advanced_font_sizes : "1,2,3,6,7,8,9,10,12,14,16",
	theme_advanced_buttons1 : "bold, italic, underline, justifyleft,justifycenter, justifyright, justifyfull , formatselect,  |, pasteword, code",
	theme_advanced_buttons2 : "undo,redo,|,bullist, numlist,|,outdent,indent, |, link, unlink, image, styleselect ",
	theme_advanced_buttons3 : "tablecontrols",
	theme_advanced_resizing : true,
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "center",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_blockformats : "p,h3,h4,h5,h6",
	convert_urls : false,
	verify_html : false,
	valid_elements : "p[class|align|style|font],span[class|style],strong/b[class|style],a[name|href|target|title],img[class|src|border=0|alt|title|width|height|align|style],hr[class|width|size|noshade],span[class|align],table[border|cellspacing|cellpadding|class|style|width],tr[class],td[class|style],th[class|style]"
});

// jquery stuff
$(document).ready(function() {
	
	// lightbox
	$("a.fancyBox").fancybox();

	// add default text to input boxes
	$('.swapValue').each(function(n) {

		if ($(this).val().length == 0) {
			$(this).val($(this).attr('title'));
			$(this).addClass('ghostInput');
		} else {
			$(this).removeClass('ghostInput');
		}

		$(this).bind('focus', function() {
			if ($(this).val() == $(this).attr('title')) {
				$(this).val('');
				$(this).removeClass('ghostInput');
			} else {
				$(this).select();
				$(this).removeClass('ghostInput');
			}
		});

		$(this).bind('blur', function() {
			if ($(this).val().length == 0) {
				$(this).val($(this).attr('title'));
				$(this).addClass('ghostInput');
			} else {
				$(this).removeClass('ghostInput');
			}
		});

	});

	// remove default text on submit
	$('form').bind('submit', function() {
		$('.swapValue').each(function() {
			if ($(this).val() == $(this).attr('title')) {
				$(this).val('');
			}
		});
	});

	// make sure links are using target="_blank" as well as rel="external"
	$('a[rel=external]').each(function(n) {
		$(this).attr('target', '_blank');
		$(this)	.attr('title', 'Open ' + $(this).attr('href') + ' in a new window');
	});

});
