$(document).ready(function() { 
	$("a.fancy").fancybox({
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'titlePosition' : 'over',
		'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">Arquivo(s) ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'; 	}
	});
	var ClassMain = '.team-thumb';
	var ClassHover = '.team-thumb-hover';
	$(ClassMain).hover(function(){
		var CHover = $(this).find(ClassHover);
		CHover.stop(true,true).fadeIn(300);
		$(".team-image-opacity").attr("style","opacity:0.4; filter:alpha(opacity=40);");
	},function(){
		$(".team-image-opacity").attr("style","");
		$(ClassMain+" "+ClassHover).fadeOut(150);	
	});
	$.jTwitter('conjuntosoul', 1, function(data){
		$('#tweets').empty();
		$.each(data, function(i, post){
			$('#tweets').append(post.text);
		});
	});
	$("#main").css("height",$("#content").height()+'px');
	$(".home-bg-go-down a, .home-bg-go-up a").click(function(){
		slider.clear();
	});
});	
var slider = {
	order: function(){
		var x = 1080,	/* $(window).height()+'px', */
			y = $('.slide');
		$.each(y, function(index,value){ 
			$(this).css('top',index*x+'px');
		});
	},
	next: function(){
		$active = $('.slide[value=active]').next();
		if($active.length===0){
			$('.slide').removeAttr('value');
			$('.slide:first').attr('value','active');
			$("#slider").stop(true,true).animate({
				marginTop: $('.slide').position().top+'px'
			}, 300);
			return false;
		} else {
			if($active.next().attr('id')==$active.attr("id")){
				$active = $('.slide:first');
				return false;
			} else {
				$('.slide').removeAttr('value');
				$active.attr('value','active');
				$("#slider").stop(true,true).animate({
					marginTop: '-'+$active.position().top+'px'
				}, 300);
				slider.session();
				return true;
			}
		}		
	},
	prev: function(){
		$active = $('.slide[value=active]').prev();
		if($active.length===0){
			$('.slide').removeAttr('value');
			$('.slide:last').attr('value','active');
			$("#slider").stop(true,true).animate({
				marginTop: $('.slide').position().top+'px'
			}, 300);
			return true;
		} else {
			if($active.prev().attr('id')==$active.attr("id")){
				$active = $('.slide:last');
				return true;
			} else {
				$('.slide').removeAttr('value');
				$active.attr('value','active');
				$("#slider").stop(true,true).animate({
					marginTop: '-'+$active.position().top+'px'
				}, 300);
				slider.session();
				return false;
			}
		}		
	},
	rotate: function(){
		var status = true;
		$play = setInterval(function(){
			if(status){
				status = slider.next();
			} else {
				status = slider.prev();
			}
		}, 10000);
	},
	clear: function(){
		clearInterval($play);
	},
	session: function(){
		$.ajax({
			url: $("#url").text()+"/slider?id="+$('.slide[value=active]').attr('id')
		});
	}
}

