var NavigareContent = Class.create();
NavigareContent.prototype = {
	initialize: function(options)
	{
		this.curent = 1;
		this.options = options;
		this.options.nav_buttons = this.options.nav_buttons!=undefined?this.options.nav_buttons:1;
		if(this.options.nav_buttons)
			this.make_events();
		this.auto_nav = this.options.auto_nav?this.options.auto_nav:0;
		this.imgs_path = this.options.imgs_path?this.options.imgs_path:'/templates/blue/images/';
		this.max_width = this.options.max_width?this.options.max_width:0;
		this.timeout = 0;
		if(this.auto_nav==1) this.go_auto_nav();
		this.width_correction = 0;
	},
	go_nav: function()
	{
		this.vnew;
		if(this.max_width>0)
		{
			if(this.curent*this.options.item_width>this.max_width)
			{
				this.vnew = this.vnew - this.max_width+this.curent*this.options.item_width;
				this.width_correction = this.curent*this.options.item_width - this.max_width;
			}
		}
		if(this.options.direction=="v")
		{
			new Effect.Move($(this.options.myclass+'_cnt'), {y: this.vnew,queue: { position: 'end', scope: 'slider'}});
		}
		else if(this.options.direction=="h")
		{
			new Effect.Move($(this.options.myclass+'_cnt'), {x: this.vnew,queue: { position: 'end', scope: 'slider'}});
		}
	},
	make_events: function()
	{
		if($(this.options.myclass+'_main_cnt')!=undefined)
		{
			Event.observe($(this.options.myclass+'_main_cnt'),'mouseover',function(){
				this.auto_nav = 0;
			}.bind(this));
			Event.observe($(this.options.myclass+'_main_cnt'),'mouseout',function(){
				clearTimeout(this.timeout);
				this.timeout = 0;
				this.auto_nav = 1;
				this.go_auto_nav();
			}.bind(this));
		}
		if($(this.options.myclass+'_left')!=undefined)
		{
			Event.observe($(this.options.myclass+'_left'),'click',function(){
				this.auto_nav = 0;
				this.calc_nav('down');
			}.bind(this));
		}
		if($(this.options.myclass+'_right')!=undefined)
		{
			Event.observe($(this.options.myclass+'_right'),'click',function(){
				this.auto_nav = 0;
				this.calc_nav('up');
			}.bind(this));
		}
		if(this.options.nav_buttons==2) 
		{
			if($(this.options.myclass+'_2_left')!=undefined)
			{
				Event.observe($(this.options.myclass+'_2_left'),'click',function(){
					this.auto_nav = 0;
					this.calc_nav('down');
				}.bind(this));
			}
			if($(this.options.myclass+'_2_right')!=undefined)
			{
				Event.observe($(this.options.myclass+'_2_right'),'click',function(){
					this.auto_nav = 0;
					this.calc_nav('up');
				}.bind(this));
			}
		}
		for(i=1;i<=this.options.total;i++)
		{
			if($(this.options.myclass+'_'+i)!=undefined)
			{
				Event.observe($(this.options.myclass+'_'+i),'click',function(e){
					this.auto_nav = 0;
					this.calc_nav(e.target.id.substr(e.target.id.lastIndexOf('_')+1));
				}.bind(this));
			}
		}
	},
	calc_nav: function(a)
	{
		go_to = 0;
		if(a=='down' && this.curent>1)
		{
			go_to = this.curent-1;
			this.vnew = this.options.item_width;
		}
		else if (a=='up' && this.curent<this.options.total)
		{
			go_to = this.curent+1;
			this.vnew = -this.options.item_width;
		}
		else if (a!='down' && a!='up')
		{
			go_to = parseInt(a);
			if(go_to>this.curent) this.vnew = (this.curent-a)*this.options.item_width;
			else if(go_to<this.curent) this.vnew = (this.curent-a)*this.options.item_width;
		}
		if(go_to<1 || go_to>this.options.total || this.curent==go_to) return;
		this.curent = go_to;
		if(this.options.nav_buttons) this.redraw_nav();
		if(this.width_correction>0)
		{
			this.vnew = this.vnew - this.width_correction;
			this.width_correction = 0;
		}
		this.go_nav();
	},
	redraw_nav: function()
	{
		if(this.curent==1)
		{
			$(this.options.myclass+'_left').src = this.imgs_path+'nav_left_inact.gif';
			if(this.options.nav_buttons==2) $(this.options.myclass+'_2_left').src = this.imgs_path+'nav_left_inact_2.gif';
		}
		else //active
		{
			$(this.options.myclass+'_left').src = this.imgs_path+'nav_left.gif';
			if(this.options.nav_buttons==2) $(this.options.myclass+'_2_left').src = this.imgs_path+'nav_left_2.gif';
		}
		if(this.curent==this.options.total)
		{
			$(this.options.myclass+'_right').src = this.imgs_path+'nav_right_inact.gif';
			if(this.options.nav_buttons==2) $(this.options.myclass+'_2_right').src = this.imgs_path+'nav_right_inact_2.gif';
		}
		else //active
		{
			$(this.options.myclass+'_right').src = this.imgs_path+'nav_right.gif';
			if(this.options.nav_buttons==2) $(this.options.myclass+'_2_right').src = this.imgs_path+'nav_right_2.gif';
		}
		for(i=1;i<=this.options.total;i++)
		{
			$(this.options.myclass+'_'+i).src = this.imgs_path+'nav_bull_inact.gif';
		}
		$(this.options.myclass+'_'+this.curent).src = this.imgs_path+'nav_bull_act.gif';
	},
	go_auto_nav: function()
	{
		if(this.auto_nav!=1) return;
		if(this.curent<this.options.total && this.timeout!=0)
			this.calc_nav('up');
		else if(this.timeout!=0)
			this.calc_nav(1);
		this.timeout = setTimeout(function(){this.go_auto_nav()}.bind(this),5000);
	}
}


