// Schepnet JS init

$(function() {
	
	// pShadow
	$('#slider, #main_wrapper .block_25, .block_50, .block_75, .block_100, .block_25_black, .block_75_black, .project, .snelContact, .headerImage, #header_wrapper, .googleMaps, .mensen').pShadow({
    type: 'middle',
    depth: 10,
    strength: 2
	}).addClass('shadow');
	$('#footer_wrapper').addClass('shadow');
	$('#footer .block_25').removeClass('shadow');


	// prettyPhoto
	$("a[rel^='prettyPhoto']").prettyPhoto({
		default_width: 1280,
		default_height: 720
	});
	
	// slider
	$('#slider').slides({
		container: "slides",
		generateNextPrev: true,
		generatePagination: false,
		play: 6000,
		slideSpeed: 350,
		slideEasing: "easeOutQuart",
		hoverPause: true
	});
	
	// block hover
	$('.newsItem div, .project div').append('<div class="more"><span>Lees meer</span></div>');
	$('.newsItem, .project').hover(function() {
		$(this).addClass('hover');
		$(this).find('.more').stop().animate({ height: '25px' },100);
	},function() {
		$(this).removeClass('hover');	
		$(this).find('.more').stop().animate({ height: '0' },100);
	});
	
	// snelContact hover
	$('.snelContact').hover(function() {
		$(this).stop().animate({ backgroundPosition : '(0 -250px)' },200);
		$(this).addClass('hover');
	},function() {
		$(this).stop().animate({ backgroundPosition : '(0 0)' },200);
		$(this).removeClass('hover');	
	});
	
	// click function
	$('.newsItem, .snelContact, .project').click(function() {
		var url = $(this).find('a').attr('href');
		if(!url) {
			url = '/contact';	
		}
		window.location = url;
	});
		
	// mensen click (new window)
	$('.mensen').click(function() {
		var url = $(this).find('a').attr('href');
		if(!url) {
			url = '/contact';	
		}
		window.open(url);
	});

	// footer auto height
	var fHeight = $('#footer').innerHeight();
	$('#top_wrapper').css({'margin-bottom': 0-fHeight});
	$('#footer, .push').innerHeight(fHeight)
	$('#footer .block_25').innerHeight(fHeight);
	
	// zoek focus css
	var defaultText = 'Zoekterm';
	$('.searchInput').val(defaultText);
	
	$('.searchInput').focus(function() {
		if($(this).val() == defaultText) {
			$(this).val("");
		}
		$('.searchBtn').addClass('searchBtnFocus');
	});
	$('.searchInput').blur(function() {
		if($(this).val() == "") {
			$(this).val(defaultText);
		}
		$('.searchBtn').removeClass('searchBtnFocus');
	});
	
	// mensen hover effect
	$('.mensen').hover(function() {
		$(this).find('.mensenName').stop().fadeTo(100, 0.5);
		$(this).find('span').stop().animate({ height: '0' },100);
	}, function() {
		$(this).find('.mensenName').stop().fadeTo(100, 1);
		$(this).find('span').stop().animate({ height: '18px' },100);
	});
	
	// nieuws detail hoogte
	var h = $('.news_detail').innerHeight();
	console.log(h);
	var new_h = 0;
	if(h < (126)) {
		new_h = 126;
	} else if(h > 126 && h < 300) {
		new_h = 300;
	} else if(h > 300 && h < 460) {
		new_h = 474;
	}
	if(new_h != 0) {
		$('.news_detail').innerHeight(new_h);
	}
	
	//////////////////////////////////////////////
	// Other
	//////////////////////////////////////////////

	// news months
	$('#news_months a').click(function(e) {
		e.preventDefault();
		if(!$(this).parent().hasClass('HighLighted')){

			var realUrl = $(this).attr('href');
			var month = $(this).text().split(' ')[0];
			var year = $(this).text().split(' ')[1];
			var ajaxUrl = '/nieuws/?month='+month+'&year='+year;

			$('#news_months li').removeClass('HighLighted');	
			$('#homeNews').empty();		
			$('#homeNews').load(ajaxUrl+' .newsItem',function () {
				add_content_behaviours();
			});
			$(this).parent().addClass('HighLighted');


			//change the url also
			history.pushState({}, "Schepnet - "+$(this).text(), realUrl);
			_gaq.push(['_trackPageview']);
		}
	})

	// news tags
	var getTags = function () {
		var tags = [];
		$('#news_tags input:checked').each(function () {
		  if ($(this).val() != 'on') {
		    tags.push($(this).val());
		  }
		});

		//eerste waarde deleten
		if (tags.length > 0) {
		  tagsString = tags.join(',');
		  tagsString = '&tagids=' + tagsString;
		} else {
		  tagsString = '';
		}
		return tagsString;
	}	

  $('.chkAll').each( function(index,elm) {
		$(elm).click( function() {
			var allCheckboxes = $(this).parent().parent().find('input').not('.chkAll');
			allCheckboxes.attr('checked',$(this).attr('checked')== 'checked');
		})
	}) 

	$('#news_tags input').change(function () { 
		$('#homeNews').empty();         
		$('#homeNews').load('/nieuws/?' + getTags()+' .newsItem',function () {
			add_content_behaviours();
		});
  })
});
