gallery_autolist_controller = function( p_self_name, p_obj_name, p_timeout, p_event_container_id, p_display_container_id )
{
	this._self_name = p_self_name;
	this._gallery_controller_name = p_obj_name;
	this._gallery_controller_ref = null;
	
	this._timeout = parseInt(p_timeout);
	this._current_timeout = this._timeout;
	this._timer_ref = null;
	
	this._event_container_id = p_event_container_id;
	this._display_ref = document.getElementById( p_display_container_id );
	
	this._playing_flag = false;
		
	this.init = function()
	{
		try
		{
			this._gallery_controller_ref = eval( this._gallery_controller_name );
			
		}
		catch(err)
		{
			alert("Greška prilikom kreiranja 'gallery_autolist_controller' objekta!\n" + err.message);
			return false;
		}
		
		//postoji li metoda?
		if (this._gallery_controller_ref.next_loop == undefined)
		{
			alert( "Ne postoji potrebna metoda 'next_loop()' u gallery_controller_objektu!" );
			return false;
		}
		
		//how many items? min 2!
		if(this._gallery_controller_ref._arr_entiteti.length < 2 )
		{
			this.display_hide();
			return false;
		}
		
		this.display_update();
		this.add_mouseover_event();
		this.play();
		
	}
	
	
	this.play = function()
	{
		if(this._playing_flag)
		{
			return;
		}
		
		this._timer_ref = window.setTimeout( this._self_name + ".countdown()", 1000 );
		this._playing_flag = true;
	}
	
	this.pause = function()
	{
		window.clearTimeout( this._timer_ref );
		this._playing_flag = false;
	}
	
	
	this.list_next = function()
	{
		this._gallery_controller_ref.next_loop();
	}
	
	this.countdown = function()
	{
		this._current_timeout--;
						
		if (this._current_timeout < 0)
		{
			this._current_timeout = this._timeout;
			this.list_next();
			
		}
		
		this.display_update();
		this._timer_ref = window.setTimeout( this._self_name + ".countdown()", 1000 );
	}
	
	
	this.display_update = function()
	{
		this._display_ref.innerHTML = this._current_timeout; //alert(this._current_timeout);
	}
	
	this.display_hide = function()
	{
		this._display_ref.style.display = "none";
	}
	
	//events
	this.mouse_in = function()
	{
		this.remove_mouseover_event();
		this.pause();
		this.add_mouseout_event();
		
	}
	
	this.mouse_out = function()
	{
		this.remove_mouseout_event();
		this.play();
		this.add_mouseover_event();
	}
	
	
	this.add_mouseover_event = function()
	{

		eval (' document.getElementById("' + this._event_container_id + '").onmouseover = \
			function()\
			{\
				' + this._self_name + '.mouse_in();\
			}' );
	}
	
	this.remove_mouseover_event = function()
	{
		document.getElementById( this._event_container_id ).onmouseover = function(){};
	}
	
	this.add_mouseout_event = function()
	{
		eval (' document.getElementById("' + this._event_container_id + '").onmouseout = \
			function()\
			{\
				' + this._self_name + '.mouse_out();\
			}' );
	}
	
	this.remove_mouseout_event = function()
	{
		document.getElementById( this._event_container_id ).onmouseout = function(){};
	}
	
	
	
	this.init();
	
}

//$('#' + this._container_id).bind("mouseleave", this._self_name + ".mouse_out()");
//document.getElementById( this._container_id ).onmouseover = eval( "function(){ alert('" + this._self_name + "');}" );