jQuery(document).ready(function() {
	jQuery('#top_nav .grantsAndGuidelines li.group2').addClass('shouldBeLast').appendTo(jQuery('#top_nav .grantsAndGuidelines .superPanel > ul'));
	jQuery('#top_nav .grantsAndGuidelines li.group3').addClass('shouldBeFirst').prependTo(jQuery('#top_nav .grantsAndGuidelines .superPanel > ul'));
	
});
/***** SUPERNOTE *****/
// pass in event e, prefix like 'supernote' or 'mydoc', id is a guid
function showNote(e, prefix, id) 
{
 // hide note if it is visible before this work
 //hideNote(prefix);
 
 if (document.getElementById(prefix + "-note-window" + id))
 {
    // swap html 
    var html = document.getElementById(prefix + "-note-window" + id).innerHTML;
    var main = document.getElementById(prefix + "-note-main");
    main.innerHTML = html;
    
    // reattach this element directly to the body so we can REALLY postion absolutely on screen
    document.body.appendChild(main);
    
    // find pos 
    x = mouseX(e);
    y = mouseY(e);
    /*
    // adjust for screen size
    var xadjust = 0;
    if(document.layers) {
        width = window.innerWidth;
        height = window.innerHeight;
    } else {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    } 
    
    
    var screenwidth = width;
    if (screenwidth > 1024)
    {
     xadjust = 1024 - screenwidth;
     //alert(xadjust);
    }
    */
    main.style.left = (x + 30) + 'px';
    main.style.top = (y + 10) + 'px';
    main.style.visibility = "visible";
 }
}

function hideNote(prefix)
{
    var main = document.getElementById(prefix + "-note-main");
    main.style.visibility = "";
}
 
// get mouse x position - pass in event
function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}
// get mouse y position - pass in event
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	alert('file upload replacement in progress');
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='iamges/btn_browse.png';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

/*
* collapsor (1.0) // 2008.04.05 // <http://plugins.jquery.com/project/collapsor>
* 
* REQUIRES jQuery 1.2.3+ <http://jquery.com/>
* 
* Copyright (c) 2008 TrafficBroker <http://www.trafficbroker.co.uk>
* Licensed under GPL and MIT licenses
* 
* collapsor opens and closes sublevel elements, like a collapsable menu
*
* We need to select the clickable elements that trigger the opening action of the sublevels: $('#menu ul li a').collapsor();
* The sublevel element must be in the same level than the triggers
*
* Sample Configuration:
* $('ul a').collapsor();
* 
* Config Options:
* activeClass: Class added to the element when is active // Default: 'active'
* openClass: Class added to the element when is open // Default: 'open'
* sublevelElement: Element that must open or close // Default: 'ul'
* speed: Speed for the opening animation // Default: 500
* easing: Easing for the opening animation. Other than 'swing' or 'linear' must be provided by plugin // Default: 'swing'
* 
* We can override the defaults with:
* $.fn.collapsor.defaults.speed = 1000;
* 
* @param  settings  An object with configuration options
* @author    Jesus Carrera <jesus.carrera@trafficbroker.co.uk>
*/
(function($) {
$.fn.collapsor = function(settings) { 
	// override default settings
	settings = $.extend({}, $.fn.collapsor.defaults, settings);
	var triggers = this;
	// for each element
	return this.each(function() {
		// occult the collapsing elements
		$(this).find('+ ' + settings.sublevelElement).hide();
		//show the opened
		if($(this).hasClass(settings.openClass)){
			$(this).find('+ ' + settings.sublevelElement).show();
		}
		
		// event handling
	  $(this).click(function() {
			// remove the active class from all the elements less the clicked
			$(triggers).not($(this)).removeClass(settings.openClass);
			// if the new active have sublevels
			if ($(this).next().is(settings.sublevelElement)){
				// blur and add the active class to the clicked
				$(this).blur().toggleClass(settings.openClass);
				// toggle the clicked
				$(this).next().animate({height:'toggle', opacity:'toggle'}, settings.speed, settings.easing);
				// hide the rest
				$(this).parent().parent().find(settings.sublevelElement).not($(this).next()).animate({height:'hide', opacity:'hide'}, settings.speed, settings.easing);
                
				return false;
			}
	   });
	});
};
// default settings
$.fn.collapsor.defaults = {
	activeClass: 'active',
	openClass:'open',
	sublevelElement: 'ul',
	speed: 500,
	easing: 'swing'
};
})(jQuery);

