/* ******************************************************
     Datei fancybox_custom.jss grvd.de
     steuert die Fancybox
     created:    23.06.2011            
     created by: karl majert          
  ****************************************************** */
$(document).ready(function() {
  
  /* *** LoginFormular ******************************** */    
  $("#login").fancybox({       
     'scrolling'      : 'no',       
     'width'          : 300,       
     'height'         : 340,       
     'autoScale'      : true,       
     /*'transitionIn' : 'none',       
     'transitionOut'  : 'none',*/       
     'type'           : 'iframe',       
     'onStart': function(){           
        $('#fancybox-outer').addClass('grey');          
     },        
     'onClosed':function() {           
        $('#fancybox-outer').removeClass('grey');          
     }     
   });  
 
   // h5 Berichte
   function blockSlide() {
     $('#content div.part').hide();
     $('#content div.part:first').show();
     $('#content h5.opener').click(
       function() {
         var blockElement = $(this).next();
         if((blockElement.is('div.part')) && (blockElement.is(':visible'))) 
           {
           return false;
           }
         if((blockElement.is('div.part')) && (!blockElement.is(':visible'))) 
           {
           $('#content div.part:visible').slideUp('slow');
             blockElement.slideDown('slow');
             return false;
           }
         }
       );
     }
     blockSlide();
  
   /* *** Sharebox mit Infos ********************** */  
   $(".showShare").fancybox({
      'scrolling'      : 'no',
      'titleShow'      : false,
      'hideOnOverlayClick'  : true,
      'onStart': function(){ 
         $('#fancybox-outer').addClass('grey'); 
        }, 
      'onClosed':function() { 
         $('#fancybox-outer').removeClass('grey'); 
        }
   });
        

   /* *** Einzelbilder ********************** */  
   $("a.fancy").fancybox({      
      'titlePosition'    : 'inside',
      'titleFormat'      : function(title) {
         return '<p class="p_fancy">' + (title.length ? title : '') + '&nbsp;</p>';
         }
   });
   
   /* *** Bildergalerien ********************** */
   $("a.fancygal").fancybox({      
      'titlePosition'    : 'inside',
      'titleFormat'      : function(title, currentArray, currentIndex, currentOpts) {
         return '<p class="p_fancy"><span>Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' </span><br /> ' + title : '') + '</p>';
         }
   });
      
   $("a.fancyinline").fancybox({
      'titlePosition'   : 'none',
      /*'transitionIn'    : 'none',
      'transitionOut'   : 'none',*/
      'titleFormat'     : function(title) {
         return '<p class="p_fancy">' + (title.length ? title : '') + '</p>';
         }
   });


/* *** Bildwechsel in Galerien ******************************** */
   var points =  $('.galChange');
   var galimages = $('.galImages div');
   var galtexte = $('.galTexte div');

   $('.galImages div').addClass('hideImg');
   $('.galImages div:eq(0)').removeClass('hideImg');
   $('.galImages div:eq(0)').addClass('showImg');
   $('.galTexte div').addClass('hideImg');
   $('.galTexte div:eq(0)').removeClass('hideImg');
   $('.galTexte div:eq(0)').addClass('showImg');

   var showImage = function(event){
      // get index for current image
      var index = points.index($(this));
      $('.galImages div').removeClass('showImg');
      $('.galImages div').addClass('hideImg');
      $('.galImages div:eq('+index+')').addClass('showImg');
      $('.galTexte div').removeClass('showImg');
      $('.galTexte div').addClass('hideImg');
      $('.galTexte div:eq('+index+')').addClass('showImg');
      };

   var hideImage = function(event){
      var index = points.index($(this));
      $('.galImages div:eq('+index+')').addClass('hideImg');
      $('.galTexte div:eq('+index+')').addClass('hideImg');
      };

   points.hover(showImage,hideImage);    

   /*points.click(function(){
      galimages.removeClass("showImg");
      var index = points.index($(this));
      $('.galImg:eq('+index+')').addClass('showImg');
   });*/

/* *** Videodarstellung Flash ************************************** */
   $(".video").click(function() {
      $.fancybox({
         'padding'       : 10,
         'autoScale'     : false,
         'transitionIn'  : 'none',
         'transitionOut' : 'none',
         'titleShow'     : 'true',
         'titlePosition' : 'inside',
         'title'         : this.title,
         'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
         'type'          : 'swf',
         'swf'           : {
            'wmode'           : 'opaque',
            'allowfullscreen' : 'true'
         }
      });
      return false;
   });
  
/* *** Videodarstellung Vimeo ************************************** */  
   $("a.vimeo").click(function() {
     $.fancybox({
        'padding'         : 10,
        'autoScale'       : false,
        'transitionIn'    : 'none',
        'transitionOut'   : 'none',
        'titleShow'       : 'true',
        'titlePosition'   : 'inside',
        'title'           : this.title,
        /*'width'           : 800,
        'height'          : 450,*/
        'href'            : this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),  
        'type'            : 'swf',
        'swf'             : {
           'wmode'           : 'opaque',
           'allowfullscreen' : 'true'
        }
     });
     return false;
   });
  
});
