var uitgelicht_interval = 20000;

(function($) {
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			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; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
})(jQuery);

$(document).ready(function() {

function load_uitgelicht(){
	$.getJSON("/get-uitgelicht/",
        function(data){
	      //console.log(data);
		  groep_naam =data.groep_naam
		  groep_omschrijving = data.groep_omschrijving;
		  org_link = data.org_link;
		  org_naam = data.org_naam;
		  org_image = data.org_image;
		  $("#uitgelicht").fadeOut(800);
		  $('#slider').fadeOut(1300, function(){
		  	$("#focus h1").html(groep_naam);
			$("#focus-omschrijving").html(groep_omschrijving);
			$("#uitgelicht span").html(org_naam);
			$("#uitgelicht a").attr("href", org_link);
			$("#uitgelicht-img").css("background-image","url("+org_image+")");
			$("#uitgelicht").fadeIn(800);
			$('#slider').fadeIn(1300);
		  });
		  
		  //console.log(data);
          
		  setTimeout(function(){
		  	load_uitgelicht();
		  }, uitgelicht_interval);
        });
}

function show_login() {
	$("#login-form").fadeIn('fast');
}

function hide_login() { 
	$("#login-form").fadeOut('slow');
}

if ($('#uitgelicht').length>0){
	setTimeout(function(){
		load_uitgelicht();
	}, uitgelicht_interval);
}
 
$("#login-holder").hoverIntent({
	sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
	interval: 50,   // number = milliseconds for onMouseOver polling interval
	over: show_login,     // function = onMouseOver callback (required)
	timeout: 500,   // number = milliseconds delay before onMouseOut
	out: hide_login       // function = onMouseOut callback (required)
});

$('#filter-form select option:first-child').css('color', '#cccccc');

});
/*
$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
}; 


$(document).ready(function(){
    $("#menu li").hover(
        function(){ $("ul", this).fadeIn("slow"); }, 
        function() { } 
    );
    if (document.all) {
        $("#menu li").hoverClass ("sfHover");
    }
});


//end sfjquery
var menu_timeout    = 1000;
var menu_closetimer = 0;
var menu_item = 0;
var menu_parent = 0;

function menu_open(){  
 
    * 
   menu_canceltimer();
   menu_close();
   console.log($(this));
   console.log($(this).parent().attr('id')=="menu");
   console.log($(this).parent().attr('id'));
   menu_parent = $(this);
   
   $(this).find('a').css('color', '#676767');
   if ($(this).find('ul').css('display') != 'block') {
   	menu_item = $(this).find('ul').fadeIn('fast', new function(){
   		console.log('done fade in');
   	});
   }
   
   if ($(this).parent().attr('id') == 'menu') {
   	$(this).addClass('hovering');
   	if ($(this).find('ul').css('display') != 'block') {
   		menu_item = $(this).find('ul');
   		menu_item.fadeIn('fast', new function(){
   			console.log('done fade in');
   		});
   	}
   }
}

function menu_close(){  
	
	if (menu_parent){
		menu_parent.removeClass('hovering');
	}
	if(menu_item){
		menu_item.fadeOut('slow');
		menu_item.parent().removeClass('hovering');
		$('#menu').find('a').css('color', '#ffffff');
		//console.log('hiding');
	} 
	
	if ($(this).hasClass('hovering')){
		console.log($(this));
		$(this).find('ul').fadeOut('slow');
	} 
}

function menu_timer(){  
	menu_closetimer = window.setTimeout(menu_close, menu_timeout);
}

function menu_canceltimer(){  
	if(menu_closetimer){  
		window.clearTimeout(menu_closetimer);
      	menu_closetimer = null;
	}
}
	  
$(document).ready(function() {
	$('#menu li').bind('mouseover', menu_open);
	$('#menu li').bind('mouseout',  menu_timer);
});
 
document.onclick = menu_close;*/