// JavaScript Document
var videoThumbInd = 1;
var videoThumbMax = 3;
var videoThumbTime = 750;
var videoThumbInterval = null;


function videoNext(){
	
	var nv = videoBoxInd + videoBoxInt;
	
	if(nv > videoBox.length - videoBoxInt) nv = videoBox.length - videoBoxInt;
	
	videoBoxInd = nv;
	
	scrollToVideo();

}

function videoPrev(){
	
	var nv = videoBoxInd - videoBoxInt;
	
	if(nv < 0) nv = 0;
	
	videoBoxInd = nv;
	
	scrollToVideo();
	
}

function scrollToVideo(elem){
	
	if(!elem) elem = $('vi' + videoBox[videoBoxInd]);

	var fxs = new Fx.Scroll('barraVideoScroll');
	
	fxs.start(elem.getPosition($('barraVideoScrollImagens')).x, 0);
	
}

function overVideo(vid, yid){

	videoThumbInd = 1;
	
	if(videoThumbInterval) clearInterval(videoThumbInterval);
	
	videoThumbInterval = playThumb.periodical(videoThumbTime, this, [vid, yid]);
	
	$('lv' + vid).setStyle('display', 'block');
	$('lv' + vid).setStyle('opacity', '0');
	$('lv' + vid).fade('in');
	
}

function outVideo(vid, yid){

	videoThumbInd = 1;
	
	if(videoThumbInterval) clearInterval(videoThumbInterval);
	
	$('vi'+vid).src = 'http://img.youtube.com/vi/' + yid + '/1.jpg';

	$('lv' + vid).fade('out');
}

function playThumb(vid, yid){

	videoThumbInd++;
	if(videoThumbInd > videoThumbMax) videoThumbInd = 1;
	
	if($('vi'+vid)){
		$('vi'+vid).src = 'http://img.youtube.com/vi/' + yid + '/' + videoThumbInd + '.jpg';
	}

}

function overProg(pid){

	$('imgNoAr').setStyle('display', 'none');
	$('linkNoAr').removeClass('sel');
	
	$('imgProg'+pid).setStyle('display', 'inline');
	$('imgProg'+pid).setStyle('opacity', '0');
	$('imgProg'+pid).fade('in');
	$('linkProg'+pid).addClass('sel');
	
}

function outProg(pid){

	$('imgNoAr').setStyle('display', 'inline');
	$('imgNoAr').setStyle('opacity', '0');
	$('imgNoAr').fade('in');
	$('linkNoAr').addClass('sel');
	
	$('imgProg'+pid).setStyle('display', 'none');
	$('linkProg'+pid).removeClass('sel');
	
}

function ligarSlideshow(id){
	
	
	  var showDuration = 5000;
	  var container = $(id);
	  var images = container.getElements('img');
	  var currentIndex = 0;
	  var interval;
	  /* opacity and fade */
	  images.each(function(img,i){ 
		if(i > 0) {
		  img.set('opacity',0);
		}
	  });
	  /* worker */
	  var show = function() {
		images[currentIndex].fade('out');
		images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
	  };
	  /* start once the page is finished loading */
	  window.addEvent('load',function(){
		interval = show.periodical(showDuration);
	  });
	  
	
		
}
