
// JavaScript Document
$(document).ready(function() {

	$('.imagecontainer').cycle();
	$('a[rel=external]').attr('target','_blank');
	$('#navigationlist li:last').css('margin', '0');
	
	$('p.readMore').bind('click', function(){
		$(this).hide();
		$(this).parent('div').find('.moreInfo').slideDown('fast', function(){
			$(this).css('display', 'inline');
		});		
	})
	$('p.closeMore').bind('click', function(){
		$(this).parent('div.moreInfo').slideUp('fast', function(){
			$(this).css('display', 'none');
		});		
		$(this).parent('div.moreInfo').parent('div').find('p.readMore').show();
	})
	$('#btnsnelcontact, .bluebutton, .redbutton').hover(function(){$(this).css('opacity','.9');},function(){$(this).css('opacity','1');});
	$('#functie').change(function(){
		if($(this).attr('selectedIndex') == 4){
			$('.kiloots').show();
		}else{
			$('.kiloots').hide();
		}
	})
	
	if($('img.batibouw').length > 0){
		var img = $('img.batibouw').attr('alt');
		$('img.batibouw').attr('alt',$('img.batibouw').attr('title'));
		
		showPopup(img);
	}
	
	$('#btnsnelcontact').removeAttr('href');
	$('#btnsnelcontact, #snelContact').click(function(){
		//alert('test');
		$('#quickContactWrapper,#quickContact').fadeIn();
		//$('#quickContact').fadeIn();
	});
	
	$('#quickContact #closeWindow').click(function(){
		//alert('test');
		$('#quickContactWrapper,#quickContact').fadeOut();
		//$('#quickContact').fadeIn();
	});
	
	$('#sendQuick').click(function(){
		var j = 0;
		var fnme = '';
		var lang = $(this).attr('rel');
		$('#quickContact input[type=text]').each(function(){
			if($(this).val() == '' && $(this).parent('p').find('label').html() != 'E-mail *' && $(this).parent('p').find('label').html() != 'Straat + nr.' && $(this).parent('p').find('label').html() != 'Gemeente'){
				fnr = j;
				fnme = $(this).parent('p').find('label').html();
				fid = $(this);
				return false;
			}
			
			if($(this).parent('p').find('label').html() == 'E-mail *' && !validMail($(this).val())){
				fnr = j;
				fnme = $(this).parent('p').find('label').html();
				fid = $(this);
				return false;
			}
			
			j++;
		})
		
		if(fnme != ''){
			alert_form(fnr, fnme, fid, lang, true);
		}else{
			$('#quickContactForm').submit();
		}
	})
	
	var email = $('#newsLetter').val()
	$('#newsLetter').focus(function(){
		if($(this).val() == email){
			$(this).val('');
			$(this).css({'color':'#282828'})
		}
	})
	
	$('#newsLetter').blur(function(){
		if($(this).val() == '' || $(this).val() == email){
			$(this).val(email);
			$(this).css({'color':'#bbb'})
		}
	})
	
	$('#newsLetterBtn').bind('click', function(){
		var wrong 	= '';
		var correct	= '';
		switch($('html').attr('lang')){
			case 'nl':
					wrong 	= 'Fout e-mailadres';
					correct	= 'U bent ingeschreven';
			break;
			case 'fr':
					wrong 	= 'Mauvaise adresse e-mail';
					correct	= 'Vous �tes inscrit';
			break;
			case 'en':
					wrong 	= 'Email address error';
					correct	= 'You are registered';
			break;
			case 'de':
					wrong 	= 'E-Mail-Adresse Fehler';
					correct	= 'Sie sind registriert';
			break;
			case 'tr':
					wrong 	= 'Yanlis e-posta adresi';
					correct	= 'Eger kayitli';
			break;
		}
											   
		var email = $('#newsLetter').val();
		if(!validMail(email)){
			$('#error').html(wrong);
		}else{
			$.ajax({
				url		: '/ajax.php',
				type	: 'POST',
				data	: {
					emailAdres : email
				},
				success	: function(){
					$('#newsLetter').attr('disabled', 'disabled');
					$('#newsLetter').css({
						'color'	: '#00aa00'
					})
					$('#error').html('');
					$('#newsLetter').val(correct)
					
				}
			
			})	
		}
	})
	
})

function setKiloots(){
	$('#functie').attr('selectedIndex', 4);
	$('.kiloots').show();
}

function setDrop(i){
	$('#functie').attr('selectedIndex', i);
}

function startAnimation(){
	$('#animationbtn').html('<div id="animationholder"></div>');
	//var params = {wmode: "transparent"};
	//var flashvars = {datafile: "/media/xml/pages_en.xml", path: "/media/img/pages/"};
	swfobject.embedSWF("/media/swf/animatie_zout.swf", 'animationholder', "100%", "100%", "9.0.0", "/media/swf/expressInstall.swf");
}

function showPopup(img){
	$('body').append(' \
		<div class="popup-wrapper"></div> \
		<div class="popup-image"> \
			<img src="http://www.aqua-service.be'+img+'" alt="batibouw" title="batibouw" width="680" height="300" > \
		</div> \
	');
	
	$('.popup-wrapper, .popup-image').fadeIn();
	
	$('.popup-wrapper, .popup-image').click(function(){
		$('.popup-wrapper, .popup-image').fadeOut();
	});
	//console.log(img);
}
