if (typeof console == 'undefined') {
	var console = {
		info: function() {},
		dir: function() {},
		group: function() {},
		groupEnd: function() {}
	};
}

VDW = {
	serviceFile : '/views/projecten/dynamic_pages.php',
	container : $('.view'),
	preInit : function() {
		$('.anythingSlider li[title="link"]').addClass('link');
		$('.merken .view .text p:odd').addClass('odd');
		this.checkCurrent();
		this.init();
	},
	init : function() {
		this.slider();
		this.addBindings();
		this.processForms();
	},
	addBindings : function() {
		$('.anythingSlider li.link').bind('click', function() { VDW.banners($(this)); return false; });
		$('.foto_list li').bind('mouseover', function() { $(this).addClass('active'); });
		$('.foto_list li').bind('mouseout', function() { $(this).removeClass('active'); });
		
		$('.foto_list li').bind('click', function(){ VDW.loadPage($(this)); });
	},
	loadPage : function(el) {
		var oLink = el.find('a').attr('rel');
		
		$.ajax({
			method: 'get',
			url: VDW.serviceFile,
			data: 'p=' + oLink,
			dataType :'html',
		//	beforeSend: function(){$('#loader').show('fast');},
		//	complete: function(){ $('#loader').hide('fast');},
			success: function(data){
			//	console.dir(this);
				$(VDW.container).attr('id',oLink).html(data);
				$('.merken .view .text p:odd').addClass('odd');
				VDW.checkCurrent();
			}
		});
	},
	checkCurrent : function() {
		var oLink = $('.foto_list a');
		oLink.each(function(){
			if($(this).attr('rel') == $('.view').attr('id')) {
				$('.foto_list li.current').removeClass('current');
				$(this).parent().addClass('current');
			}
		});
		
	},
	slider : function() {
		$('.anythingSlider').anythingSlider({
			easing: "easeInOutExpo",        			// Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,                				// This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 5000,                    			// How long between slide transitions in AutoPlay mode
			startStopped: false,            			// If autoPlay is on, this can force it to start stopped
			animationTime: 600,             			// How long the slide transition takes
			hashTags: false,                 			// Should links change the hashtag in the URL?
			buildNavigation: true,         			 	// If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             			// If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",             				// Start text
			stopText: "Stop",               			// Stop text
			navigationFormatter: VDW.formatText			// Details at the top of the file on this use (advanced use)
		});
	},
	formatText : function(index, panel) {
	  return index + "";
	},
	banners : function(el) {
		var aHref = el.find('a').attr('href');
		window.open(aHref);
	},
	processForms : function() {
		var arrForm = $('form');
		
		arrForm.each(function() {
			var oForm = $(this);
			var formId = oForm.attr('id');		
			
			switch(formId) {
				case 'contactForm':
					VDW.checkContact(formId);
				break;
				
				default:
				
				break;
			}
		});
	},
	checkContact : function(formId) {
		var contactForm = '#' + formId;
		
		var validContact = $(contactForm).validate({
			rules		: {
				naam : {
					required : true,
					minlength : 2
				},
				bedrijfsnaam : 'required',
				adres : 'required',
				woonplaats : 'required',
				email: {
						required: true,
						email	: true
				},
				bericht : 'required'
				
			},
			messages	: {
				naam : {
					required	: 'Vul uw naam in.',
					minlength	: 'Uw naam moet tenminste 2 letters hebben.'
				},
				bedrijfsnaam : 'Vul een bedrijfsnaam in.',
				adres : 'Vul een adres in.',
				woonplaats : 'Vul een woonplaats in.',
				email			: {
					required	: 'Vul een geldig e-mailadres in.',
					email		: 'Vul een geldig e-mailadres in.'
				},
				bericht 		: 'Vul een bericht in.'
			},
			submitHandler : function(form) {
				form.submit();
			}
		});
		
		$.validator.addMethod("zip", function(value) {
			var regex = /\d{4}\s{0,1}\w{2}$/;
			return value.match(regex);
		}, 'Vul een geldige postcode in.');
		
		$.validator.addMethod("phone", function(ph, element) {
			if (ph == null) {
				return false;
			}
			var regex = ph.replace(/[\s()+-]|ext\.?/gi, "");
			return ((/\d{10,}/i).test(regex));
		}, "Vul een geldig telefoonnummer in.");
	}
};


$(document).ready(function(){
	VDW.preInit();
});
