/*	NETVLIES.NL SCRIPTS
	Author:	Sebastiaan Smid, Netvlies
	
	dependencies: 
	- jQuery v 1.2.2
	- jQuery.lightbox 0.4
	----------------------------------------------------*/

// Body onload function 
$(function() {

    if ($.browser.msie && $.browser.version == '6.0') {
        DD_belatedPNG.fix('*');
    }

	// Lightbox
	//	$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel

	var imageArray = new Array();
	var activeImage = 0;

	$('a[@rel*=lightbox]').click( function() {
		objClicked= this;
		imageArray = new Array();
		activeImage = 0;

		// maak een array van alle thumbs
		if ( $('a[@rel*=lightbox]').length == 1 ) {
			imageArray.push($('a[@rel*=lightbox]').getAttribute('href'));
		} else {
			// Add an Array with the href and title atributess
			for ( var i = 0; i <  $('a[@rel*=lightbox]').length; i++ ) {
				imageArray.push($('a[@rel*=lightbox]')[i].getAttribute('href'));
			}
		}

		while (imageArray[activeImage] != objClicked.getAttribute('href') ) {
			activeImage++;
		}

		$('#verbouwings_fotos').hide();
		$('#project-nav').show();
		$('#photohdr').show();
		$('#projectomschrijving').hide();
		$('#project-photo').show();
		$('.photo-omschrijving').css({ display: 'none' });

		var objImagePreloader = new Image();
		objImagePreloader.onload = function() {
			$('#project-img').attr('src', objClicked.getAttribute('href'));
			$('#phototxt_'+$(objClicked).attr('id')).css({ display: 'block'});
			$('#klanttxt, #klanthdr').hide();

			$('#content-box').height('auto');
			h = ((Math.floor($('#content-box').innerHeight() / 34)+1)*34)+13;
			$('#content-box').height(h);

			//	clear onLoad, IE behaves strange with animated gifs otherwise
			objImagePreloader.onload=function(){};
			return false;
		};
		objImagePreloader.src =  objClicked.getAttribute('href');
		showhideButtons();
		return false;

	});

	function loadNextImage() {
		$('#project-nav .prev').hide();
		$('#project-nav .next').hide();
		$('#project-img').attr('src', '/img/x.gif');
		$('.photo-omschrijving').hide()

		if(activeImage+1 < imageArray.length) {
			activeImage++;

			var objImagePreloader = new Image();
			objImagePreloader.onload = function() {
				$('#project-img').attr('src', imageArray[activeImage]);
				$('.photo-omschrijving').hide()
				$('#phototxt_'+(activeImage+1)).show();

				$('#content-box').height('auto');
				h = ((Math.floor($('#content-box').innerHeight() / 34)+1)*34)+13;
				$('#content-box').height(h);

				//	clear onLoad, IE behaves strange with animated gifs otherwise
				objImagePreloader.onload=function(){};
				return false;
			};
			objImagePreloader.src =  imageArray[activeImage];
			showhideButtons()
		}
	}

	function loadPrevImage() {
		$('#project-nav .prev').hide();
		$('#project-nav .next').hide();
		$('#project-img').attr('src', 'img/x.gif');
		$('.photo-omschrijving').hide()

		if(activeImage-1 >= 0 ) {
			activeImage = activeImage - 1;

			var objImagePreloader = new Image();
			objImagePreloader.onload = function() {
				$('#project-img').attr('src', imageArray[activeImage]);
				$('#phototxt_'+(activeImage+1)).show();


				$('#content-box').height('auto');
				h = ((Math.floor($('#content-box').innerHeight() / 34)+1)*34)+13;
				$('#content-box').height(h);

				//	clear onLoad, IE behaves strange with animated gifs otherwise
				objImagePreloader.onload=function(){};
				return false;
			};
			objImagePreloader.src =  imageArray[activeImage];

			showhideButtons();
		}
	}

	function showhideButtons() {
		if(activeImage+1 >= imageArray.length) {
			$('#project-nav .next').hide();
			$('#project-nav .prev').show();
		} else if(activeImage == 0) {
			$('#project-nav .prev').hide();
			$('#project-nav .next').show();
		} else {
			$('#project-nav .prev').show();
			$('#project-nav .next').show();
		}
	}


	$('#project-nav .back').click( function() {
		$('#verbouwings_fotos').show();
		$('#project-nav').hide();
		$('#project-photo').hide();
		$('#photohdr').hide();
		$('#projectomschrijving').show();
		$('.photo-omschrijving').hide();
		$('#klanttxt, #klanthdr').show();
		$('#project-img').attr('src', 'img/x.gif');
	});

	$('#project-nav .next').click( function() {
		loadNextImage();return false;
	});
	$('#project-nav .prev').click( function() {
		loadPrevImage();return false;
	});

	resetcontentbox();
	
	if( $('#bestelalbum').attr('id') == 'bestelalbum' ){

		// maak een array van alle thumbs
		if ( $('a[@rel*=lightbox]').length == 1 ) {
			imageArray.push($('a[@rel*=lightbox]').getAttribute('href'));
		} else {
			// Add an Array with the href and title atributess
			for ( var i = 0; i <  $('a[@rel*=lightbox]').length; i++ ) {
				imageArray.push($('a[@rel*=lightbox]')[i].getAttribute('href'));
			}
		}

		$('#projectalbum').hide();
		$('#project-nav').show();
		$('#project-photo').show();

		var objImagePreloader = new Image();
		objImagePreloader.onload = function() {
			$('#project-img').attr('src',imageArray[activeImage]);
			//	clear onLoad, IE behaves strange with animated gifs otherwise
			objImagePreloader.onload=function(){};
			return false;
		};
		objImagePreloader.src = imageArray[activeImage];

		showhideButtons();
	}
	
});

function resetcontentbox() {
	h = ((Math.floor($('#content-box').innerHeight() / 34)+1)*34)+5;
	$('#content-box').height(h);
}

function contactform_submit(e) {
	if(document.getElementById('voornaam').value == '') {
		alert('U dient uw voornaam in te geven.');
		return false;
	}
	if(document.getElementById('achternaam').value == '') {
		alert('U dient uw achternaam in te geven.');
		return false;
	}
	if(document.getElementById('email').value == '') {
		alert('U dient uw e-mail adres in te geven.');
		return false;
	}
	if(document.getElementById('bericht').value == '') {
		alert('U dient een bericht in te geven.');
		return false;
	}
	return true;
}

function bestelform_submit(e) {
	if(document.getElementById('voornaam').value == '') {
		alert('U dient uw voornaam in te geven.');
		return false;
	}
	if(document.getElementById('achternaam').value == '') {
		alert('U dient uw achternaam in te geven.');
		return false;
	}
	if(document.getElementById('straat').value == '') {
		alert('U dient een straat in te geven.');
		return false;
	}
	if(document.getElementById('huisnummer').value == '') {
		alert('U dient een huisnummer in te geven.');
		return false;
	}
	if(document.getElementById('postcode_cijfers').value == '') {
		alert('U dient de cijfers van uw postcode in te geven.');
		return false;
	}
	if(document.getElementById('postcode_letters').value == '') {
		alert('U dient de letters van uw postcode in te geven.');
		return false;
	}
	if(document.getElementById('woonplaats').value == '') {
		alert('U dient uw woonplaats in te geven.');
		return false;
	}
	if(document.getElementById('telefoon').value == '') {
		alert('U dient uw telefoon in te geven.');
		return false;
	}
	if(document.getElementById('email').value == '') {
		alert('U dient uw e-mail adres in te geven.');
		return false;
	}
	return true;
}


