/* 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");
	nivoslider();
//	prettyphoto();
});

$.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: ---@---.--"	
								}
							}
			
		});
	} 
}

function nivoslider() {
	if ($('#slider').length) {
		$('#slider').nivoSlider({
			effect:'fade', //Specify sets like: 'random,fold,fade,sliceDown,sliceDown'
			slices:6,
			animSpeed:500, //Slide transition speed
			pauseTime:4000,
			startSlide:0, //Set starting Slide (0 index)
			directionNav:false, //Next & Prev
			directionNavHide:false, //Only show on hover
			controlNav:false, //1,2,3...
			controlNavThumbs:false, //Use thumbnails for Control Nav
			controlNavThumbsFromRel:false, //Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav:true, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:0.8, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){}, //Triggers after all slides have been shown
			lastSlide: function(){}, //Triggers when last slide is shown
			afterLoad: function(){} //Triggers when slider has loaded
		});
	}
}

$(function(){
    $('a.newWindow').click(function(){
        window.open(this.href);
        return false;
    });
});

function prettyphoto() {
    $("a[rel^='prettyPhoto']").prettyPhoto({
		animation_speed: 'slow', /* fast/slow/normal */
		slideshow: false, /* false OR interval time in ms */
		autoplay_slideshow: false, /* true/false */
		opacity: 0.60, /* Value between 0 and 1 */
		show_title: false, /* true/false */
		allow_resize: false, /* Resize the photos bigger than viewport. true/false */
		default_width: 500,
		default_height: 344,
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		horizontal_padding: 20, /* The padding on each side of the picture */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		wmode: 'opaque', /* Set the flash wmode attribute */
		autoplay: true, /* Automatically start videos: True/False */
		modal: false, /* If set to true, only the close button will close the window */
		deeplinking: true, /* Allow prettyPhoto to update the url to enable deeplinking. */
		overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
		keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		callback: function(){}, /* Called when prettyPhoto is closed */
		ie6_fallback: true,
		markup: '<div class="pp_pic_holder"> \
					<div class="ppt">&nbsp;</div> \
					<div class="pp_top"> \
						<div class="pp_left"></div> \
						<div class="pp_middle"></div> \
						<div class="pp_right"></div> \
					</div> \
					<div class="pp_content_container"> \
						<div class="pp_left"> \
						<div class="pp_right"> \
							<div class="pp_content"> \
								<div class="pp_loaderIcon"></div> \
								<div class="pp_fade"> \
									<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
									<div class="pp_hoverContainer"> \
										<a class="pp_next" href="#">next</a> \
										<a class="pp_previous" href="#">previous</a> \
									</div> \
									<div id="pp_full_res"></div> \
									<div class="pp_details"> \
										<div class="pp_nav"> \
											<a href="#" class="pp_arrow_previous">Previous</a> \
											<p class="currentTextHolder">0/0</p> \
											<a href="#" class="pp_arrow_next">Next</a> \
										</div> \
										<p class="pp_description"></p> \
										{pp_social} \
										<a class="pp_close" href="#">Close</a> \
									</div> \
								</div> \
							</div> \
						</div> \
						</div> \
					</div> \
					<div class="pp_bottom"> \
						<div class="pp_left"></div> \
						<div class="pp_middle"></div> \
						<div class="pp_right"></div> \
					</div> \
				</div> \
				<div class="pp_overlay"></div>',
		gallery_markup: '<div class="pp_gallery"> \
							<a href="#" class="pp_arrow_previous">Previous</a> \
							<div> \
								<ul> \
									{gallery} \
								</ul> \
							</div> \
							<a href="#" class="pp_arrow_next">Next</a> \
						</div>',
		image_markup: '<img id="fullResImage" src="{path}" />',
		flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
		quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
		iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
		inline_markup: '<div class="pp_inline">{content}</div>',
		custom_markup: '',
		social_tools: false /* '<div class="pp_social"><div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="facebook"><iframe src="http://www.facebook.com/plugins/like.php?locale=en_US&href='+location.href+'&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe></div></div>' html or false to disable */
	});
}
