function showPreview(coords)
{
	if (parseInt(coords.w) > 0)
	{
		var rx = 100 / coords.w;
		var ry = 100 / coords.h;

		$('#preview').css({
			width: Math.round(rx * 500) + 'px',
			height: Math.round(ry * 370) + 'px',
			marginLeft: '-' + Math.round(rx * coords.x) + 'px',
			marginTop: '-' + Math.round(ry * coords.y) + 'px'
		});
	}
}

$(document).ready(function(){
	$('#header').cycle({timeout:3000,speed:1500});
	/* Formulieren submit */
	$('form > fieldset > a.submit-form').click(function(event){
		event.preventDefault();
		$(this).parents('form').submit();
	});
	/* Zoek icoontje */
	$('#search-bar > a > img').hover(function(){
			$(this).attr('src', base_url +'resources/images/search-hover.png');
		},function(){
			$(this).attr('src', base_url +'resources/images/search.png');
		}
	);
	
	/* Foto Fancybox */
	$('a[rel="fancybox"]').fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition'		: 'outside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.9,
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return (title.length ? title : '') + '';
		}
	});
	
	$('a.fancybox_if').fancybox({
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titleShow'			: false,
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.9,
		'type'				: 'iframe',
		'width'				: 700,
		'height'			: 500
	});
	
	$('#crop-avatar').Jcrop({
		onChange: showPreview,
		onSelect: showPreview,
		aspectRatio: 1
	});
});
