if (typeof (console) === 'undefined') {
	console = new function() {};
	console.log = function(message) {
		alert('Console log: ' + message);
	}
}


var autoPlay_interval = 0;


$(document).ready(function() {
	// IF BROWSER IS IE THEN SET HOVER CLASS ON TR
	if(jQuery.browser.msie) {
		$('table tr').hover(
			function () {
				$(this).addClass('hover');
			}, 
			function () {
				$(this).removeClass('hover');
			}
		);
    }
	
	//Externe links
	$("a[rel=external]").each(function(i){this.target="_blank";});
	
	// componenten
	$('.box-component > *:last').css('margin-bottom','0px')
	
	// FANCY BOX
	$("a.send_to_a_friend").fancybox({ 'hideOnContentClick': false, 'frameHeight': 500 });
	
	// quote
	$('p .quote-left').each(function() {
		var box_quote  = "";
		box_quote += "<span class='box-quote box-quote-left'>&#147;";
		box_quote += $(this).html();
		box_quote += "&#148;</span>";
		
		// $(this).before(box_quote);
		$(this).parent('p').prepend(box_quote);
	});
	$('p .quote-right').each(function() {
		var box_quote  = "";
		box_quote += "<span class='box-quote box-quote-right'>&#147;";
		box_quote += $(this).html();
		box_quote += "&#148;</span>";
		
		// $(this).before(box_quote);
		$(this).parent('p').prepend(box_quote);
	});
	
	// forms focus
	$('form input').focus(function() {
		$(this).parent().addClass('focus');
	});
	$('form input').blur(function() {
		$(this).parent().removeClass('focus');
	});
	$('form textarea').focus(function() {
		$(this).parent().addClass('focus');
	});
	$('form textarea').blur(function() {
		$(this).parent().removeClass('focus');
	});
	
	
	// SAME HEIGHT
	if($('#content_summary').length > 0) {
		var max_height = 0;
		$('#content_summary .column').each(function(){
			new_height = $(this).height();
			if(max_height < new_height) {
				max_height = new_height;
			}
		});
		
		$('#content_summary .column').each(function(){
			while($(this).height() < max_height) {
				var height = $(this).find('.box:last').height();
				$(this).find('.box:last').height(height + 1)
			}
		});
	}
	
	if($('div.quote').length > 0) {
		if($('div.quote .content').text() != '') {
			$('div.quote').show();
			setQuotePos();
		} else {
			$('div.quote').hide();
		}
	}

	$("#vacatures").tablesorter({widthFixed: true, widgets: ['zebra']});
	$("#vacatures").tablesorterPager({container: $("#pager"), size: 10});
	
	if(true) {
		autoPlay_interval = setInterval(autoPlay,8000);

	}
});

function autoPlay() {
	impressionsNext();
	var first_link = $('.thumbnails .holder a').get(1);
	setImpressionPhoto($(first_link));
}

function setImpressionPhoto(link) {
	// QUOTE GOTO HEIGHT (15px DOWN)
	var time = 400;
	var gotoHeight = parseFloat($('div.quote').css('top')) + 15;
	
	// ANIMATE QUOTE (HIDE)
	$('div.quote').animate({
		top: gotoHeight + 'px',
		opacity: 0
	}, time, 'swing', function(){
		
		// SET NEW QUOTE SETTINGS AND POSITION QUOTE
		$('div.quote div.content').html(link.find('.content').html());
		if(link.find('.content').text() != '') {
			$('div.quote').show();
			setQuotePos();
		} else {
			$('div.quote').hide();
		}
				
		// ANIMATE IMAGE (HIDE)
		$('#impression_image').animate({
			opacity: 0
		}, time, 'swing', function(){
			
			// SET NEW IMAGES VALUES
			$('#impression_image').attr('src',link.attr('href'));
			$('#impression_image').attr('alt',link.attr('title'));
			$('#impression_image').attr('title',link.attr('title'));
			
			// ANIMATE IMAGES (SHOW)
			$('#impression_image').animate({
				opacity: 1
			}, time, function() {
				
				// SET GOTO HEIGHT OF QUOTE AND POSITION 15px LOWER
				var gotoHeight = parseFloat($('div.quote').css('top'));
				$('div.quote').css('top', 0 - ($('div.quote').height() + 54) + 15 );
				
				// ANIMATE QUOTE (SHOW)
				$('div.quote').animate({
					top: gotoHeight + 'px',
					opacity: 1
				}, time, 'swing');
			});
		});
	});
}
function setQuotePos() {
	$('div.quote').css('top', 0 - ($('div.quote').height() + 54));
}
function impressionsNext() {
	var first_link = $('.thumbnails .holder a:first');
	var width = first_link.width() + parseInt(first_link.css('margin-right'));
	
	$('.thumbnails .holder').animate({ 
		left: (0 - width) + "px"
	}, 500, 'swing', function(){
		first_link.appendTo('.thumbnails .holder');
		first_link.css('display', 'none');
		first_link.fadeIn();
		$('.thumbnails .holder').css('left','0px');
	} );
}
function impressionsPrev() {
	var last_link = $('.thumbnails .holder a:last');
	var width = last_link.width() + parseInt(last_link.css('margin-right'));
	
	last_link.prependTo('.thumbnails .holder');
	$('.thumbnails .holder').css('left', (0 - width) + 'px');
		
	$('.thumbnails .holder').animate({ 
		left: "0px"
	}, 500, 'swing');
}
