function fbInit(){

    $("a.fbYoutube").click(function() { 
           $.fancybox({ 
               'width'               : 400, 
               'height'              : 300,   
               'margin'              : 0,         
               'padding'             : 0, 
               'autoScale'           : false, 
               'transitionIn'        : 'none', 
               'transitionOut'       : 'none', 
			   'overlayShow'         : true,
			   'overlayOpacity'      : 0.7,               
               'title'               : this.title, 
               'href'                : this.href.replace(new RegExp("youtu.be/", "i"), 'www.youtube.com/v/') + '&autoplay=1', 
               'type'                : 'swf',    
               'swf'                 : {'wmode':'transparent','allowfullscreen':'true'} // <-- flashvars here 
           }); 
           return false; 
     });  
 
     $(".fbIframe").fancybox({
               'width'               : 500, 
               'height'              : 500,      
			   'margin'              : 0,
			   'padding'             : 0,   
			   'transitionIn'		 : 'none',
			   'transitionOut'		 : 'none',
			   'centerOnScroll'      : true,
			   'titleShow'           : false,
			   'autoScale'           : false, 				
			   'overlayShow'         : true,
			   'overlayOpacity'      : 0.7,
			   'modal'               : true,
			   'type'                : 'iframe',			   
			   'onComplete'		     : function() {                
                                      //   setTimeout('fbResize()',1000);
                                       } 
	 });
	 
     $(".fbExternal").fancybox({
               'width'               : 400, 
               'height'              : 300, 						   
			   'margin'              : 5,
			   'padding'             : 5,     
    		   'titlePosition'	     : 'inside',
			   'transitionIn'		 : 'none',
			   'transitionOut'		 : 'none',
			   'autoScale'           : false, 
			   'overlayShow'         : false,
			   'overlayOpacity'      : 0.7,				   
			   'onComplete'		     : function() {
	                                   //  setTimeout('fbResize()',2000);
	                                   }
    });
     			
    $(".fbInline").fancybox({
               'width'               : 10, 
               'height'              : 10,	 
			   'margin'              : 5,
			   'padding'             : 5,                    
    		   'titlePosition'		 : 'inside',
			   'transitionIn'		 : 'none',
			   'transitionOut'		 : 'none',
			   'autoScale'           : false, 			   
			   'overlayShow'         : true,
			   'overlayOpacity'      : 0.7,			   
			   'modal'               : true
	});
      
    $('.fbImage').click(function() { 
           $.fancybox({ 			
                'type'              : 'image',
				'overlayShow'       : true,
				'overlayOpacity'    : 0.7,
				'margin'            : 5,
				'padding'           : 5,
			    'transitionIn'	    : 'fade',
			    'transitionOut'		: 'fade',	
			    'showNavArrows'     : true,			
				'titleShow'         : true,
                'href'              : $(this).attr('src')   
           });                                       
    });          
}

function fbClose(){

  $.fancybox.close();
}
  
function fbResize(w,h){
	if (document.getElementById('fancybox-frame')){
		if (w == undefined){
			var w = document.getElementById('fancybox-frame').contentWindow.document.body.scrollWidth;
	    	var h = document.getElementById('fancybox-frame').contentWindow.document.body.scrollHeight + 17;
	    }	
   		$("#fancybox-content").css({'width': w+17+'px', 'height': h+'px'});
	    $("#fancybox-wrap").css({'width': w+17+'px', 'height': h+'px'});
 	}
  	else {
   		$.fancybox.resize();
  	} 
    $.fancybox.center(); 
}  

