var focusOnMainPage = false; // may be set by app's search forms

function focusOnSearch()
{
	if(document.getElementById)
	{
		var inputId = focusOnMainPage ? 'name' : 'sidebar_search';
		
		if(document.getElementById && document.getElementById(inputId))
			document.getElementById(inputId).focus();
	}
}

if (window.addEventListener){ 
	window.addEventListener('load', focusOnSearch, false);
} else if (window.attachEvent){ 
	var r = window.attachEvent("onload", focusOnSearch); 
}
// otherwise forget it, go buy yourself a true browser



/////////// SCROLLER

var NB_SCOLLERS=3;		// this script can manage as many scollers as you want!
var SCROLLER_HEIGHT=55;   // height of the scrolling window
var SCROLLER_WIDTH=134;

var scrolltimer = new Array(NB_SCOLLERS);  // pointers to timer objects
var base_top = new Array(NB_SCOLLERS);     // the "top" value of the scrolling window
var height = new Array(NB_SCOLLERS);       // the height of the complete content
var div = new Array(NB_SCOLLERS);		   // pointer to object.style
var top = new Array(NB_SCOLLERS);		   // the actual "top" value of the moving div

function Scroll(i) {
	if(height[i] <= SCROLLER_HEIGHT)
		return; // we don't need to scroll here...
	
	// compute new position
	var c_top = base_top[i]-top[i]+1;
	var c_bot = c_top+SCROLLER_HEIGHT;
	top[i]=top[i]-1;
	
	// if we hitted the bottom...
	if(top[i]<=(base_top[i]-height[i]-SCROLLER_HEIGHT)){
		// ... roll again!
		top[i] = base_top[i];
		c_top = 0;
		c_bot = SCROLLER_HEIGHT;
	}
	
	// set new position	
	if(document.layers){ // netscape...
		div[i].top=top[i];
		div[i].clip.top = c_top;
		div[i].clip.bottom = c_bot;
	} else {
		div[i].clip = "rect("+c_top+"px "+SCROLLER_WIDTH+"px "+c_bot+"px 0px)";
		div[i].top=top[i]+'px';
	}
		
	scrolltimer[i] = setTimeout("Scroll("+i+")", 100);
}

function stopScroll(i) {
	if(scrolltimer[i]!=null){
		clearTimeout(scrolltimer[i]);
		scrolltimer[i]=null;
	}
}

/**
 * @param i an int in 0..(number of scollers -1)
 * @param ident the element id
 * @param init_top the original element's top (int)
 */
function scroll_init(i,ident,init_top){
	if (document.layers) {
		div[i] = eval("document."+ident);  // netscape 4
		height[i] = eval("document."+ident+".offsetHeight");
	} else if (document.getElementById) {
		div[i] = eval("document.getElementById('"+ident+"').style");  // DOM level2 compliant
		height[i] = eval("document.getElementById('"+ident+"').offsetHeight");
	} else if (document.all) {
		div[i] = eval("document.all."+ident+".style"); // IE 5+
		height[i] = eval("document.all."+ident+".offsetHeight");
	}
	
	if(div[i]!=null){
		if(height[i] > SCROLLER_HEIGHT)
			// add a blank between two rolling loops
			div[i].padding = SCROLLER_HEIGHT+"px 0 0 0";
	
		base_top[i]=init_top;
		top[i]=init_top;
		Scroll(i);
	}
}


//////// COMMUNITIES

var currentCommId = 0;
var counterComms  = 0;

function swapNewComm()
{
	id = 'newCommunity'+currentCommId;
	if (document.layers) {
		element = eval("document."+id);  // netscape 4
	} else if (document.getElementById) {
		element = eval("document.getElementById('"+id+"').style");  // DOM level2 compliant
	} else if (document.all) {
		element = eval("document.all."+id+".style"); // IE 5+
	}
	if ( element )
		element.display = 'none';
	
	currentCommId++;
	if ( currentCommId >= counterComms )
	{
		currentCommId = 0;
	}
	id = 'newCommunity'+currentCommId;
	
	if (document.layers) {
		element = eval("document."+id);  // netscape 4
	} else if (document.getElementById) {
		element = eval("document.getElementById('"+id+"').style");  // DOM level2 compliant
	} else if (document.all) {
		element = eval("document.all."+id+".style"); // IE 5+
	}
	
	if (element)
		element.display = 'block';
	
	setTimeout('swapNewComm()',5000);
}
