// JavaScript Document
$(document).ready(function (){
    //search for cookie stuff!
    if($.cookie("tinyMCEOff")== null){
	init_mce();

        $("#wysiwygToggle").attr('value',"WYSIWYG editor: On");//("WYSIWYG: On");

    }else{
        $("#wysiwygToggle").attr('value',"WYSIWYG editor: Off");
    }

if ($.browser.msie && $.browser.version.substr(0,1)<7) {
                        // alert("We're currently working making this work in IE6, you'll need to bear with us!\n \nTry viewing this in another browser for the moment!");
			 
			          }
				  });
function init_mce(){
	
	$('textarea.tinymce').tinymce({
			// Location of TinyMCE script
			script_url : 'sucu/display/js/tiny_mce/tiny_mce.js',

			// General options
			theme : "advanced",
			plugins : "table",
			plugins : "media",
			media_strict: false,

			// Theme options
			theme_advanced_toolbar_location : "top",
			theme_advanced_buttons1 : "formatselect,|,bold,italic,underline,|,table,|,bullist,numlist,|,undo,redo,|,link,unlink,|,code",
			theme_advanced_buttons2 : "",
			invalid_elements : "xml,w,font",
			theme_advanced_blockformats : "p,h2,h3,h4",

			// Example content CSS (should be your site CSS)
			//content_css : "/sucu/display/css/common.css",
			//relative_urls : false,
                        convert_urls : false,
                        
//remove_script_host : false,

			// 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",

			// Replace values for the template plugin
			template_replace_values : {
				username : "Some User",
				staffid : "991234"
			}
		});
}

in_array=function(needle,haystack)
  {
	for (var k=0;k<haystack.length;k++)
	  {
		if(haystack[k] === needle)
		  {
			return true;
			}
		}
  return false;
	}


function myAddEvent(obj,event,func) {
	//adapted from a function by Todd Anthony Spartaforce http://spatacoli.com/storydisplay.aspx?reqid=5463c334-0d6f-425a-94cd-fe5ead3634e7
	//needed a non-destructive cross-browser method for adding event listeners
	var oldevent = obj[event];
	if (typeof obj[event] != 'function')
		obj[event] = func;
	else {
		obj[event] = function() {
			oldevent();
			func();
		};
	}
} 
