
/**
 * ui.js -> http://ojmed.com/
 * (cc) creative commons by 3.0
 */
 



window.onload = function() {
	news_start();
	fix();
}


window.onresize = function() {
	fix();
}

window.onscroll = function() {
	fix();
}
 
 
/**
 * Show or hide the element defined by the given id
 *
 * @param String	the element ID, or a list of element id
 * @param String	[ the display style : block (default), inline, etc… ]
 * @param boolean	[ force the element to stay in the given style (false by default)  ]
 *
 * @return String	the current element ID display style (only for a single ID)
 */
function display( id, style, fix )
{
	
	var i,elem;

	if ( !style ) style = "block";
	if ( !fix ) fix = false;
	if ( typeof(id)=="string" ) id = [id];
	
	for( i in id  ) {
		elem = document.getElementById( id[i] );
		elem.style.display = elem.style.display==style && !fix ? 'none' : style;
	}
	
	// return style
	if ( i==0 ) return elem.style.display==style;
}


/**
 * fix navigation element position.
 */
var _nav = {};
function fix()
{

	var min, max;
	
	var nav		= document.getElementById( "nav");
	var inner	= document.getElementById( "navinner" );
	var footer	= document.getElementById( "footer" );
	var main	= document.getElementById( "main" );
	var content	= document.getElementById( "content" );
	
	
	if ( nav ) {
		if ( !_nav.main ) _nav.main  = nav.offsetTop;
		max = Math.min( CSS.windowHeight()-footer.offsetHeight-nav.offsetHeight, _nav.main );
		nav.style.top = Math.max( 20, max ) + 'px';
	}
	
	if ( inner ) {
		if ( !_nav.inner) {
			inner.style.position = "fixed";
			_nav.inner = inner.offsetTop - CSS.get(inner,"margin-top",true);
		}
		
		min = CSS.top(main) - CSS.pageOffsetTop() + CSS.get( main, "padding-top", true );
		min = Math.max( min, Math.min( CSS.windowHeight()-inner.offsetHeight-10, _nav.inner ) );
		max = CSS.bottom(content) - CSS.pageOffsetTop() - CSS.get(inner,"margin-top",true) - inner.offsetHeight - 320;
		
		inner.style.top = Math.min( min, max ) + 'px';
	}
	
}


/**
 * Validate form.
 */
var check = false;
function validate() {

	if ( check ) document.getElementById( "form" ).submit();
	else {
		document.getElementById( "confirm_msg" ).style.display = "block";
		check = true;
	}

	/*var inputs = document.getElementsByTagName('input');
	var textareas = document.getElementsByTagName('textarea');
	
	for( i=0; i<inputs.length; i++ ) if ( inputs[i].type!="submit" ) inputs[i].disabled = true;
	for( i=0; i<textareas.length; i++ ) textareas[i].disabled = true;*/
	
}




