jQuery.fn.extend({everyTime:function(b,c,d,e,a){return this.each(function(){jQuery.timer.add(this,b,c,d,e,a)})},oneTime:function(a,b,c){return this.each(function(){jQuery.timer.add(this,a,b,c,1)})},stopTime:function(a,b){return this.each(function(){jQuery.timer.remove(this,a,b)})}});jQuery.extend({timer:{global:[],guid:1,dataKey:"jQuery.timer",regex:/^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,powers:{ms:1,cs:10,ds:100,s:1000,das:10000,hs:100000,ks:1000000},timeParse:function(c){if(c==undefined||c==null){return null}var b=this.regex.exec(jQuery.trim(c.toString()));if(b[2]){var a=parseFloat(b[1]);var d=this.powers[b[2]]||1;return a*d}else{return c}},add:function(d,c,h,g,b,f){var a=0;if(jQuery.isFunction(h)){if(!b){b=g}g=h;h=c}c=jQuery.timer.timeParse(c);if(typeof c!="number"||isNaN(c)||c<=0){return}if(b&&b.constructor!=Number){f=!!b;b=0}b=b||0;f=f||false;var e=jQuery.data(d,this.dataKey)||jQuery.data(d,this.dataKey,{});if(!e[h]){e[h]={}}g.timerID=g.timerID||this.guid++;var i=function(){if(f&&this.inProgress){return}this.inProgress=true;if((++a>b&&b!==0)||g.call(d,a)===false){jQuery.timer.remove(d,h,g)}this.inProgress=false};i.timerID=g.timerID;if(!e[h][g.timerID]){e[h][g.timerID]=window.setInterval(i,c)}this.global.push(d)},remove:function(d,c,e){var a=jQuery.data(d,this.dataKey),b;if(a){if(!c){for(c in a){this.remove(d,c,e)}}else{if(a[c]){if(e){if(e.timerID){window.clearInterval(a[c][e.timerID]);delete a[c][e.timerID]}}else{for(var e in a[c]){window.clearInterval(a[c][e]);delete a[c][e]}}for(b in a[c]){break}if(!b){b=null;delete a[c]}}}for(b in a){break}if(!b){jQuery.removeData(d,this.dataKey)}}}}});jQuery(window).bind("unload",function(){jQuery.each(jQuery.timer.global,function(a,b){jQuery.timer.remove(b)})});
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:150,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);


function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

$(function() {
	
	// menu
	$('#menu-hoofdmenu > li:nth-child(1)').addClass("menu-business-solutions");
	$('#menu-hoofdmenu > li:nth-child(2)').addClass("menu-producten");
	$('#menu-hoofdmenu > li:nth-child(3)').addClass("menu-over-redant");
	
	$('#menu-hoofdmenu > li').hoverIntent(function() {
		$(this).addClass("hover");
		$(this).find("ul").slideDown('100');
	}, function() {
		$(this).find("ul").slideUp('100', function() { });
		$(this).removeClass("hover"); 
	});
		
	// screenshots slider
	$('#slider').slider();		
	$("#slider li a[rel=slider]").fancybox({
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Screenshot ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	// columns
	$('.entry-content, #content.product').columnize({columns: 2, lastNeverTallest: true});
	$('.itemlist').addClass('dontsplit');
	$('.entry-content ul').addClass('dontsplit');
	
	// search field
	var searchfieldvalue = $('#searchbar .field').attr('value');
	$('#searchbar .field').focusin(function() { $(this).attr('value',''); });
	$('#searchbar .field').focusout(function() { $(this).attr('value', searchfieldvalue); });
	$('#searchbar').focusin(function() { $('#searchbar').addClass("active"); });
	$('#searchbar').focusout(function() {$('#searchbar').removeClass("active");});
	
	// fader on or off
	$('#picture').append('<div id="fader"><div class="layer1"></div><div class="layer2"></div></div>');
	
	if(screen.height >= 480 && screen.width >= 320 && getInternetExplorerVersion() > 7) {
		$('#fader .layer2').hide();
		// deze geeft fouten? @todo een keer fixen
		//$('#fader').fader(); 

	}
	
	// other
	$('input[type="submit"]').addClass("button"); 
	$('.menulist li:last-child').addClass("last-child");
});

