
$(document).ready(function(){
	$(document.body).addClass('js-enabled');
	
	$('.text-teaser-block.has-link, .image-teaser-block.has-link div.main')
		.mouseover(function(){
			$(this).addClass('active');
		})
		.mouseout(function(){
			$(this).removeClass('active');
		})
		.click(function(){
			var link = $('div.link a', this);
			var url = link.attr('href');
			var target = link.attr('target');
			if ( url && !execPortfolioURL(url) )
			{
				if( target == "_blank" ){
					window.open(url);
				} else {	
					location = url;	
				}
			}
		})
		.addClass('clickable');
	
	if ( !IS_IE6 )
	{
		/*
		var products = $('#products-block li.item');
		$('#last-projects-block li.item')
			.each(function(i){
				if ( products.length - 1 < i )
				{
					return;
				}
				var project = $(this);
				var product = $(products.get(i));
				var height = Math.max(project.height(), product.height());
				product.height(height);
				project.height(height);
			});
		*/
		
		$('.text-teaser-block')
			.each(function(){
				$('.link a', this).height($(this).height() - 2);
			});
			
		$('.image-teaser-block')
			.each(function(){
				$('div.link a', this).height($(this).height());
			});
			
		$('#projects div.link a')
			.each(function(){
				var a = $(this);
				a.height(a.parent().parent().height() - 1);
			});
	}
	
	$('#middle a').click(function(){
		if ( execPortfolioURL(this.href) )
		{
			return false;
		}
	});
	
	$(document.body).append('<div id="ajax-loader" style="display: none;"></div>');
	
	$('#ajax-loader')
		.ajaxStart(function(){
			$(this).fadeIn('fast');
		})
		.ajaxStop(function(){
			$(this).fadeOut('fast');
		});
	
	Page.init();
	Overlay.init();
	Portfolio.init();
});

function execPortfolioURL(url)
{
	if ( url.indexOf('portfolio') != -1 )
	{
		var params = Util.extractQueryStringParams(url);
		if ( params.portfolio == 'open' )
		{
			Portfolio.open(params.opdrachtgever);
			return true;
		}
	}
	return false;
}
