/* This script by $criptMaster B  Duall 2011 */
/* JQuery 1.6 needed */
/* www.duall.be */


$(document).ready(function(){
	$('a.media').media();
	RCnav();
	RCpopup();
	RCbannerKlik();
	RCaddAssoClass();
	RCtooltip();
	RCvalidateNL("div#form_Con_NL form");
	RCvalidateFR("div#form_Con_FR form");
	RCvalidatePRO_NL("div#form_Pro_NL form");
	RCvalidatePRO_FR("div#form_Pro_FR form");
	RCtasteNav();
	RCfluitend();
	RChomeSlider();
    RCexternal();
});
//------------------------------------------------------------------------------------------

function RChomeSlider() {
	if ($('#home_main').length) {
		$('#home_main').cycle({
			fx:	'scrollHorz', 
			prev: '.prevtrigger',
			next:	'.nexttrigger',
			timeout:  0, 
			easing: 'jswing',
			speed: 300,
			height: '470px'
		});
	
	};
};

//------------------------------------------------------------------------------------------


function RCtasteNav() {

/*
	//$('.top').addClass('hidden');
	$.waypoints.settings.scrollThrottle = 30;
	$('#products').find('#tasteNav ul').waypoint(function(event, direction) {
		$(this).parent().toggleClass('sticky', direction === "down");
		event.stopPropagation();
		//$('#tasteNav ul').localScroll({offset:-60,margin:true});
		
	});
 */
	$('#tasteNav ul').localScroll({offset:-80,margin:true});
	
	$('div.pack').waypoint({offset:80});
	
	var stickyPanelOptions = {
		 topPadding: 10,
		 afterDetachCSSClass: "active",
		 savePanelSpace: true
	 };

	$("#tasteNav").stickyPanel(stickyPanelOptions);

	$("body").delegate("div.pack", "waypoint.reached", function (event, direction) {
		var $active = $(this);
		if (direction === 'up') {
			$active = $active.prev();
		  }
		if (!$active.length) { $active.end(); }
		
		$(".pack-active").removeClass("pack-active");
		$active.addClass("pack-active");
		$(".selected").removeClass("selected");
		$("a[href=#"+$active.attr("id")+"]").addClass("selected");
		});
	if ($(window).height() > 1200) {
		$('#products').css('padding-bottom','400px');
	};
}


//------------------------------------------------------------------------------------------

function RCbannerKlik() {
		
	$('.homeActieBanner').click(function() {
		var linky = $(this).attr('title');
		//console.log(linky);
		window.open(linky);
	});
	
}

function RCtooltip() {

		$('ul.schap li').each(function(){
					tekst = $(this).text();
					if ($(this).hasClass('new')) {
						$(this).append('<div class="tooltipTekst">'+tekst+'<span class="new">new</span></div>');
					} else {
						$(this).append('<div class="tooltipTekst">'+tekst+'</div>');
					};
		});
		
		$('ul.schap li').hoverIntent(
				function(){
					$('.tooltipTekst').stop().hide();
					$(this).find('.tooltipTekst').show().animate({
						top:'+=10',
						opacity: 1
						}, 250, 'swing', function(){
					});
				},function(){
					$(this).find('.tooltipTekst').fadeOut('fast',function(){
					$('.tooltipTekst').attr('style',''); 
					});
				});
		
}

//------------------------------------------------------------------------------------------

function RCaddAssoClass(){
	if ($('#products').length) {
		$('body').addClass('assortiment');
	};
}

//------------------------------------------------------------------------------------------

function RCnav(){
	if($('a.active:first').parent('li').children('ul').length) {
		var childUl = $('a.active:first').parent('li').children('ul').html();
		$('#main_nav').append('<ul id="nav04"></ul>');
		$('#nav04').html(childUl);
	} else {
		$('#main_nav').remove();
	}
	$('#nav01 li > ul').hide();
	
	//console.log(childUl);

}

//------------------------------------------------------------------------------------------

function RCpopup(){
	if ($('.popup').length) {
		$('.popup').hide();
		$('.popupOpen').click(function() {
			popupID = $(this).attr('href');
			$('body').prepend('<div class="popupBg"></div>').find('.popupBg').hide();
			$(popupID).prepend('<a href="#" class="popupClose">&times;</a>');
			RCpopupCenter(popupID);
			$('.popupBg').fadeIn("slow");
			$(popupID).fadeIn("slow");
			$(window).resize(function(){RCpopupCenter(popupID);});
			$('.popupClose,.popupBg').click(function(){
				$('.popup:visible, .popupBg').fadeOut("slow",function(){
					$('.popupClose').remove();
					$('.popupBg').remove();
				});
				return false;
			});
			return false;
		});
	};	
}

