var NavigatorInstance = null;
var Navigator = function(idList, idNavigator){
	NavigatorInstance = this;
	this.indexList = 0;
	this.indexEndList = 0;
	this.currentIndexNavigator = 0;
	
	this.navigator = $(idNavigator);
	this.list = $(idList);
	this.controlUp = this.navigator.children('img.NavigatorControlUp');
	this.controlDown = this.navigator.children('img.NavigatorControlDown');
	this.controlSlider = this.navigator.children('div.NavigatorControlsSlide');
	
	this.activate();
};
Navigator.prototype.activate = function(){
	this.list.scrollable({ vertical: true, mousewheel: true });
	
	this.indexEndList = this.controlSlider.find('div.PositionSlide').size() - 1;
	
	this.controlUp.hide();
	this.controlUp.click(function(){
		if(NavigatorInstance.indexList > 0){	NavigatorInstance.indexList--;}
		NavigatorInstance.list.scrollable().seekTo(NavigatorInstance.indexList);
		NavigatorInstance.update();
	});
	this.controlUp.hover(
			function(){
				$(this).attr('src', 'application/resources/images/up_over.png');
			},
			function(){
				$(this).attr('src', 'application/resources/images/up.png');
			}
	);
	
	this.controlDown.click(function(){
		if(NavigatorInstance.indexList < NavigatorInstance.indexEndList){	NavigatorInstance.indexList++;}
		NavigatorInstance.list.scrollable().seekTo(NavigatorInstance.indexList);
		NavigatorInstance.update();
	});

	this.controlDown.hover(
			function(){
				$(this).attr('src', 'application/resources/images/down_over.png');
			},
			function(){
				$(this).attr('src', 'application/resources/images/down.png');
			}
	);
	
	this.controlSlider.find('div.PositionSlide').click(function(){
		NavigatorInstance.indexList = parseInt($(this).attr('title'));
		NavigatorInstance.list.scrollable().seekTo(NavigatorInstance.indexList);
		NavigatorInstance.update();
	});
	
	this.controlSlider.find('div.PositionSlide').hover(
			function(){
				$(this).attr('class', 'PositionSlide Event TextoEfectoOver');
			},
			function(){
				if($(this).attr('title')==NavigatorInstance.currentIndexNavigator || $(this).attr('title')==NavigatorInstance.indexList){
					$(this).attr('class', 'PositionSlide Event TextoEfectoResaltado');
				}else{
					$(this).attr('class', 'PositionSlide Event TextoEfectoOut');
				};
			}
	);
};
Navigator.prototype.update = function(){
	if(this.indexList > 0 && this.indexList <= this.indexEndList){
		this.controlUp.show();
	}else{
		this.controlUp.hide();
	}
	if(this.indexList >= 0 && this.indexList < this.indexEndList){
		this.controlDown.show();
	}else{
		this.controlDown.hide();
	}

	this.controlSlider.find('div.PositionSlide[title='+this.currentIndexNavigator+']').attr('class', 'PositionSlide Event TextoEfectoOut');
	this.currentIndexNavigator = this.indexList;
	this.controlSlider.find('div.PositionSlide[title='+this.currentIndexNavigator+']').attr('class', 'PositionSlide Event TextoEfectoResaltado');
};