function fbYoutube(url, title){
   $.fancybox({ 
              'width'               : 400, 
              'height'              : 300,  
              'margin'              : 0,                     
              'padding'             : 0, 
              'autoScale'           : false, 
              'transitionIn'        : 'none', 
              'transitionOut'       : 'none', 
	          'overlayShow'         : true,
		      'overlayOpacity'      : 0.7,                
              'title'               : title, 
              'href'                : url.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1', 
              'type'                : 'swf',    
              'swf'                 : {'wmode':'transparent','allowfullscreen':'true'} // <-- flashvars here 
    }); 
} 
function fbIframe(url,showCloseButton){
  $.fancybox({			
				'overlayShow'       : true,
				'overlayOpacity'    : 0.7,
				'margin'            : 0,
				'padding'           : 0,
			    'transitionIn'	    : 'none',
			    'transitionOut'		: 'none',
			    'centerOnScroll'    : true,			    				
				'modal'             : showCloseButton != true,
			    'autoScale'         : false,				
                'width'             : 500, 
                'height'            : 500,
                'type'              : 'iframe', 
                'href'              : url,
			    'onComplete'	    : function() {
	                                  }                                     
  });
}
function fbBook(url){
  $.fancybox({			
				'overlayShow'       : true,
				'overlayOpacity'    : 0.7,
				'margin'            : 8,
				'padding'           : 8,
			    'transitionIn'	    : 'none',
			    'transitionOut'		: 'none',
			    'centerOnScroll'    : true,			    				
				'modal'             : true,
			    'autoScale'         : false,				
                'width'             : 10, 
                'height'            : 10,
                'type'              : 'iframe', 
                'href'              : url,
			    'onComplete'	    : function() {
	                      //              $('#fancybox-content').css({'border-bottom-width':'35px', 
	                       //             							'border-color':'transparent'});
	                                  }                                     
  });
}
function fbInline(href){
  $.fancybox({			
				'overlayShow'       : true,
				'overlayOpacity'    : 0.7,
				'margin'            : 5,
				'padding'           : 5,
			    'transitionIn'	    : 'none',
			    'transitionOut'		: 'none',				
				'titleShow'         : false,
                'href'              : href                                     
  });
}
  
function fbImage(href,title){
  $.fancybox({			
                'type'              : 'image',
				'overlayShow'       : true,
				'overlayOpacity'    : 0.7,
				'margin'            : 5,
				'padding'           : 5,
			    'transitionIn'	    : 'fade',
			    'transitionOut'		: 'fade',	
			    'showNavArrows'     : true,			
				'titleShow'         : true,
				'titlePosition'     : 'inside',
				'titleFormat'       : formatTitle,
				'title'             : title,
                'href'              : href                                          
  }); 
}

function fbGallery(iArray, index){
  $.fancybox(iArray,{			
                'index'             : index,
                'type'              : 'image',
				'overlayShow'       : true,
				'overlayOpacity'    : 0.7,
				'margin'            : 5,
				'padding'           : 5,
			    'transitionIn'	    : 'none',
			    'transitionOut'		: 'none',	
			    'showNavArrows'     : true,	
			    'showCloseButton'   : true,		
				'titleShow'         : true,
				'cyclic'            : true,
				'hideOnOverlayClick': false,
				'titlePosition'     : 'inside',
				'onClosed'          : fbSlideShowExit(),				
				'titleFormat'       : formatTitle                                       
  }); 
}
var fbSlideShowInterval = "";
var fbSlideShowMode = false

function fbSlideShowStart(){
  fbSlideShowMode = true;
  $.fancybox.next();
  fbSlideShowInterval=setInterval($.fancybox.next,3000);
}  
function fbSlideShowStop(currentIndex){
  clearInterval(fbSlideShowInterval);
  fbSlideShowMode = false;
  $.fancybox.pos(currentIndex);
} 
function fbSlideShowExit(){
  clearInterval(fbSlideShowInterval);
  fbSlideShowMode = false;
} 

function formatTitle(title, currentArray, currentIndex, currentOpts) {

   return '<div style="position:relative;text-align:left; padding-right:80px;min-height:40px">' +
           (title && title.length ? title  : '' ) + 
           '<div id="fbSlideShowButton" style="position:absolute;top:0px;right:0px">' +
           (fbSlideShowMode ? '<a href="javascript:;" onclick="fbSlideShowStop(' + currentIndex + ')"><img title="pause" src="/assets/fancybox/fancy_pause.png"></a>' : '<a href="javascript:;" onclick="fbSlideShowStart()"><img title="speel diashow" src="/assets/fancybox/fancy_play.png"></a>') +
           '<br>' +  
           (currentIndex + 1) + ' / ' + currentArray.length + 
           '</div></div>'
}    
var fbStack = new Array();
var fbStackPointer = -1;

function fbCall(URL,callbackURL){
  fbStackPointer += 1;
  fbStack[fbStackPointer] = callbackURL;
  document.getElementById('fancybox-frame').src = URL;
}
function fbReturn(){  
  if (fbStackPointer < 0){
    fbStackPointer = -1;
    fbClose();
    location.reload();
  }
  else {
    var fbCallbackURL = fbStack[fbStackPointer];
    fbStackPointer -= 1;
    document.getElementById('fancybox-frame').src = fbCallbackURL;  
  }  
}
function fbRedirect(URL){
  document.getElementById('fancybox-frame').src = URL;
}
