// -----------------------------------------------------------------------------------
// JQUERY VALIDATION -  GENERAL USE
// -----------------------------------------------------------------------------------
/*
 * Translated default messages for the jQuery validation plugin.
 * Locale: NL
 */
jQuery.extend(jQuery.validator.messages, {
        required: "Dit is een verplicht veld.",
        remote: "Controleer dit veld.",
        email: "Vul hier een geldig e-mailadres in.",
        url: "Vul hier een geldige URL in.",
        date: "Vul hier een geldige datum in.",
        dateISO: "Vul hier een geldige datum in (ISO-formaat).",
        number: "Vul hier een geldig getal in.",
        digits: "Vul hier alleen getallen in.",
        creditcard: "Vul hier een geldig creditcardnummer in.",
        equalTo: "Vul hier dezelfde waarde in.",
        accept: "Vul hier een waarde in met een geldige extensie.",
        maxlength: jQuery.validator.format("Vul hier maximaal {0} tekens in."),
        minlength: jQuery.validator.format("Vul hier minimaal {0} tekens in."),
        rangelength: jQuery.validator.format("Vul hier een waarde in van minimaal {0} en maximaal {1} tekens."),
        range: jQuery.validator.format("Vul hier een waarde in van minimaal {0} en maximaal {1}."),
        max: jQuery.validator.format("Vul hier een waarde in kleiner dan of gelijk aan {0}."),
        min: jQuery.validator.format("Vul hier een waarde in groter dan of gelijk aan {0}.")
});


/*
 * Localized default methods for the jQuery validation plugin.
 * Locale: NL
 */
jQuery.extend(jQuery.validator.methods, {
	date: function(value, element) {
		return this.optional(element) || /^\d\d?[\.\/-]\d\d?[\.\/-]\d\d\d?\d?$/.test(value);
	},
	number: function(value, element) {
		return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
	}
});

// -----------------------------------------------------------------------------------


// -----------------------------------------------------------------------------------
// JCAROUSELLITE 1.0.1
// -----------------------------------------------------------------------------------
(function($){$.fn.jCarouselLite=function(o){o=$.extend({btnPrev:null,btnNext:null,btnGo:null,mouseWheel:false,auto:null,speed:200,easing:null,vertical:false,circular:true,visible:3,start:0,scroll:1,beforeStart:null,afterEnd:null},o||{});return this.each(function(){var b=false,animCss=o.vertical?"top":"left",sizeCss=o.vertical?"height":"width";var c=$(this),ul=$("ul",c),tLi=$("li",ul),tl=tLi.size(),v=o.visible;if(o.circular){ul.prepend(tLi.slice(tl-v-1+1).clone()).append(tLi.slice(0,v).clone());o.start+=v}var f=$("li",ul),itemLength=f.size(),curr=o.start;c.css("visibility","visible");f.css({overflow:"hidden",float:o.vertical?"none":"left"});ul.css({margin:"0",padding:"0",position:"relative","list-style-type":"none","z-index":"1"});c.css({overflow:"hidden",position:"relative","z-index":"2",left:"0px"});var g=o.vertical?height(f):width(f);var h=g*itemLength;var j=g*v;f.css({width:f.width(),height:f.height()});ul.css(sizeCss,h+"px").css(animCss,-(curr*g));c.css(sizeCss,j+"px");if(o.btnPrev)$(o.btnPrev).click(function(){return go(curr-o.scroll)});if(o.btnNext)$(o.btnNext).click(function(){return go(curr+o.scroll)});if(o.btnGo)$.each(o.btnGo,function(i,a){$(a).click(function(){return go(o.circular?o.visible+i:i)})});if(o.mouseWheel&&c.mousewheel)c.mousewheel(function(e,d){return d>0?go(curr-o.scroll):go(curr+o.scroll)});if(o.auto)setInterval(function(){go(curr+o.scroll)},o.auto+o.speed);function vis(){return f.slice(curr).slice(0,v)};function go(a){if(!b){if(o.beforeStart)o.beforeStart.call(this,vis());if(o.circular){if(a<=o.start-v-1){ul.css(animCss,-((itemLength-(v*2))*g)+"px");curr=a==o.start-v-1?itemLength-(v*2)-1:itemLength-(v*2)-o.scroll}else if(a>=itemLength-v+1){ul.css(animCss,-((v)*g)+"px");curr=a==itemLength-v+1?v+1:v+o.scroll}else curr=a}else{if(a<0||a>itemLength-v)return;else curr=a}b=true;ul.animate(animCss=="left"?{left:-(curr*g)}:{top:-(curr*g)},o.speed,o.easing,function(){if(o.afterEnd)o.afterEnd.call(this,vis());b=false});if(!o.circular){$(o.btnPrev+","+o.btnNext).removeClass("disabled");$((curr-o.scroll<0&&o.btnPrev)||(curr+o.scroll>itemLength-v&&o.btnNext)||[]).addClass("disabled")}}return false}})};function css(a,b){return parseInt($.css(a[0],b))||0};function width(a){return a[0].offsetWidth+css(a,'marginLeft')+css(a,'marginRight')};function height(a){return a[0].offsetHeight+css(a,'marginTop')+css(a,'marginBottom')}})(jQuery);



