
$(function(){
			
	/////////////LOGO///////////////////////
	$('#logo').click(function(){
		window.location = "index.php";
	});
	
	/////////////LOGIN///////////////////////
	$('#login').click(function(){
		$('#loginOverlay').fadeIn();
	});
	
	$('#loginOverlay, #closeLogin').click(function(e){
		if (this == e.target) {
			$('#loginOverlay').fadeOut();
		}
	});
	
	$('#register').click(function(){
		$('#registerOverlay').fadeIn();
	});
	
	$('#registerOverlay, #closeRegister').click(function(e){
		if (this == e.target) {
			$('#registerOverlay').fadeOut();
		}
	});
	
	/////////////NAVIGATION DROPDOWN/////////
	$("#menu li").stop().hover(function(){
		$(this).find('ul:first').stop(true, true).fadeIn();
	},function(){
		$(this).find('ul:first').stop(true, true).fadeOut();
	});
			
	$(".ValidateForm").validate();
	$(".loginForm").validate();
	$(".registerForm").validate();
	
	///////////LOCKED PAGES///////
	$('.locked').click(function(e){
		e.preventDefault();
		$('#login').trigger('click');
	});
	
	///////////GALLERY IMAGE CENTER IN MASK/////////////
//	$('.gallery li').each(function(){
//		if ($(this).find('img').width() > $(this).find('img').height()) {
//			$(this).find('img').height('100%');
//			var minLeft = 0 - ($(this).find('img').width() / 2);
//			var css = {
//				'left' : '50%',
//				'margin-left' : minLeft 
//			}
//			$(this).find('img').css(css);
//		} else {
//			$(this).find('img').width('100%');
//			var minTop = 0 - ($(this).find('img').height() / 2);
//			var css = {
//				'top' : '50%',
//				'margin-top' : minTop 
//			}
//			$(this).find('img').css(css);
//		}
//	});
	$(window).load(function(){
		$('.gallery li').each(function(index) {
			if ($(this).find('img').height() == $(this).find('img').width()) {
				$(this).find('img').width('100%');
			} else if ($(this).find('img').height() > $(this).find('img').width()) {
				$(this).find('img').width('100%');
				$(this).find('img').css('margin-top' ,'-25%');
			} else {
				$(this).find('img').height('100%');
				$(this).find('img').css('margin-left' ,'-25%');
			}
		});
	});
	
	////////////FANCYBOX/////////////
	$('.fancybox').fancybox({
		overlayColor	: '#000',
		overlayOpacity	: '0.6',
		opacity			: true,
		titlePosition : 'inside',
		titleFormat   : function(title, currentArray, currentIndex, currentOpts) {
			return '<span class="floatLeft"><a href="'+title+'">Lees verder &raquo;</a></span><span class="floatRight">'+(currentIndex + 1) + ' / ' + currentArray.length+'</span>';
		}
	});
	
	$('.fancybox2').fancybox({
		overlayColor	: '#000',
		overlayOpacity	: '0.6',
		opacity			: true,
		titlePosition : 'inside',
		titleFormat   : function(title, currentArray, currentIndex, currentOpts) {
			return '<span class="floatLeft"><a href="'+title+'">Lees verder &raquo;</a></span><span class="floatRight">'+(currentIndex + 1) + ' / ' + currentArray.length+'</span>';
		}
	});
	
	
	////////////ICONS///////////
	$('.icon').hover(function(){
		$(this).stop().fadeTo('100','0.6');
	}, function(){
		$(this).stop().fadeTo('100','1');
	});
	
	////////////FLAGS///////////
	$('.flag').hover(function(){
		$(this).stop().fadeTo('100','0.6');
	}, function(){
		$(this).stop().fadeTo('100','1');
	});
	
	$('#newsArchive').cycle({
		fx: "scrollVert",
		timeout: 0,
		startingSlide:   0,
		pager:  '.pager',
		pagerAnchorBuilder: function(idx, slide) {
			return '<a href="#">&bull;</a>';
		}
	});
		
	$('#agendaCycle').cycle({
		fx: "scrollHorz",
		timeout: 0,
		startingSlide:   0,
		pager:  '.pager',
		pagerAnchorBuilder: function(idx, slide) {
			return '<a href="#">&nbsp;&bull;&nbsp;</a>';
		},

		before: function(slide,next){
				$('#agendaCycle').animate({
				'height' :  $(next).height()
				}, 1000);
		}
	});
		
});

window.onload = function(){

	var projectHeight = $('#projects').height() - 155;
	if (projectHeight > $('.content').height()) {
		$('.content').height(projectHeight);
	} else {
		$('#projects').height($('.content').height() + 155);
	}

}

