
/* BEGIN: [Ordinal Number Format v.1 :: Author: Addam Driver :: Date: 10/5/2008 ]
	** Disclaimer:  Use at your own risk, copyright Addam Driver 2008  
	** Example on calling this function:
	** ordinal(this, {subScript: true});
	** The Ordinal script will append the proper ordinal to any number like: 1st, 2nd, 33rd, etc.
	** If you pass the "subScript:true" option, then it will use the html subscript for the new ordinal
*/
function ordinal(num, options){		
	var options = options || {}; // setup the options
	var sScript = options.sScript; // get subscript if needed
	
	var mod1 = num%100; // get the divided "remainder" of 100
	var mod2 = num%10; // get the divided "remainder" of 10
	var ord; // ste the ordinal variable
	
	if((mod1-mod2) == 10){ // capture 10
		ord = "th"; // set the oridnal to th as in: 10th
	}else{// for everything else
		switch(mod2){  // check the remainder of the 10th place
			case 1: // if 1 as in 1st
				ord = "st"; // set the ordinal
			break;
			case 2: // if 2 as in 2nd
				ord = "nd";// set the ordinal
			break;
			case 3: // if 3 as in 3rd
				ord = "rd";// set the ordinal
			break;
			default: // for everything else
				ord = "th";// set the ordinal
			break;
		}
	}
	switch(sScript){
		case "sub":
			return num+"<sub>"+ord+"<\/sub>";	// put the ordinal in the HTML sub script
		break;
		case "sup":
			return num+"<sup>"+ord+"<\/sup>";	// put the ordinal in the HTML super script
		break;
		default:
			return num+ord;
		break;
	}	
}