// -----------------------------------------------------------------------------------
// SUPERFISH v1.4.8 / http://users.tpg.com.au/j_birch/plugins/superfish
//
// Superfish v1.4.8 - jQuery menu widget
// Copyright (c) 2008 Joel Birch
//
// Dual licensed under the MIT and GPL licenses:
// 	http://www.opensource.org/licenses/mit-license.php
// 	http://www.gnu.org/licenses/gpl.html
//
// CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
// -----------------------------------------------------------------------------------
//

(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				//menu.sfTimer=setTimeout(function(){
				//	o.retainPath=($.inArray($$[0],o.$path)>-1);
				//	$$.hideSuperfishUl();
				//	if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				//},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'current',
		pathLevels	: 1,
		delay		: 400,
		animation	: {opacity:'show', height: 'show'},
		speed		: 300,
		autoArrows	: false,
		dropShadows : false,
		disableHI	: true,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);



/*
 * jQuery Character Justify plugin 0.1
 * http://heychinaski.com
 * Licensed under the GPL license:
 *   http://www.gnu.org/licenses/gpl.html
 */
(function($) {
  /*
   * Calculates the spacing required for a given element.
   * current - element to calculate
   * width - width to aim to justify at
   */
  var calculateSpacing = function(current, width) {
      // Don't let word spacing screw us up
      current.css("word-spacing", "0px");
      // create a hidden clone
      var clone = current.clone();
      clone.hide();
      var text = clone.text();  
      clone.text(text.replace(/\s+/g, "_"));
      // Temporarily insert the clone so we can measure it
      current.before(clone);
      // Reset the letter spacing while we measure the span
      clone.css("letter-spacing", "0px");
      clone.css("float", "left");
      var noSpaceText = clone.text();
      var normalWidth = clone.innerWidth();
      // Work out the difference between the current size of text
      // and the size we should be at
      var widthDifference = (width) - normalWidth;
      //  How many letters in the text?
      var textLength = (text.length);
      textLength -= 1;
      var letterSpacing = (widthDifference) / (textLength);
      // Remove the clone again
      clone.remove();
      return letterSpacing;
  }

  jQuery.fn.characterJustify = function(width, speed, easing, callback) {
    var maxSpacing = 0;
    var last = this.get(this.length - 1);
    var actualWidth = this.innerWidth();
    var widthToUse = actualWidth;
    // If nothing is passed in use the current width
    if(typeof(width) != "undefined" && !isNaN(width) && width > 0) { widthToUse = width; }
    // For each element
    this.each(function() {
      if($(this).text().split(/\s+/).length > 1) { maxSpacing = Math.max(calculateSpacing($(this), actualWidth), maxSpacing); }
    });
    widthToUse = Math.min(actualWidth - (2 * maxSpacing), widthToUse);
    // For each element
    this.each(function() {
      var letterSpacing = calculateSpacing($(this), widthToUse);
      // Not animating?
      if(typeof(speed) == "undefined" || speed <= 0) {
        $(this).css({letterSpacing: letterSpacing + "px"});
      } else if($(this).get(0) == last) {
        // Only callback on the last element
        $(this).animate({letterSpacing: Math.round(letterSpacing) + "px"}, speed, easing, callback);
      } else {
        $(this).animate({letterSpacing: Math.round(letterSpacing) + "px"}, speed, easing);
      }
    });
  };

  jQuery.fn.characterUnjustify = function(spacing, speed, easing, callback) {
    var last = this.get(this.length - 1);
    $(this).each(function() {
      var toSpace;
      if(typeof(spacing) == "undefined" || isNaN(spacing) || spacing <= 0) { toSpace = 1; } else { toSpace = spacing; }
      if(typeof(speed) == "undefined" || speed <= 0) {
        $(this).css({letterSpacing: "" + toSpace + "px"});
      } else {
        if($(this).get(0) == last) {
          $(this).animate({letterSpacing: "" + toSpace + "px"}, speed, easing, callback);
        } else {
          $(this).animate({letterSpacing: "" + toSpace + "px"}, speed, easing);
        }
      }
    });
  };
}(jQuery));






