var animObj = { 
	interval: 0, 
	start_time: 0,
	h: 0,
	dir: 0,
	target: 0,
	elem: 0,
	start: function( from, to, fromsrch )
		{
			this.elem = document.getElementById( 'results_mover' );
			var now = new Date();
			this.start_time = now.getTime();
			
			this.dir = (( from < to )*2)-1;
			this.target = to;
			
			if ( this.interval != 0 ) clearInterval( this.interval );
			this.interval = window.setInterval( 'animObj.animate()', 10 );
			this.h = from;
			this.fromsrch = fromsrch;
		},
	animate: function()
		{
			//alert( this );
			//clearInterval( this.interval );
			var now = new Date();
			
			this.h += ( ( ( now.getTime() - this.start_time )/5.0 ) * this.dir );
			
//window.console.log( this.start_time + ' | ' + this.dir + ' | ' + now.getTime() );
			
			if ( this.dir > 0 && this.h >= this.target ) this.stop();
			else if ( this.dir < 0 && this.h <= this.target ) this.stop();

			this.setpos();
		},
	stop: function()
		{
			clearInterval( this.interval );
			this.interval = 0;
			this.h = this.target;
			if ( this.target != 0 ) document.getElementById( 'paging' ).innerHTML = '<img src="/images/progbar.gif" alt="progress" width="96" height="20" />';
		},
	setpos: function()
		{
			this.elem.style.left = Math.floor( this.h ) + 'px';
		}
	};

//------------------------------------------------------------

function page( lang, offs, dir )
{
	//START
	if ( dir > 0 ) animObj.start( 0, -460 );
	else animObj.start( 0, 460 );
	
	srch( lang, offs, 1 );
	
	return false;
}

//------------------------------------------------------------


//------------------------------------------------------------

//------------------------------------------------------------

function srch( lang, offs, from_paging )
{	
	var form = document.getElementById( 'filter' );
	
	if ( ! from_paging )
	{
		animObj.start( 0, -460, 1 );
	}
	
//alert( offs );
	if ( ! offs ) offs = 0;
	
	var url = '/' + lang + '/home/index/' + offs + '/' + collect_form( form );
//alert( url );
	
	xmlHttp=GetXmlHttpObject( search2 );
	if (xmlHttp==null) alert ("Browser does not support HTTP Request");
	else SendXmlHttpRequest( xmlHttp, url );

//	var msg = '';
//	if ( lang == 'nl' ) msg = 'ZOEKT RESULTATEN...';
//	else msg = 'SEARCHING...';
	
//	document.getElementById('results').innerHTML = msg + ' <img src="/images/barberpole.gif" width="" height="" alt="">';
	
	return false;
}

//------------------------------------------------------------

function search2()
{
	if ( xmlHttp.readyState==4 || xmlHttp.readyState=="complete" )
	{
		
		document.getElementById('results').innerHTML=xmlHttp.responseText;
		
		if ( animObj.fromsrch ) animObj.start( -460, 0 );
		else if ( animObj.dir < 0 ) animObj.start( 460, 0 );
		else animObj.start( -460, 0 );

	}
} 

//------------------------------------------------------------

function collect_form( obj )
{
	var getstr = '';
	var add = '';
	
	//TRAVERSE FORM
	for ( var i=0; i<obj.childNodes.length; i++ ) 
	{
		add = '';
		
		if ( obj.childNodes[i].tagName == "INPUT" ) 
		{
			if ( obj.childNodes[i].type == "text" ) 
			{
				add = obj.childNodes[i].name + ":" + obj.childNodes[i].value;
			}
			else if ( obj.childNodes[i].type == "checkbox" ) 
			{
				if ( obj.childNodes[i].checked ) 
				{
					add = obj.childNodes[i].name;// + ":" + obj.childNodes[i].value;
				} 
			}
			else if ( obj.childNodes[i].type == "radio" ) 
			{
				if ( obj.childNodes[i].checked ) 
				{
					add = obj.childNodes[i].name + ":" + obj.childNodes[i].value;
				}
			}
		} 
		else if ( obj.childNodes[i].tagName == "SELECT" ) 
		{
			var sel = obj.childNodes[i];
			add = sel.name + ":" + sel.options[sel.selectedIndex].value;
		}
		else if ( obj.childNodes[i].childNodes.length )
		{
			add = collect_form( obj.childNodes[i] );
		}
		
		if ( add != 0 )
		{
			if ( getstr != '' ) getstr += '+';
			getstr += add;
		}
	}
	
	return getstr;

}

//------------------------------------------------------------
