$(document).ready(function () {
	$('.scroller').scrollLeft(0);
	var activeAnimation = false;
	$('.content .post').each(function(){
		var id = $(this).attr('class').replace('post post-','');
		var scrollwidth = 4;
		var prtt = 0;
		$('.post-' + id + ' .imgGallery .thumbs ul li').each(function(){
			prtt = $(this).width() + 36;
			scrollwidth += prtt;
		})
		if (scrollwidth < 930) {
			$('.post-' + id + ' .prox a, .post-' + id + ' .ante a').hide()
		}
		
		$('.post-' + id + ' .imgGallery .thumbs ul').width(scrollwidth)
		
		$('.prox a').click(function(){
			if (activeAnimation == false){
				activeAnimation = true;
				$('.scroller').stop().animate({scrollLeft: "+=" + prtt}, function(){
					activeAnimation = false;
				})
			}
		})
		$('.ante a').click(function(){
			if (activeAnimation == false){
				activeAnimation = true;
				$('.scroller').stop().animate({scrollLeft: "-=" + prtt}, function(){
					activeAnimation = false;
				})
			}
		})

		$('.post-' + id + ' .big div').hide()
		$('.post-' + id + ' .big div:first-child,.post-' + id + ' .imgGallery .thumbs ul li:first-child').show().addClass('show')
		$('.post-' + id + ' .imgGallery .thumbs ul li:first-child').children().css({'border-color':'#fff', 'opacity':'1'})
		$('.post-' + id + ' .imgGallery .thumbs ul li').click(function(){
			if (activeAnimation == false) {
				if (!$(this).hasClass("show")) {
					activeAnimation = true;
					var tsrc = $(this).index();
					$('.post-' + id).find('.big .show').removeClass('show').fadeOut(600)
					$('.post-' + id).find('.big div:eq(' + tsrc + ')').addClass('show').fadeIn(600, function (){
						activeAnimation = false;
					})
					$('.post-' + id).find('.thumbs ul li').removeClass('show').children().stop().animate({'border-color':'#000', 'opacity':'0.4'}, 599);
					$(this).addClass('show').children().stop().animate({'border-color':'#fff', 'opacity':'1'}, 599);
					
				}
			}
		})
		var btw = $('.ccrtg').width();
		var bth = $('.ccrtg').outerHeight(true);
		$('.ccrtg .cctxt').add('.ccrtg .ccbg').width(btw);
		$('.ccrtg .cctxt').add('.ccrtg .ccbg').height(bth);
		$('.ccrtg .ccbg').css({'opacity':'0.4'});
		$('.post-' + id + ' .thumbs').css({'margin-top':'-120px'});
		$('.post-' + id + ' .thumbs .tbbg').height($('.scroller').innerHeight() + 4).css({ 'opacity': '0.4' });
		$('.post-' + id + ' .thumbs ul li').not('.show').css({ 'opacity': '0.4' });
		
		$('.ccrtg').click(function(){
			if ($(this).hasClass('open')){
				$(this).find('.cctxt').text('OPEN');
				$(this).parent().stop().animate({'margin-top':'-16px'}, 400, function(){
					$(this).find('.ccrtg').removeClass('open').addClass('close');
				});
			} else {
				$(this).find('.cctxt').text('CLOSE');
				$(this).parent().stop().animate({'margin-top':'-120px'}, 400, function(){
					$(this).find('.ccrtg').removeClass('close').addClass('open');
				})
			}
		});
		//$('.post-' + id + ' .thumbs').stop().animate({'margin-top':'-104px'}, 400)		
	});
	
	
	$('.post .thumbs ul li div').mouseover(function (e) {
		$(this).parent().not('.show').stop().animate({'opacity':'1', 'border-color':'#000'})
	}).mouseout(function (e) {
		$(this).parent().not('.show').stop().animate({'opacity': '0.4', 'border-color':'#000'})
	});
	
	$('.post .video').each(function(){
		var vd = $(this).text()
		$(this).append('<iframe src="http://player.vimeo.com/video/' + vd + '" width="1024" height="567" frameborder="0"></iframe>')
	});
	
	$('.page_navigation').append('<div class="clear"></div>')
})
