$(document).ready(function(){
	menu();
});

function menu() {
	$('.nav_item:not(.active)').hover(function() {
		$(this).addClass('active');
		$(this).children('.nav_submenu').show();
	}, function() {
		$(this).removeClass('active');
		$(this).children('.nav_submenu').hide();
	});
}

function initCycle() {
	$('#load-slides').fadeOut(500);
	$('#slides').fadeIn(500);
	
	var nRand = Math.random()*4;
	nRand = Math.round(nRand);
	
	var sCycle = '';
	if(nRand == 2) {
		sCycle = 'utiliteit'
	} else if(nRand == 3) {
		sCycle = 'agrarisch'
	} else if(nRand == 4) {
		sCycle = 'industrie'
	} else {
		sCycle = 'renovatie'
	}
	
	$('.'+sCycle).show();
	$('#'+sCycle).addClass('activeSlide');
	
	$('.'+sCycle+' .slides').cycle({
		prev: '.prev',
		next: '.next'
	});
}

function initCycleOther() {
	$('#load-slides').fadeOut(500);
	$('#slides').fadeIn(500);
	$('#slides .slides').cycle({
		prev: '.prev',
		next: '.next'
	});
}

function initCycleHome() {
	var sActive = '.renovatie';
	$('.item').click(function() {
		var nTarget = '.'+$(this).children('div').attr('class');
		
		$(sActive+' .slides').cycle('destroy');
		$('.slidewrapper').fadeOut(500);
		$('#slidemenu .items .item.activeSlide').removeClass('activeSlide');
		$(this).addClass('activeSlide');
		$(nTarget).fadeIn(500);
		$(nTarget+' .slides').cycle({
			prev: '.prev',
			next: '.next'
		});	
		sActive = nTarget;	
	});
}

function initCycledetail() {
	$('#load-slides').fadeOut(500);
	$('#slides').fadeIn(500);
	$('.slides').cycle({
		prev: '#prev',
		next: '#next',
		timeout: 0,
		pagerAnchorBuilder: function(idx, slide) { 
			return '.items .item:eq(' + idx + ')'; 
		} 
	});
	$('a[rel=lightbox]').lightBox();	
}

function initLightbox(){
	var nTotal = $('.content .lightbox').size();		
	for(var nI = 1; nI <= nTotal; nI++){
		$('a.lightbox-'+nI+'').lightBox({
			containerResizeSpeed: 150						 
		});	
	}
}

function radioButtons() {
	$('.radio').click(function() {
		$('label.radio').removeClass('checked');	
		$('label.radio').find('input').attr('checked','');
		$(this).addClass('checked');
		$(this).find('input').attr('checked','checked');
	});
	$('.radio2').click(function() {
		$('label.radio2').removeClass('checked');	
		$('label.radio2').find('input').attr('checked','');
		$(this).addClass('checked');
		$(this).find('input').attr('checked','checked');
	});
	$('.checkbox').toggle(
		function() {
			$(this).prev().attr('checked','checked');
			$(this).addClass('checked');
			$(this).children('input').val('Ja');
		},
		function(){
			$(this).prev().attr('checked','');
			$(this).removeClass('checked');
			$(this).children('input').val('');
		}	
	);
}

function validateForm(p_sForm) {

	switch(p_sForm) {
		case 'contact':

			var rules = {};
			rules[oFields[p_sForm][2]] = {
				required: true,
				notags: true,
				nonumber: true,
				minlength: 2
			};
			rules[oFields[p_sForm][5]] = {
				required: true,
				email: true,
				notags: true,
				minlength: 2
			};
			
			var messages = {};
			messages[oFields[p_sForm][2]] = {
				required: 'Vul uw naam in.',
				notags: 'U mag geen tags invoeren.',
				nonumber: 'Vul een geldige naam in',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][5]] = {
				required: 'Vul uw e-mailadres in.',
				email: 'Vul hier een geldig e-mailadres in.',
				notags: 'U mag geen tags invoeren.',
				minlength: 'Vul minimaal 2 karakters in.'
			};
		
		break;
	}
	
	$('#'+p_sForm).validate({
		rules: rules,
		messages: messages,
		errorPlacement: function(error, element) {
			var obj = element.parent().next('div.icon');
			error.insertAfter(obj);
			obj.attr('class','icon invalid');
		},
		success: function(label) {
			label.prev('div.icon').attr('class','icon valid');
			label.remove();
		},
		submitHandler: function(form) {
			form.trigger('submit');
		}
	});	
}

function googlemaps(){
	var myCenter = new google.maps.LatLng(51.64450, 4.00462);
	var myOptions = {
	  zoom: 15,
	  center: myCenter,
	  mapTypeId: google.maps.MapTypeId.ROADMAP,	  
	  mapTypeControl: false,
	  scrollwheel: false
	}
	var myLatlng = new google.maps.LatLng(51.64450, 4.00462);
	var map = new google.maps.Map(document.getElementById("map"), myOptions);
	var image = new google.maps.MarkerImage('images/template/marker_hanse_staalbouw.png',
		new google.maps.Size(73, 50),
		// The origin for this image is 0,0.
		new google.maps.Point(0,0),
		// The anchor for this image is the base of the flagpole at 0,32.
		new google.maps.Point(40, 50)
	);
	var marker = new google.maps.Marker({
		position: myLatlng, 
		map: map,
		icon: image
	});
}
