/************************************************************************************
* mtweb.js:		global javascript for miletracker
* mark guinn, 5.12.08
************************************************************************************/

var MT = {
	flashDuration:	15,	// seconds	

	/**
	 * hides any 'flash messages' on the screen
	 */
	hideFlashMsg : function() {
		var $m = $('.flash-msg');
		if ($m.length == 0) return;
		var h = $m.innerHeight();
		
		$m.css({
			opacity:	0.9,
			height:		h,
			position:	'relative'
		}).animate({
			opacity:		0,
			height:			0,
			'margin-top':	0,
			'margin-bottom':0,
			'padding-top':	0,
			'padding-bottom':0
		}, function(){ $(this).remove(); });
	}
};


// add parser to the tablesorter that can handle commas in numbers 
$.tablesorter.addParser({ 
    // set a unique id 
    id: 'flexnumber', 
    is: function(s) { 
        // return false so this parser is not auto detected 
        return false; 
    }, 
    format: function(s) { 
        return $.tablesorter.formatFloat(s.replace(/,/,'')); 
    }, 
    type: 'numeric' 
});
	

// start up code
$(document).ready(function(){
	
	// handle flash messages
	var $fm = $('.flash-msg');
	if ($fm.length)
	{
		$fm.click(MT.hideFlashMsg);
		setTimeout(MT.hideFlashMsg, MT.flashDuration * 1000);		
	}
	
	// focusing on forms
	$('.focus-me').each(function(){ this.focus(); });
	
});
