jQuery(document).ready(function() {

    jQuery ("#upload_image_button").click (function () {
        formfield = jQuery ("#upload_image").attr('name');
        tb_show ("", "media-upload.php?type=image&amp;TB_iframe=true");
        return false;
    });

    window.send_to_editor = function(html) {
        imgurl = jQuery ("img", html).attr ("src");
        jQuery ("#upload_image").val (imgurl);
        tb_remove ();
    };
	
});

	
/**
 *	Check the menu system... This is a hacky way of doing this, but there's no other option for it right now.
 */
function checkMenu () {
	var menu = jQuery("#content_left #menu-primary-nav-1 > li > ul > li:visible");
	
	if (menu) {
		var element;
		var subs = false;
		
		menu.each (function (i, el) {
			element = jQuery (el);
			
			subs = false;
			
			element.has ("ul").each (function (j, sub_el) {
				subs = true;
			});
		});
			
		if (subs !== true) {
			var html = menu.parent ().parent ().html ();
			var title = menu.parent ().parent ().text ();
			title = title.split ("\n");
			title = title [0];
			
			var tmp = menu.parent ().parent ().children ("a");
			var title_link = tmp [0];
			
			html = menu.parent ().parent ().wrap (function () {
				return "<li class=\"current-menu-ancestor\"><ul><li class=\"current-menu-ancestor\"><a href=\"" + title_link + "\">" + title + "</a>" + jQuery(this).html () + "</li></ul></li>";
			});
				menu.parent ().parent ().parent ().parent ().first ().html (html.html ());
		} // if ()
	} // if ()
} // checkMenu ();
