$(document).ready(function() {

	$('.one-col-post:last').addClass('last');
	
	$('.two-col-post:eq(0), .two-col-post:eq(1)').addClass('first-row');
	$('.two-col-post:odd').addClass('alt');

	$('.post-related ul li:first').addClass('first');
	$('.post-related ul li:eq(3)').addClass('last');

	$('.two-col-post').click(function() {
		window.location=$(this).find(".figure a").attr("href");
		return false;
	});

	$('#page-figure .info').click(function() {
		window.location=$(this).find("h4 a").attr("href");
		return false;
	});

	$('.post-related ul li').click(function() {
		window.location=$(this).find(".figure").attr("href");
		return false;
	});

	$('.two-col-post').hover(function() {
			
		$(this).find('.description').stop(true, false).animate({ 'bottom': 0 }, '300', 'easeInOutExpo');

	}, function() {
		
		var $this = $(this);
		$this.find('.description').stop(true, false).animate({ 'bottom': - $this.find('.description').outerHeight() + 40 }, '300', 'easeInOutExpo');

	})

	$('.two-col-post').each(function() {
		
		var $this = $(this);

		$this.find('.description').css({ 'bottom': - $this.find('.description').outerHeight() + 40 })

	})

	var twocolpostsize = $('.two-col-post').size();
	
	if( isEven(twocolpostsize) ) {
		$('.two-col-post:last').addClass('last').prev().addClass('last');
	} else {
		$('.two-col-post:last').addClass('last')
	}

	$('form.wpcf7-form select').tzSelect();

	$('#mc-embedded-subscribe-form input[type="text"]').each(function() {

		var usedinput = $(this);		
		var usedinputtitle = $(this).attr('title');

		function addTitle() { 
			if(usedinput.val() == "") {
			$(usedinput).val(usedinputtitle);
		}};

		function remove() {
			if(usedinput.val() == usedinputtitle) {
				$(usedinput).val("");
			}
		}

		addTitle();

		$(this).blur(addTitle).focus(remove);

	});

	// $('#mc-embedded-subscribe').click(function() {

	// 	$('#mc-embedded-subscribe-form input[type="text"]').each(function() {

	// 		var usedinput = $(this);		
	// 		var usedinputtitle = $(this).attr('title');

	// 		if( usedinput.val() == usedinputtitle) {
	// 			usedinput.val('')
	// 		}

	// 	});		
		
	// })

});

$(window).load(function() {
	
	$('#page-figure.slider').slides({
		container: 'holder',
		generateNextPrev: true,
		generatePagination: false,
		effect: 'slide',
		slideSpeed: 500,
		play: 5000,
		slideEasing: "easeInOutExpo",
		animationComplete: function(current) {
			changeSlideInfo(current-1);
			changePagNr(current);
		}
	})

	changeSlideInfo(0);
	$('#page-figure.slider .pag .total').html( $('$page-figure.slider .slide').size() );

	function changePagNr(nr) {
		
		$('#page-figure.slider .pag .current').html(nr);

	}

	function changeSlideInfo(nr) {
		
		var newContent = $('#page-figure.slider .slide:eq(' + nr + ')').children('.intro-text').html();
		$('#page-figure.slider .info .intro-text').html(newContent);

	}

	$('.gallery').slides({
		container: 'holder',
		generateNextPrev: true,
		generatePagination: false,
		paginationClass: 'pag',
		effect: 'slide',
		slideSpeed: 300,
		slideEasing: "easeInOutExpo"
	})

	if( $('.gallery .pag ul li').size() >  5 ) {
		
		$('.gallery .pag ul').easyListSplitter({
			colNumber: 2
		})
		
	}

	$('.footer-nav ul').easyListSplitter({
		colNumber: 2
	})

		
	if( $('#main').height() > $('#sidebar').height() ) {
		$('#sidebar').height($('#main').height());
	}

})

function isEven(value) {
	return (value%2 == 0);
}
