$(document).ready(function() {

	$("a.openfoto").fancybox({
		'padding'			:	1,
		'transitionIn'		:	'elastic',
		'transitionOut'		:	'elastic',
		'speedIn'			:	300,
		'speedOut'			:	300,
		'titleShow'			:	false,
		'overlayOpacity'	:	0.0,
		'hideOnContentClick':	true,
		'overlayShow'		:	true
	});

	$("a.openfotometitel").fancybox({
		'padding'			:	1,
		'transitionIn'		:	'elastic',
		'transitionOut'		:	'elastic',
		'speedIn'			:	300,
		'speedOut'			:	300,
		'titleShow'			:	true,
		'overlayOpacity'	:	0.0,
		'hideOnContentClick':	true,
		'overlayShow'		:	true
	});

	$("a.tellFriend").fancybox({
		'padding'			:	1,
		'transitionIn'		:	'elastic',
		'transitionOut'		:	'elastic',
		'speedIn'			:	300,
		'speedOut'			:	300,
		'titleShow'			:	false,
		'overlayOpacity'	:	0.8,
		'hideOnContentClick':	false,
		'width' 			:	300,
		'overlayShow'		:	true
	});

	// initialise plugins
	$('ul.sf-menu').superfish({
       delay:       350,                            // one second delay on mouseout
       animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation
       speed:       0,                          // faster animation speed
       autoArrows:  false,                           // disable generation of arrow mark-up
       dropShadows: false                            // disable drop shadows
    });


	$('.iframe-delta-0').attr({
	  allowtransparency: 'true'
	});

		// Rollover functie
   $(".item_tr").hover(
      function () {
        $(this).addClass("rollover");
      },
      function () {
        $(this).removeClass("rollover");
      }
    );


   //Handleidingen netjes open en dicht schuiven
	$(".msg_head").click(function()
    {
		$(this).next("div.msg_body").slideToggle(300).siblings("div.msg_body").slideUp("slow");
    });

	// popup items
	$("a.leerMeer").click(function() {
		var welkeGroep = $(this).attr("groep_ID");
		var welkeID = $(this).attr("item_ID");
		var vraagGroep 	= $(this).attr("vraagGroep");
		
		// console.log("ajax_item_popup.php | welkeGroep: "+welkeGroep+" -- "+"welkeID: "+welkeID+" -- "+"vraagGroep: "+vraagGroep);

		popup();
		
		$('#binnenContent').load('inc/ajax_item_popup.php?welkeGroep='+welkeGroep+'&welkeID='+welkeID+'&vraagGroep='+vraagGroep, function() {
			$('#loadingContent').fadeOut('medium', function() {
			     $('#binnenContent').fadeIn('medium', function() {

				 });
			 });
		});
    });
   
   	// popup projecten
	$("a.leerMeerProjecten").click(function() {
		var welkeGroep 	= $(this).attr("groep_ID");
		var welkeID 	= $(this).attr("item_ID");
		var vraagGroep 	= $(this).attr("vraagGroep");
		
		// console.log("ajax_project_popup.php | welkeGroep: "+welkeGroep+" -- "+"welkeID: "+welkeID+" -- "+"vraagGroep: "+vraagGroep);

		popup();
		
		$('#binnenContent').load('inc/ajax_project_popup.php?welkeGroep='+welkeGroep+'&welkeID='+welkeID+'&vraagGroep='+vraagGroep, function() {
			$('#loadingContent').fadeOut('medium', function() {
			     $('#binnenContent').fadeIn('medium', function() {

				 });
			 });
		});
    });

    // Mogelijkheden om de popup weer te verbergen
	$('a.terugOverzicht').click(function () {
		$('#dialog-overlay, #dialog-box').hide();

		// reset content bij sluiten
		$('#loadingContent').show();
		$('#binnenContent').hide();

		return false;
	});

	// Popup in het midden laten
	$(window).resize(function () {
		//only do it if the dialog box is not hidden
		if (!$('#dialog-box').is(':hidden')) popup();
	});


});









//Popup scherm
function popup() {
	// get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	// midden voor de popup uitrekenen
	var dialogTop =  (maskHeight/2) - ($('#dialog-box').height()/2);
	var dialogTop = 220;
	var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2);

	// assign values to the overlay and dialog box
	$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
	$('#dialog-box').css({top:dialogTop, left:dialogLeft}).show();
	
	$('body').scrollTo( 0, 400 );
}



// Youtube afbeelding binnen halen
function getScreen( url, size )
{
  if(url === null){ return ""; }

  size = (size === null) ? "big" : size;
  var vid;
  var results;

  results = url.match("[\\?&]v=([^&#]*)");

  vid = ( results === null ) ? url : results[1];

  if(size == "small"){
    return "http://img.youtube.com/vi/"+vid+"/2.jpg";
  }else {
    return "http://img.youtube.com/vi/"+vid+"/0.jpg";
  }


}

