(function($){
  $.fn.gallery = function(options) {
     var defaults = {
         wrapID: '#center_center',
     };
     
    //Erweitern und zusammenf?hren der ?bergebenen Werten mit den standard Werten
    return this.each(function(){
      if (options) {
        $.extend(defaults,options);
      }
      
      var tmp = '<div class="imgapp_pos"><div><img src="'+defaults.zoomImg+'" /><div>';
      tmp += '<div class="imgapp_footer"><div class="imgapp_close"><span>'+defaults.closeText+'<img src="fileadmin/template/imgapp/images/trol_imgapp_close.png" /></span></div></div></div>';
      
      if(document.getElementById('center_center').offsetHeight   < 650) {
        console.log(document.getElementById('center_center').offsetHeight);
        $('#center_center').css({'height' : '650px'});
      }
      
      if($('.imgapp_pos').length > 0) {
        $('.imgapp_pos').fadeOut('1000', function () {
          $('.imgapp_pos').remove();
          $(defaults.wrapID).append(tmp);
          $('.imgapp_pos').css ({
              'display' : 'none',
              'position' : 'absolute',
              'overflow' : 'hidden',
              'top' : '350px',
              'left' : '205px',
              'width' : '490px',
              'height' : 'auto',
              'background-position' : 'left center',
              
          });
          $('.imgapp_footer').css({
              'display' : 'inline',
              'position' : 'relative',
              'float' : 'left',
              'overflow' : 'hidden',
              'width' : '490px',
              'height' : '32px',
              'margin-top' : '3px',
              'background-image' : 'url(fileadmin/template/imgapp/images/trol_imgapp_bg.png)',
              'background-repeat' : 'no-repeat',
              'background-position' : 'left center',
          });    
          
          $('.imgapp_close').css({
              'cursor' : 'pointer',
              'display' : 'inline',
              'float' : 'right',
              'height' : '32px',
              'margin' : '0 15px 0 0',
              'position' : 'relative',
              'width' : '100px',
          });
          
          $('.imgapp_close span').css({
              'display' : 'inline',
              'float' : 'right',
              'font-family' : 'tahoma',
              'font-size' : '12px',
              'color' : '#fff',
              'text-decoration' : 'none',
              'line-height' : '32px',
              'margin' : '0px 0px 0px 0px',
              'color' : 'rgb(0,85,129)',
              'cursor' : 'pointer',
          });
          
          $('.imgapp_close img').css({  
              'display' : 'inline',
              'float' : 'right',
              'height' : '12px',
              'margin' : '10px 0px 0px 7px',
              'cursor' : 'pointer',
          });
          
          $('.imgapp_close span:hover').css({
              'color' : 'rgb(0,85,129)',
          });
          $('.imgapp_pos').fadeIn('slow');
          
          $('.imgapp_close span').click(function(){
            $('.imgapp_pos').fadeOut('1000', function () {
              $('.imgapp_pos').remove();
            });
          });
        });
      }else {
        $(defaults.wrapID).append(tmp);

        $('.imgapp_pos').css ({
            'display' : 'none',
            'position' : 'absolute',
            'overflow' : 'hidden',
            'top' : '350px',
            'left' : '205px',
            'width' : '490px',
            'height' : 'auto',
            'background-position' : 'left center',
            
        });        
        
        $('.imgapp_pos').fadeIn('slow');
      
        /*$(this).css({
            'display' : 'inline',
            'float' : 'left',
            'cursor' : 'pointer',
          
        });*/
        
        $('.imgapp_close span').click(function(){
          $('.imgapp_pos').fadeOut('1000', function () {
            $('.imgapp_pos').remove();
          });
        });
        
        
        $('.imgapp_footer').css({
            'display' : 'inline',
            'position' : 'relative',
            'float' : 'left',
            'overflow' : 'hidden',
            'width' : '490px',
            'height' : '32px',
            'margin-top' : '3px',
            'background-image' : 'url(fileadmin/template/imgapp/images/trol_imgapp_bg.png)',
            'background-repeat' : 'no-repeat',
            'background-position' : 'left center',
        });
        
        
        $('.imgapp_close').css({
            'cursor' : 'pointer',
            'display' : 'inline',
            'float' : 'right',
            'height' : '32px',
            'margin' : '0 15px 0 0',
            'position' : 'relative',
            'width' : '100px',
        });
        
        $('.imgapp_close span').css({
            'display' : 'inline',
            'float' : 'right',
            'font-family' : 'tahoma',
            'font-size' : '12px',
            'color' : '#fff',
            'text-decoration' : 'none',
            'line-height' : '32px',
            'margin' : '0px 0px 0px 0px',
            'color' : 'rgb(0,85,129)',
            'cursor' : 'pointer',
        });
        
        $('.imgapp_close img').css({  
            'display' : 'inline',
            'float' : 'right',
            'height' : '12px',
            'margin' : '10px 0px 0px 7px',
            'cursor' : 'pointer',
        });
        
        $('.imgapp_close span:hover').css({
            'color' : 'rgb(0,85,129)',
        });
      }
    });
  };
})(jQuery);
