// JavaScript Document
$.fn.sliderHome = function (intervalo){


	nro = 0
	tiempo = "";

	if(!intervalo){
		return false;
	}
	
	

	cont = this
	// *** preparo maqueta  ************************************************************************************************************************************************** // 
	
	anchArea = cont.width();
	altoArea = cont.height();
	
	this.append("<div class='fila'></div>");
	
	this.find('.fila').width(anchArea)
	this.find('.fila').height(altoArea)	
	
	// retiro los paginas y las pongo en la fila
	this.find('div.page').appendTo( $(cont).children('.fila') );
	
	this.find('.fila').width( this.find('.fila .page').length * anchArea );
	this.find('.fila').css("left",anchArea);
	
	this.find('.fila .page').css({ 'float':'left' })
	
	this.find('.fila .page').width(anchArea);
	this.find('.fila .page').height(altoArea);
	
	this.children('div[class!="fila"]').addClass('text');
	this.children('.text').width(anchArea);
	
	this.append("<div class='paginador'></div>");
	
	this.children('.text').each(function(vuelta){
		$(this).css("height",$(this).height() )
		cont.children('.paginador').append('<a href="#" id="botonPag'+vuelta+'">&nbsp;</a>');
		
		cont.children('.paginador').children('#botonPag'+vuelta).click(function(){
			
			mostrarTanda(vuelta);
			return false;
		})
	})
	
	this.children('.text').css("top",altoArea);
	this.children('.text').slideDown();
	
	// armo paginador
	
	
	// END preparo maqueta  ************************************************************************************************************************************************** // 
	
	function mostrarTanda(nro){
	
		clearInterval(tiempo)
		
		
		// acomodo
		cont.find('.paginador a').removeClass('activo');
		cont.find('.paginador #botonPag'+nro).addClass('activo');
		
		cont.children(".fila").stop().animate({"left": 0 - anchArea * nro },500);

		tiempo = setInterval(function(){
			
			clearInterval(tiempo);
			
			nro = parseInt(nro);
			
			
			
			if(nro == 2 ){
			
				nro = -1;
			}
			
			mostrarTanda(nro+1);
		},
		intervalo)
	} // END mostrarTanda()
	
	mostrarTanda(0);
}

$.fn.menuFeatures = function (){
	
	this.nro = 0;
	move = false;
	// inicio
	menu = this;
	//this.find('.overlap').css('opacity',0);
	this.find('.overlap').hide();
	
	this.find('.botoneraFeatures a').click(function(event){

		cargarData(
			$(this).attr("href"),
			menu.find('.botoneraFeatures a.selected').attr("nro"),
			$(this).attr("nro")
		);
		event.preventDefault();
	})
	
	this.find('.botoneraFeatures a').each(function(vuelta){
		
		$(this).attr("nro",vuelta);
	})
	
	function cargarData(href, act, sig){

		move = true
		
		if(!act){
		
			act = 0;
		}

		if(act > sig){
		
			pos = 610;
		
		}
		
		if(act <= sig ){
			
			pos = -610;
		}
		
		menu.nro = sig;

		//returo
		menu.find('.contentData').stop().animate({"left":pos},300, function(){
		
			//cargo
			$.post( href ,'',function(data){
				
				//ingreso
				menu.find('.contentData').stop();
				menu.find('.contentData').css({"left":(pos * -1)})
				menu.find('.contentData').html(data);
				menu.find('.contentData').animate({"left":0}, 300, function(){
					
					move = false;
					menu.find('.botoneraFeatures a').removeClass('selected');
					menu.find('.botoneraFeatures a:eq('+ menu.nro +')').addClass('selected')
				})
			})
		})
		
	}
	
	this.find('#antFeat').click(function(event){
		
		if(!menu.find('.botoneraFeatures a:eq('+ ( parseInt(menu.nro) - 1 ) +')').attr("href")){
			return false;
		}
		if(move){
			return false;
		}
		
		cargarData(
			menu.find('.botoneraFeatures a:eq('+ ( parseInt(menu.nro) - 1 ) +')').attr("href"),
			menu.nro,
			parseInt(menu.nro) - 1
		);
		event.preventDefault();
	})
	this.find('#sigFeat').click(function(event){
		
		if(!menu.find('.botoneraFeatures a:eq('+ ( parseInt(menu.nro) + 1 ) +')').attr("href")){
			return false;
		}
		if(move){
			return false;
		}
		
		cargarData(
			menu.find('.botoneraFeatures a:eq('+ ( parseInt(menu.nro) + 1 ) +')').attr("href"),
			menu.nro,
			parseInt(menu.nro) + 1
		);
		event.preventDefault();
	})
	
	this.find('.botoneraFeatures a:first').trigger('click')
}
