/* This script by $criptMaster B & Stijnster Duall / Skylight 2009 */
/* JQuery 1.2.6 needed */
/* www.duall.be */


$(document).ready(function(){
	DUALLblurAnchors();
	CMPbackground();
	CMPscrollers();
	CMProute();
	CMPdo_da_shuffle();
	CMPbollen();
	CMPbounce();
	CMPhomeNewsLinks();
	CMPhomeDropdown();
	DUALLvalidateNL(".Taal_nl #new_generic_candidate");
	DUALLvalidateFR(".Taal_fr #new_generic_candidate");
	DUALLvalidateEN(".Taal_en #new_generic_candidate");
});


$.fn.extend({
	random: function(count){
		this.addClass('temporary_random');
		while((random_set = $('.temporary_random')).length > count){
			$(random_set[Math.floor(Math.random() * random_set.length)]).removeClass('temporary_random');
		}
		random_set.removeClass('temporary_random');
		return random_set;
	},
	shuffle: function(){
		var count = (this.length * 2);
		for(i = 0; i < count; i++){
			element = $(this[Math.floor(Math.random() * this.length)]);
			element.parent().append(element);
		}
		return this;
	}
});

function DUALLblurAnchors(){ 
	if(document.getElementsByTagName) { 
		var a = document.getElementsByTagName("a"); 
		for(var i = 0; i < a.length; i++){ 
			a[i].onfocus = function(){this.blur();}; 
		} 
	} 
};

function DUALLnoSpam(user,domain){
	locationstring = "mailto:" + user + "@" + domain + ".be";
	window.location = locationstring;
};

function CMPscrollers(){
	// needs jcarousel plugin
	$('ul#ULmerken').jcarousel({
		visible: 6,
		scroll: 6,
		vertical: false
	});
	$('ul#ULhistory').jcarousel({
		visible: 3,
		scroll: 3,
		vertical: false
	});
	$('ul#ULmission').jcarousel({
		visible: 1,
		scroll: 1,
		vertical: false
	});
}

function CMPbackground(){
/*	$('ul#banners').hide();*/
	banner = $('ul#banners li.active');

	if(banner.length != 1){
		all_banners = $('ul#banners li');
		banner = $(all_banners[Math.floor(Math.random() * all_banners.length)]);
	}

	$('#header').css('background-image', 'url(' + banner.text() + ')');
	$("#topbanner").addClass(banner.attr('class'));
	$("#merkenenbannerswrapper").addClass(banner.attr('class'));

	if(banner.attr('title').length > 0){
		$("#header #logo").after("<a id='IElink'></a>");
		$('a#IElink').attr('href', banner.attr('title'));	
		$('a#IElink').addClass('clickable');
	}
}

function CMProute(){
	$('#route').accordion({
		active: false,
		header: 'h3'
	});
}

function CMPbounce(){
	$("ul#ULmerken li a").hover(function(){
//			$(this).animate({borderTop: "1px solid white"},150);
			$(this).addClass('borderwhite');
		},function(){
//			$(this).animate({borderTop: "5px solid white"},150);
			$(this).removeClass('borderwhite');
	});

}

function CMPdo_da_shuffle(){
	$('ul#testimonialnav li.shuffle').hide().random(4).shuffle().show();
}

function CMPbollen(){
	$(".bol").hover(
	function(){
		//CMPwereldnaam(this); 
		var tietel = $(this).attr("title");
		$("#inleiding").css('display', 'none');
		$("#info"+tietel).toggleClass("hover");
//		$("#info"+tietel).slideToggle("slow");
	},
	function(){
		var tietel = $(this).attr("title");
		$("#inleiding").css('display', 'block');
		$("#info"+tietel).toggleClass("hover");
//		$("#info"+tietel).slideToggle("slow");
	});
}



function CMPhomeNewsLinks(){
//	var meerLink = $("a.meerLink").attr('href');
	$("div.post").click(function(){
		var meerLink = $(this).find('a.meerLink').attr('href');
		location.href= meerLink;
		});
	$("div.post").mouseover(function () {
		$(this).css("cursor","pointer");
		});
}

