/*
	* * * * * * * * * * * * *
	*						*
	*	General Functions	*
	*						*
	* * * * * * * * * * * * *
*/

function SetRollOvers(){
	// usage: add the class 'rollover' to image elements
	jQuery("input[type=image].rollover, a.rollover img, img.rollover").hover(function(){
		    $(this).attr("src",jQuery(this).attr("src").replace(/(\.[^.]+)$/, 'Hi$1'));
	    },function(){
		    $(this).attr("src",jQuery(this).attr("src").replace(/Hi(\.[^.]+)$/, '$1'));
	});
}
function SetBiggerClick(){
	// make a '.clickable' element activate the first link it contains (when clicking anywhere on it)
	$(".clickable").biggerlink(); // requires: jquery.biggerlink.pack.js
}
function SetEnterSubmit(){
	// usage: add the class 'submit-on-enter' to any element
	$(".submit-on-enter input[type=text], .submit-on-enter textarea").keydown(function(ev){
        //$(".submit-on-enter").append(ev.keyCode);
        if(ev.keyCode == 13)
        {
            ev.preventDefault();
            ev.stopPropagation();
             //$(".submit-on-enter").append("==submitting");    
             $(this).parents(".submit-on-enter").children("input[type=image], input[type=button]").click();
             return false;
        }
    });
}
function SetExternalLinks(){
	/* Purpose: checks all <a>'s in the doc, if it has a rel attribute of 'external', sets to open in new window
	usage: <a href="http://www.google.com" rel="external">Google</a> */
	$('a[rel=external]').click(function() { if ($(this).attr('href').length > 0) { window.open(this.href); return false; } });
}
function Equalise(elms){
	// usage:
	// Equalise($(".list li"));
	// Equalise($("#nav, #content"));
	var highest = 0;
	for(i=0; i < elms.length; i++){ if($(elms[i]).height() > highest) highest = $(elms[i]).height(); }
	for(i=0; i < elms.length; i++){ if($(elms[i]).height() < highest) $(elms[i]).height(highest); }
}

//TinyMCE settings ==================================================================================
//===================================================================================================
$.fn.tinymce = function(options) {
    return $(this).each(function() {
        // I don't think the style declaration is not really used in this sense, but I left it anyway
        preString = "<div class='jqHTML_frame' style='width:" + $(this).css("width") + "px;height:" + ($(this).css("height") + 20) + "px;'>";
        postString = "</div>";
        $(this).wrap(preString + postString);
        // this comes last to avoid IE7 bug
        tinyMCE.addMCEControl($(this), $(this).attr('id'));
        alert($(this).attr('id'));
    });
}

// for configuration options see documentation here: http://wiki.moxiecode.com/index.php/TinyMCE:Configuration
/*
tinyMCE.init({
            mode : "none",
            editor_selector : "mceEditor",
            theme : "advanced",
            plugins: "table,advimage",
            theme_advanced_buttons1 : "bold,bullist,numlist,formatselect,sub,sup,|,image,link,unlink,anchor,charmap,|,tablecontrols,|,removeformat,cleanup,help,code",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : "",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            theme_advanced_resizing : true,
            paste_auto_cleanup_on_paste : true,
            paste_convert_headers_to_strong : false,
            paste_strip_class_attributes : "all",
            paste_remove_spans : true,
            paste_remove_styles : true,
            //these settings for"domain-less--absolute-url"
            convert_urls : true,
            relative_urls: false,
            remove_script_host : true,
            //end settings for"domain-less--absolute-url"
            apply_source_formatting : true,
            table_inline_editing : true,
            extended_valid_elements : "a[name|href|target|title|onclick]",
            valid_elements: "+a[id|rel|rev|charset|hreflang|dir|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur|onclick|" + 
"ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup]," + 
"-strong/-b[]," + 
"-em/-i[]," + 
"-strike[]," + 
"-u[]," + 
"#p[id|dir|align]," + 
"-ol[]," + 
"-ul[]," + 
"-li[]," + 
 "br," + 
 "img[id|dir|lang|longdesc|usemap|src|onmouseover|onmouseout|border|alt=|title|hspace|vspace|width|height|align]," + 
"-sub[]," + 
"-sup[]," + 
"-blockquote[dir]," + 
"-table[border=0|cellspacing|cellpadding|width|height|class|align|summary|dir|id|lang|bgcolor|background|bordercolor]," + 
"-tr[id|lang|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor]," + 
 "tbody[id|class]," + 
 "thead[id|class]," + 
 "tfoot[id|class]," + 
"-td[id|lang|dir|class|colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor|scope]," + 
"-th[id|lang|dir|class|colspan|rowspan|width|height|align|valign|scope]," + 
 "caption[id|lang|dir|class]," + 
"-pre[class|align]," + 
 "address[class|align]," + 
"-h1[id|dir|align]," + 
"-h2[id|dir|align]," + 
"-h3[id|dir|align]," + 
"-h4[id|dir|align]," + 
"-h5[id|dir|align]," + 
"-h6[id|dir|align]," + 
 "hr[],"
       });
*/