function RCpopupCenter(popupID){
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	var popupWidth = $(popupID).width();
	var popupHeight = $(popupID).height();
	$(popupID).css({
		"z-index": 500,
		"position": "fixed",
		"top": 200,
		"left": windowWidth/2-popupWidth/2
	});
}

//------------------------------------------------------------------------------------------

function RCfluitend() {
	$('#tastaalkeuze .nl .bttn').hoverIntent(function() {
		$('.fluitendnl').fadeIn();
	},function() {
		$('.fluitendnl').fadeOut();
	});
	
	$('#tastaalkeuze .fr .bttn').hoverIntent(function() {
		$('.fluitendfr').fadeIn();
	},function() {
		$('.fluitendfr').fadeOut();
	});
}

//------------------------------------------------------------------------------------------

function RCvalidateNL(FORM) {
	if($(FORM).length){ // zijn de forms aanwezig op de pagina?
		$(FORM).validate({
			rules: {
				strPartName: "required",
				strAccountMail: {required: true, email: true}
			},
			messages: {
				strPartName: "<span>&uarr;</span> Dit veld is verplicht",
				strAccountMail: {
					required: "<span>&uarr;</span> Gelieve uw e-mailadres correct in te geven",
					email: "<span>&uarr;</span> e-mail moet in het volgende formaat: naam@domein.com"
				}
				}
		}); 
	}
}

function RCvalidateFR(FORM) {
	if($(FORM).length){ // zijn de forms aanwezig op de pagina?
			$(FORM).validate({
				rules: {
					strPartName: "required",
					strAccountMail: {required: true, email: true}
				},
				messages: {
					strPartName: "<span>&uarr;</span> Ce champ est obligatoire",
					strAccountMail: {
						required: "<span>&uarr;</span> Veuillez entrer une adresse e-mail valable",
						email: "<span>&uarr;</span> Veuillez entrer une adresse e-mail valable: *****@*****.**"
				}
				}
		});
	}
}
function RCvalidatePRO_NL(FORM) {
	if($(FORM).length){ // zijn de forms aanwezig op de pagina?
		$(FORM).validate({
			rules: {
				  strCompany: "required",
				  strEmployees: "required",
				  strName: "required",
				  strFunction: "required",
				  strGSM: "required",
				  strAddress1: "required",
				  strAddress2: "required",
				  strMail: { required: true, email: true}
			  },
			messages: {
				strCompany: "<span>&uarr;</span> Dit veld is verplicht",
				strEmployees: "<span>&uarr;</span> Dit veld is verplicht",
				strName: "<span>&uarr;</span> Dit veld is verplicht",
				strMail: {
					required: "<span>&uarr;</span> Gelieve uw e-mailadres correct in te geven",
					email: "<span>&uarr;</span> e-mail moet in het volgende formaat: naam@domein.com"
				},
				strFunction: "<span>&uarr;</span> Gelieve de functie van de verantwoordelijke in te vullen",
				strCompany: "<span>&uarr;</span> Dit veld is verplicht",
				strAddress1: "<span>&uarr;</span> Dit veld is verplicht",
				strAddress2: "<span>&uarr;</span> Dit veld is verplicht",
				strGSM: "<span>&uarr;</span> We hebben je telefoonnummer nodig om je te kunnen contacteren"
				}
		}); 
	}
}

function RCvalidatePRO_FR(FORM) {
	if($(FORM).length){ // zijn de forms aanwezig op de pagina?
		$(FORM).validate({
			rules: {
				  strCompany: "required",
				  strEmployees: "required",
				  strName: "required",
				  strFunction: "required",
				  strGSM: "required",
				  strAddress1: "required",
				  strAddress2: "required",
				  strMail: { required: true, email: true}
			  },
			messages: {
				strCompany: "<span>&uarr;</span> Ce champ est obligatoire",
				strEmployees: "<span>&uarr;</span> Ce champ est obligatoire",
				strName: "<span>&uarr;</span> Ce champ est obligatoire",
				strMail: {
					required: "<span>&uarr;</span> Veuillez entrer une adresse e-mail valable",
					email: "<span>&uarr;</span> Veuillez entrer une adresse e-mail valable: *****@*****.**"
				},
				strFunction: "<span>&uarr;</span> Veuillez entrer votre fonction",
				strCompany: "<span>&uarr;</span> Ce champ est obligatoire",
				strAddress1: "<span>&uarr;</span> Ce champ est obligatoire",
				strAddress2: "<span>&uarr;</span> Ce champ est obligatoire",
				strGSM: "<span>&uarr;</span> Afin de pouvoir vous contacter nous avons besoin de votre adresse numéro de GSM"
				}
		}); 
	}
}

function RCexternal() {
		$("a[rel=external]").click( function(){window.open($(this).attr("href")); return false;});
}