function CMPhomeDropdown() {
	$("select.jumpmenu").change(
		function() {
			location.href = this.options[this.selectedIndex].value;
			
		});
}


function DUALLvalidateNL(FORM) {
	if($(FORM).length){ // zijn de forms aanwezig op de pagina?
		$(FORM).validate(
			{
				rules:	{
					'generic_candidate[firstname]': "required",
					'generic_candidate[lastname]': "required",
					'generic_candidate[address]': "required",
					'generic_candidate[zipcode]': "required",
					'generic_candidate[city]': "required",
					'generic_candidate[phone]': "required",
					'generic_candidate[email]': 	{	
							required: true, 
							email: true
							}
						},
						
				messages:	{
						'generic_candidate[firstname]': "We hebben je voornaam nodig om je te kunnen contacteren" ,
						'generic_candidate[lastname]': "We hebben je achternaam nodig om je te kunnen contacteren" ,
						'generic_candidate[address]': "We hebben je adres nodig om je te kunnen contacteren" ,
						'generic_candidate[zipcode]': "We hebben je postcode nodig om je te kunnen contacteren" ,
						'generic_candidate[city]': "We hebben je woonplaats nodig om je te kunnen contacteren" ,
						'generic_candidate[phone]': "We hebben je telefoonnummer nodig om je te kunnen contacteren" ,
						'generic_candidate[email]': "We hebben je e-mailadres nodig om je te kunnen contacteren" ,
						'generic_candidate[email]': 	{
								required: "We hebben je e-mailadres nodig om je te kunnen contacteren",
								email: "Gebruik deze structuur: ---@---.--"	
								}
							}
			
		});
	} 
}

function DUALLvalidateEN(FORM) {
	if($(FORM).length){ // zijn de forms aanwezig op de pagina?
		$(FORM).validate(
			{
				rules:	{
					'generic_candidate[firstname]': "required",
					'generic_candidate[lastname]': "required",
					'generic_candidate[address]': "required",
					'generic_candidate[zipcode]': "required",
					'generic_candidate[city]': "required",
					'generic_candidate[phone]': "required",
					'generic_candidate[email]': 	{	
							required: true, 
							email: true
							}
						},
						
				messages:	{
						'generic_candidate[firstname]': "firstname cannot be blank" ,
						'generic_candidate[lastname]': "lastname cannot be blank" ,
						'generic_candidate[address]': "address cannot be blank" ,
						'generic_candidate[zipcode]': "postal code cannot be blank" ,
						'generic_candidate[city]': "city cannot be blank" ,
						'generic_candidate[phone]': "phone cannot be blank" ,
						'generic_candidate[email]': 	{
								required: "email cannot be blank",
								email: "Use this structure: ---@---.--"	
								}
							}
			
		});
	} 
}

function DUALLvalidateFR(FORM) {
	if($(FORM).length){ // zijn de forms aanwezig op de pagina?
		$(FORM).validate(
			{
				rules:	{
					'generic_candidate[firstname]': "required",
					'generic_candidate[lastname]': "required",
					'generic_candidate[address]': "required",
					'generic_candidate[zipcode]': "required",
					'generic_candidate[city]': "required",
					'generic_candidate[phone]': "required",
					'generic_candidate[email]': 	{	
							required: true, 
							email: true
							}
						},
						
				messages:	{
						'generic_candidate[firstname]': "Le champ prénom doit être complété" ,
						'generic_candidate[lastname]': "Le champ nom doit être complété" ,
						'generic_candidate[address]': "Le champ adresse doit être complété" ,
						'generic_candidate[zipcode]': "Le champ code postal doit être complété" ,
						'generic_candidate[city]': "Le champ ville doit être complété" ,
						'generic_candidate[phone]': "Le champ téléphone doit être complété" ,
						'generic_candidate[email]': 	{
								required: "Le champ e-mail doit être complété",
								email: "Use this structure: ---@---.--"	
								}
							}
			
		});
	} 
}
