var Video = {
	
	i: 0,
	limite: 0,
	show: null,
	prox: null,
	ante: null,
	botoes: null,
	youtube: null,
	
	start: function(){ 
		this.prox = $('div.lista_videos div.botoes a.proximo');
		this.ante = $('div.lista_videos div.botoes a.anterior-ina');
		this.show = $('div.lista_videos ul');
		this.limite = Math.ceil(($('div.lista_videos ul li').length - 3) / 3);
		this.botoes = $('div.lista_videos div.botoes a.bolinhas');
		this.youtube = $('div.fixo a.video_youtube');
		Video.prox.bind('click',Video.proximo);
		Video.ante.bind('click',Video.anterior);
		this.botoes.bind('click',Video.clicar);
		this.youtube.bind('click', Video.html);
		$(this.youtube[0]).trigger('click');
	},
	
	proximo: function(){
		if (Video.i < Video.limite) {
			Video.i++;
			var rolar = Video.i * 285;
			Video.show.animate({ 'margin-left': '-' + rolar + 'px' }, 600);
		}
		Video.verifica();
		return false;
	},
	
	anterior: function(){
		
		if (Video.i > 0) {
			Video.i--;
			var rolar = Video.i * 285;
			Video.show.animate({ 'margin-left': '-' + rolar + 'px'}, 600);
		}
		Video.verifica();
		return false;
	},
	
	verifica: function(){
		if (Video.i != 0) {
			Video.ante.removeClass('anterior-ina');
			Video.ante.addClass('anterior');
		} else {
			Video.ante.removeClass('anterior');
			Video.ante.addClass('anterior-ina');
		}
		if (Video.limite == Video.i) {
			Video.prox.removeClass('proximo');
			Video.prox.addClass('proximo-ina');
		} else {
			Video.prox.removeClass('proximo-ina');
			Video.prox.addClass('proximo');
		}
		Video.botoes.removeClass('inativo');
		Video.botoes.addClass('ativo');
		$(Video.botoes[Video.i]).addClass('inativo');
	},
	
	clicar: function () {
		var valor = $(this).attr('name'), sinal = null; Video.i = valor;
		var rolar = valor * (-285);
		Video.show.animate({ 'margin-left': rolar + 'px' }, 600);
		Video.verifica();
		return false;	
	},
	
	html: function () {
		var video = document.getElementById('barra_video'),
		    iframe = document.getElementById('iframe_youtube'),
			nome = this.name,
		    link = this.getAttribute('link'),
			detalhes = this.getAttribute('detalhes'),
			conteudo = '<iframe title="YouTube video player" width="301" height="220" src="http://www.youtube.com/embed/'+ 
				nome + '?wmode=opaque" frameborder="0" allowfullscreen></iframe>',
			detalhes = '<a href="'+ link +'" class="det" title="'+ detalhes + '">'+ detalhes +'</a> '+
				'<a href="'+ link +'" class="mais" title="Mais">Mais</a>';
		video.innerHTML = detalhes;
		iframe.innerHTML = conteudo; 		
		return false;
	}
};
