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


$(document).ready(function(){
	DLLblurAnchors();
	HomeLink();
	HomeBackground();
	SetupTemoignages();
	Tabs();
	CMPbollen();
	Plus();
	DUALLvalidateFR('#new_generic_candidate');
	HiddenCandidates();
});


$.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 DLLblurAnchors(){ 
	if(document.getElementsByTagName) { 
		var a = document.getElementsByTagName("a"); 
		for(var i = 0; i < a.length; i++){ 
			a[i].onfocus = function(){this.blur();}; 
		} 
	} 
};

function HomeBackground(){
	var max = 7;
	var random = Math.floor(Math.random() * max) + 1;

	$('#pictures').css({backgroundImage: 'url(/images/bg0' + random + '.jpg)'});
	$('body#royco div#pictures').css({backgroundImage: 'url(/images/bgRoyco.jpg)'});
}

function SetupTemoignages(){
	$('#gezichtjes_hier a.gezichtje').click(function(){
		$('#blahblah_hier').html($(this).find('span').html());

		return false;
	});
	
	$("#gezichtjes_hier a.gezichtje").click(function(){
			$("#gezichtjes_hier a.gezichtje").removeClass('selected');
			$(this).addClass('selected');
		});
	
}

function Plus(){
	$('a.btnPlus').click(function(){
		$('a.btnPlus').show();
		openDIV = $(this).attr("href");
		$('.plusTekst').slideUp();
		
		$(this).prev('div'+openDIV).slideDown("slow");
		$(this).hide();
		return false;
	});
	
	$('a.close').click(function(){
		$('.plusTekst').slideUp();
		$('a.btnPlus').show();
	});
}


function noSpam(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').attr('link', banner.attr('title'));	
		$('#header').addClass('clickable');
		$('#header').click(function(){
			window.location = $(this).attr('link');
		});
	}
}

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 HomeLink(){
	$("#top h1").click(function(){
       location.href= "/index.html";
		});
	$("#top h1").mouseover(function () {
		$(this).css("cursor","pointer");
		});
}

function Tabs() {
	$("#tabs").tabs();
}

function DUALLvalidateFR(FORM) {
	if($(FORM).length){ // zijn de forms aanwezig op de pagina?
		//alert("Forms aanwezig!");
		$(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[education]': "required",
					'generic_candidate[cv]': "required",
					'generic_candidate[resume]': "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[education]': "Le champ formation doit être complété",
						'generic_candidate[cv]': "S'il vous plaît télécharger votre cv",
						'generic_candidate[resume]': "S'il vous plaît télécharger votre lettre de motivation",
						'generic_candidate[email]': 	{
								required: "Le champ e-mail doit être complété",
								email: "Use this structure: ---@---.--"	
								}
							}
		});
	} 
}

function HiddenCandidates() {
	var countHidden = 1;
	$('a#btnextraExperience').click(function() {
		$('#hiddenExperience0' + countHidden).show();
		countHidden = countHidden + 1;
		if(countHidden == 6) {
			$('a#btnextraExperience').hide();
		}
	});
}