// -----------------------------------------------------------------------------------
// JQUERY INITS
// -----------------------------------------------------------------------------------
 $(document).ready(function(){ 

	// init main-menu | settings set above in main script
	$('ul.sf-menu').superfish();

	// handle search fields
	//var jInput_Search = $('.searchform_text').val();
	//$('.searchform_text').focus(function(){	if ($(this).val()==jInput_Search) { $(this).val(''); $(this).removeClass('do_gray'); }  });
	//$('.searchform_text').blur(function(){	if ($(this).val()=='') { $(this).val(jInput_Search); $(this).addClass('do_gray'); }  	});
	//$('.searchform_button').click(function(){		$('#search_form_id').submit();   });


	// CALL ME FORM
	// --------------------------------------------------------------------
	var jInput_CallMenu_company = $('#CallMeBedrijfsnaam').val();
	$('#CallMeBedrijfsnaam').focus(function(){	if ($(this).val()==jInput_CallMenu_company) { $(this).val(''); $(this).removeClass('light_gray'); }  });
	$('#CallMeBedrijfsnaam').blur(function(){	if ($(this).val()=='') { $(this).val(jInput_CallMenu_company); $(this).addClass('light_gray'); }  	});

	var jInput_CallMenu_name = $('#CallMeNaam').val();
	$('#CallMeNaam').focus(function(){	if ($(this).val()==jInput_CallMenu_name) { $(this).val(''); $(this).removeClass('light_gray'); }  });
	$('#CallMeNaam').blur(function(){	if ($(this).val()=='') { $(this).val(jInput_CallMenu_name); $(this).addClass('light_gray'); }  	});
	
	var jInput_CallMenu_phone = $('#CallMeTelefoonnummer').val();
	$('#CallMeTelefoonnummer').focus(function(){	if ($(this).val()==jInput_CallMenu_phone) { $(this).val(''); $(this).removeClass('light_gray'); }  });
	$('#CallMeTelefoonnummer').blur(function(){	if ($(this).val()=='') { $(this).val(jInput_CallMenu_phone); $(this).addClass('light_gray'); }  	});

	$('#CallMeSubmit').click(function(){
		var jDoValidate = false;
		if ($('#CallMeNaam').val()==jInput_CallMenu_name)			 { $('#CallMeNaam').val(""); jDoValidate=true; }
		if ($('#CallMeTelefoonnummer').val()==jInput_CallMenu_phone) { $('#CallMeTelefoonnummer').val(""); jDoValidate=true; }
		if (($('#CallMeBedrijfsnaam').val()==jInput_CallMenu_company) && (jDoValidate==false)) { $('#CallMeBedrijfsnaam').val(""); }
		if (jDoValidate) { $('#callme_form_id').valid(); } else { $('#callme_form_id').submit(); }
	});

	$("#callme_form_id").validate({
		errorClass: "form_error",

		rules: {
			Naam: { required: true },
			Telefoonnummer: { required: true }
		},

		submitHandler: function(form){
			$('#sendingformallowed').attr('value', '556d699968986a989a9869986e989a986c709d98989898989b996c986a9869');
			$('#callme_form_id').attr('action', '/forms/form-10597.asp');
			form.submit();
		}
	});


	// home boxes
	// --------------------------------------------------------------------
	$('.HomeBoxMargin').each(function(index) {
			$(this).click(function(){ 
				var jURL = $('A',this).attr("href");
				if (jURL != undefined) { self.location.href=jURL; 	}
			});
	});


	// form fields
	// --------------------------------------------------------------------
	$('.form_text').focus( function(){ $(this).addClass('form_focus'); });
	$('.form_text').focusout( function(){  $(this).removeClass('form_focus'); });
	$('.form_textarea').focus( function(){  $(this).addClass('form_focus'); });
	$('.form_textarea').focusout( function(){  $(this).removeClass('form_focus'); });
	$('.form_select').mousedown( function(){  $(this).addClass('form_focus'); });
	$('.form_select').focusout( function(){  $(this).removeClass('form_focus'); });

	$('.form_main_button').hover( function(){  $(this).addClass('form_main_button_hover'); },
								  function(){  $(this).removeClass('form_main_button_hover'); });

	// justify
	// --------------------------------------------------------------------
	$("#WordBar_cnt a").characterJustify();
	$("#FootBar_cnt div").characterJustify();


	// Tweets
	// --------------------------------------------------------------------
	  $("#Twitter_cnt ").tweet({
        join_text: null,
        username: "imach_peter",
        avatar_size: null,
        count: 5,
		outro_text: '<script language="JavaScript"> startTweetCarousel();</script>', 
        loading_text: '<img src="/images/ajax-loader.gif" width="16" height="11" border="0" align="absMiddle" alt=""> bezig met laden...',
		template: function(info) { return info["text"] + info["time"]; }
      });

 });



/* start Tweet caroussel*/
function startTweetCarousel() {
	$("#Twitter_cnt").jCarouselLite({
			auto: 1500,
			speed: 1500,
			visible: 1,
			vertical: true
		});
}



