function nl2br (str, is_xhtml) {   
    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';    
    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
function br2nl(str) {
    return str.replace(/<br\s*\/?>/mg,"\n");
}
function tmce(selector) {
    return $(selector).tinymce({
        script_url : '/static/tiny_mce/tiny_mce.js',
        // General options
        theme : "advanced",
        skin : "o2k7",
        skin_variant : "silver",
        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,advlist",

        // Theme options
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,sub,sup,|,image,charmap,emotions",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_buttons4 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // 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",
    });
}

$(function() {
	$('.content-tabs li,.sidebar li,.menu li')
	//.hover( function(){ $(this).addClass('tab_hover', 100); }, function(){ $(this).removeClass('tab_hover', 100); })
	//.css('cursor','pointer')
	.click(function() {
        if( $(this).hasClass('current') )
            return;

		var toHide = null;
		$(this).parent().find('li').each(function() {
			if( $(this).hasClass('current') )
			{
				toHide = '#'+$(this).attr('id')+'_content';
				$(this).removeClass('current');
			}
		});
		$(this).addClass('current');

		try {
			eval( "tab_changed_in_"+$(this).parent().attr('id')+"( $(this).attr('id') );" );
		} catch(err) {
		}

		$('#'+$(this).attr('id')+'_content').fadeIn('fast');
		if( toHide != null )
			$(toHide).hide();//fadeOut('fast');
	});

	$(".map-info,.titles-wrap,.question,.map-list").live("mouseover mouseout", function(event) {
        if ( event.type == "mouseover" ) {
            $(this).addClass("hover");
        } else {
            $(this).removeClass("hover");
        }
    });

});

