$(document).ready( function() {
	
	// add default text to input boxes
	$('.swapValue').each( function(n) {
		if ( $(this).val().length == 0 ) {
			$(this).val($(this).attr('title'));
			$(this).addClass('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');
			}
		});
	});
	
	$('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');
	});
	
	// lightbox
	$("a.colorbox").colorbox({
		photo: true,
		opacity: 0.65,
		scalePhotos: true,
		maxWidth: '75%', 
		maxHeight:'75%'
	});
	
	// ui calendar
	$('input.datePicker').datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: 'dd/mm/yy',
		showOn: 'button',
		buttonImage: '/images/btn_calendar.gif',
		buttonImageOnly: true,
		autoSize: true,
		buttonText: 'Select a date from a calendar',
		yearRange: 'c-90:c+10'
	});

});	

tinyMCE.init({
	mode : "specific_textareas",
	editor_selector : /(tiny_mce|image_mce)/,
	theme : "advanced",
	editor_deselector : "mceNoEditor",
	body_class : "cms",
	content_css : "/css/content.css",
	plugins : "safari,inlinepopups,paste,table",
	paste_auto_cleanup_on_paste : true,
	width : "275",
	height : "500",
	theme_advanced_buttons1 : "bold, italic, underline, justifyleft,justifycenter, justifyright, justifyfull , formatselect,  |, pasteword,pastetext, code ",
	theme_advanced_buttons2 : "undo,redo,|,bullist, numlist,|,outdent,indent, |, link, unlink, image ,forecolor",
	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,h2,h4",
	convert_urls : false,
	verify_html : true,
	valid_elements : "@[class|style|title],br,h2,h3,h4,-p[align],-strong/b,a[name|href|target]," 
		+ "img[src|border=0|alt|title|width|height|align],hr[width|size|noshade],"
		+ "table[border|cellspacing|cellpadding|width],tr[rowspan],td[colspan],th[colspan],-ul,ol,-li"
});

