$(document).ready(function(){
	$('.faq .opener').click(function(){
		$(this).parents('.faq ul li').find('.slide').slideToggle(700);
		return false;
	});
	$('.develop-box .opener').click(function(){
		$('.develop-box .slide').slideToggle(600);
		$('.develop-box').toggleClass('develop-box-active');
		return false;
	});
	$('.btn-send').hover(function(){
		$(this).toggleClass('btn-send-hover')
	});
	var maxheight = 0;
	var i = 0;
	$('.works-list li').each(function(index) {
		if (maxheight <= ($(this).find('.holder .visual img').height())){
			maxheight = $(this).find('.holder .visual img').height();
		};
		if (((index+1) % 4) == 0){
			for(i = index-3;i <= index;i++){
				$('.works-list li').eq(i).find('.visual').height(maxheight);
			};
			maxheight = 0;
		};
	});
	if ($('.works-list li').size() % 4 != 0){
		maxheight = 0;
		var qtylastli = $('.works-list li').size() % 4;
		for(i = ($('.works-list li').size() - qtylastli);i <= ($('.works-list li').size()- 1);i++){
			if (maxheight <= ($('.works-list li').eq(i).find('.holder .visual img').height())){
				maxheight = $('.works-list li').eq(i).find('.holder .visual img').height();
			};
		};
		$('.works-list li').slice(-qtylastli).find('.visual').height(maxheight);
	};
	var maxhli = 0;
	$('.comments-list li').each(function(index) {
		$(this).find('.qty').html(index + 1 + '/' + $('.comments-list li').size());
		if (maxhli <= ($(this).height())){
			maxhli = $(this).height();
		};
	});
	$('.comments-list').height(maxhli);
	if ($('.comments-list').size()>0) {
		var commentwidth = $('.comments-list').width();
		$('.comments-list li').width(commentwidth).css({left:commentwidth});
		$('.comments-list li.active').css({left:0});
	};
	checkLastFirst();
	$('.comments-nav .next').click(function(){
		if ($(this).hasClass('not-active')) {
			return false;
		}
		$('.comments-list li.active').animate({left:-commentwidth}, 1000).removeClass('active').next().animate({left:0}, 1000).addClass('active');
		checkLastFirst();
		return false;
	});
	$('.comments-nav .prev').click(function(){
		if ($(this).hasClass('not-active')) {
			return false;
		}
		$('.comments-list li.active').animate({left:commentwidth}, 1000).removeClass('active').prev().animate({left:0}, 1000).addClass('active');
		checkLastFirst();
		return false;
	});
	var teamh = $('.team-box').outerHeight();
	$('.team-box .text').height(teamh);
	$('.team-list li a').click(function(){
		window.location.hash = $(this).attr('rel');
		var teamtext = $(this).text() + '<span> &mdash; ' +  $(this).parent().find('span em').text() + '</span>';
		if ($(this).parent().hasClass('active')){
			return false;
		};
		$('.team-box h2').animate({opacity:0}, 400, function(){
			$('.team-box h2').html(teamtext);
		});
		if ($(this).parent().index()<$('.team-list li.active').index()){
			$('.text:last').after('<div class="text" style="height:' + teamh + 'px; top:100%;"><div class="visual"><img src="'+$(this).attr('href')+'" alt="" /></div><dl>'+$(this).parent().find('dl').html()+'</dl></div>');
			$('.text:first').animate({top:"-100%", opacity:"0"}, 600, function(){
				$('.text:first').remove();
			});
			$('.text:last').css({opacity:0}).animate({top:0, opacity:1}, 600);
		} else {
			$('.team-list').after('<div class="text" style="height:' + teamh + 'px; top:-100%;"><div class="visual"><img src="'+$(this).attr('href')+'" alt="" /></div><dl>'+$(this).parent().find('dl').html()+'</dl></div>');
			$('.text:last').animate({top:"100%", opacity:"0"}, 600, function(){
				$('.text:last').remove();
			});
			$('.text:first').css({opacity:0}).animate({top:0, opacity:1}, 600)
		};
		$('.team-list li').removeClass('active');
		$(this).parent().addClass('active');
		$('.team-box h2').animate({opacity:1}, 400);
		return false;
	});
	if (window.location.hash != ''){
		$('.team-list li a[rel='+window.location.hash.substr(1)+']').click();
	};
});
$(window).resize(function(){
	var commentwidth = $('.comments-list').width();
	$('.comments-list li').width(commentwidth);
});
function checkLastFirst(){
	if ($('.comments-list li.active').is(':first-child')){
		$('.comments-nav .prev').addClass('not-active');
	} else {
		$('.comments-nav .prev').removeClass('not-active');
	};
	if ($('.comments-list li.active').is(':last-child')){
		$('.comments-nav .next').addClass('not-active');
	} else {
		$('.comments-nav .next').removeClass('not-active');
	};
};

