$(document).ready(function()
{
	/* PLAIN OLD MARQUEE */
	
    $('marquee').marquee('pointer').mouseover(function () {
        $(this).trigger('stop');
    }).mouseout(function () {
        $(this).trigger('start');
    });
	

	/* POSITION THE FOOTER */
	
	positionFooter();
	$(window).resize(function() {
		positionFooter();
	});
	
	/* LIGHTBOX FOR THE EXPOSITION PAGE */
	
	if($('#expolist a').length){
		$('#expolist a').nvsAlbum({
			overlayBackground: 		'#fff',
			overlayTransparancy: 	0.7,
			overlaySpeed:			500,
			popUpBackground:		'#7c6359'
		})
	};
	
	/* REMOVE X AND Y PARAMATERS FROM SEARCH*/
	
	$('#frm-search').submit(function(){
		$('#frm-search')[0].submit();
		return false;
	});
	
	replaceSubmitButton('#question form, #quickscan');
	

	$('#files .file .delete').click(function(){
		var id = (this.parentNode.parentNode.id.toString().split('_')[1]);
		var fileinput = $('<input type="hidden" name="delete_files[]" value="'+id+'" /><input class="file" type="file" name="files[]" />');
		$(this.parentNode).replaceWith(fileinput);
		return false;
	});
	
	$('#form1').submit(function(){
		$('#form1').unbind('submit');
		$('#form1').attr('target', '_blank');
		$('#form1').submit();

		var url = String(window.location)+'?ideal=1';
		setTimeout(function(){
			location.href = url;
		},0);
		return false;
	});
	
	/* Show hide "Het contract heef x pagina's " */
	
	var quickscan_radio = $('#quickscan input[name=options\[quickscan\]]');
	var show_hide_pages = function(){
		var value = '';
		quickscan_radio.each(function(i, el){
			if(el.checked){
				value = el.value
			}
		});
		if (value == 'Contract') {
			$('#quickscan .aantal_paginas').removeClass('hidden');
		} else {
			$('#quickscan .aantal_paginas').addClass('hidden');
		}
		
	}
	quickscan_radio.change(show_hide_pages)
	.click(show_hide_pages)
	.change();
	
	/* QUICKSCAN CALCULATOR */
	
	var calculateQuickscan = function() {
		var amount = 0;
		$('#quickscan li:not(.hidden) .inhoud:checked').each(function() {
			amount = amount + parseInt($(this).attr('amount'));
		});
		$('#quickscan .total .amount').text(amount);
	}	
	$('#quickscan .inhoud').change(calculateQuickscan);
	calculateQuickscan();
});

function positionFooter() {	
	// if the window is bigger than the content put the footer on the bottom of the screen
	if($(window).height() > $('#body-wrapper').height()) {
		$('#footer').css({ position: 'absolute' });
	// otherwise just put it directly below the content
	} else {
		$('#footer').css({ position: 'relative' });
	}
}

function replaceSubmitButton(obj) {
	if ($(obj).length > 0) {
		var a;
		$('input[type=submit]', obj).replaceWith(
			$('<a class="sbmt-replaced"></a>').html(
				$('input[type=submit]', obj).val()
			).click(function() {
				$(obj).submit();
			})		
		);
	}
}

