$(document).ready(function(){
    $('.showImageDescription').addImageDescription();
    $('.zoomable').zoomable();
});
jQuery(function($){
    if ($.datepicker){
        $.datepicker.regional['de'] = {clearText: 'löschen', clearStatus: 'aktuelles Datum löschen',
                closeText: 'schließen', closeStatus: 'ohne Änderungen schließen',
                prevText: '&#x3c;zurück', prevStatus: 'letzten Monat zeigen',
                nextText: 'Vor&#x3e;', nextStatus: 'nächsten Monat zeigen',
                currentText: 'heute', currentStatus: '',
                monthNames: ['Januar','Februar','März','April','Mai','Juni',
                'Juli','August','September','Oktober','November','Dezember'],
                monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
                'Jul','Aug','Sep','Okt','Nov','Dez'],
                monthStatus: 'anderen Monat anzeigen', yearStatus: 'anderes Jahr anzeigen',
                weekHeader: 'Wo', weekStatus: 'Woche des Monats',
                dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
                dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
                dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
                dayStatus: 'Setze DD als ersten Wochentag', dateStatus: 'Wähle D, M d',
                dateFormat: 'dd.mm.yy', firstDay: 1,
                initStatus: 'Wähle ein Datum', isRTL: false};
        $.datepicker.setDefaults($.datepicker.regional['de']);
}
});

var $buoop = {}
$buoop.ol = window.onload;
window.onload=function(){
     if ($buoop.ol) $buoop.ol();
     var e = document.createElement("script");
     e.setAttribute("type", "text/javascript");
     e.setAttribute("src", "http://browser-update.org/update.js");
     document.body.appendChild(e);
}


;(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

;(function($) {
  $.fn.sliderBu = function(timeShow, timeSlide) {
        $(this).find('img').hide();
        $(this).find('img:first').show();
        count = $(this).find('img').length;
        var i = 0;
        var slider = $(this);
        window.setInterval(
        function(){
            if (i+1 == count){
                next = 0;
            }else{
                next = i+1;
            }
            slider.find('img:eq('+i+')').fadeOut(timeSlide*1000);
            slider.find('img:eq('+next+')').fadeIn(timeSlide*1000);
            i= next;
        }, (timeShow+timeSlide)*1000 );
    }
})(jQuery);



$(document).ready(function(){
$('.slider').sliderBu(5,2);
//$('html').mask('test');
});

// mask && unmask

(function($) {
  $.fn.mask2 = function(html, opacity ) {
      if (!opacity){
          opacity = '.3';
      }
      
    obj = $('body');
       obj.append('<div class=\"mask\"></div><div class=\"maskMessage\"></div>');
        mask = $('div.mask');
        message = $('div.maskMessage');
        message.css('z-index', '999');
        message.css('background-color', '#FFF');
        message.css('color', '#000');

        mask.height($('html').outerHeight(true));
        mask.width($('html').outerWidth(true));
        mask.css('z-index', '998');
        mask.css('position', 'fixed');
        mask.css('opacity', opacity);
        mask.css('background-color', '#000');
        message.css('top','50%');
       message.css('left','50%');
        message.css('display','block');
        message.css('padding','5px');
        message.css('moz-border-radius','5px');
       message.css('position', 'fixed');
       message.hide();
       
    mask.show();
   
        mask.css('left', 0);
        mask.css('top', 0);
    
    message.html(html);
            
        message.css('margin-left','-'+(message.width()/2)+'px');
        message.css('margin-top','-'+(message.height()/2)+'px');
        if (message.find('img').length > 0){
    message.find('img').load(function(){
        message.css('margin-left','-'+(message.width()/2)+'px');
        message.css('margin-top','-'+(message.height()/2)+'px');
        
     message.show();
         
    });
        }else{
            message.show();
        }
 }
  $.fn.unMask = function() {
      $('div.mask, div.maskMessage').remove();
    };
})(jQuery);
(function($) {
  $.fn.Tree = function(options) {
      th = $(this);
      if (!th.hasClass('isTree')){
          th.addClass('isTree');
            th.find('li').addClass('nodeOpen');
            th.find('li').each(function(){
                if ($(this).find('ul').length>0){
                    $(this).prepend('<span class=\"closer Node"></span>')
                }else{
                    $(this).prepend('<span class=\"emptyNode Node"></span>')
                }
            })
            closer(th.find('li'));

            if ( options['startClosed']){
                th.find('.closer').click();
        }
        }
        function closer(container){
            container.children('.closer').click(function(){
                var t = $(this);
                t.parents('li:first').removeClass('nodeOpen Node').addClass('nodeClosed');
                
              t.parents('li:first').prepend('<span class=\"opener"></span>');
                
                opener(t.parents('li'));
                t.remove();
            });
        }
        function opener(container){
            container.children('.opener').click(function(){
                var t = $(this);
                t.parents('li:first').removeClass('nodeClosed').addClass('nodeOpen');
                t.parents('li:first').prepend('<span class=\"closer"></span>');
                
                closer(t.parents('li'));
                t.remove();
            });
        }
    }
})(jQuery);
(function($) {
  $.fn.addImageDescription = function(options) {
      $(this).each(function(){
      img = $(this);
      if (!img.parent().hasClass('imageContainer')){
          var classes = "imageContainer";
          if (img.hasClass('imageLeft')){
              classes += " imageLeft";
              img.removeClass('imageLeft');
          }
          if (img.hasClass('imageNoTextFloat')){
              classes += " imageNoTextFloat";
              img.removeClass('imageNoTextFloat');
          }
          if (img.hasClass('imageRight')){
              classes += " imageRight";
              img.removeClass('imageRight');
          }
          img.replaceWith("<div class=\""+classes+"\">"+img.outerHtml()+"<div class=\"imageDescription\">"+img.attr("alt")+"</div></div>");
          
      }
      });
  }
  $.fn.delImageDescription = function(options) {
      $(this).each(function(){
      img = $(this);
      if (img.parent().hasClass('imageContainer')){
          if (img.parent().hasClass('imageLeft')){
              img.addClass('imageLeft').parent().removeClass('imageLeft');
          }
          if (img.parent().hasClass('imageNoTextFloat')){
              img.addClass('imageNoTextFloat').parent().removeClass('imageNoTextFloat');
          }
          if (img.parent().hasClass('imageRight').parent().removeClass('imageRight')){
              img.addClass('imageRight');
          }
          img.parent().replaceWith(img.outerHtml());
      }
      });
  }
})(jQuery);
 var zoomwindowobj = "";
      $(window).resize(function(){
       if(zoomwindowobj != ""){
          var src = zoomwindowobj.attr('src').substring(zoomwindowobj.attr('src').lastIndexOf('/')+1);
          $.get(
      '?modul=system&rand='+Math.random()+'&controller=imagemanager&action=getzoomimage&src='+src+'&maxwidth='+($('html').width()-100)+'&maxheight='+($('html').height()-100), function(data){
         
    $().unMask();

      var window = ""+
          "<img src=\""+data+"\" class=\"imageNoTextFloat\" alt=\""+zoomwindowobj.attr('alt')+"\"/>"+
          "<div>"+zoomwindowobj.attr('alt')+ "</div>";
      $().mask2(window, '0.8');
        $('.maskMessage').closeButton({click: function (){zoomwindowobj.zoomWindowClose();}});

            $('.mask').click(function(){
                zoomwindowobj.zoomWindowClose();
            });
      });
      }});
(function($) {
  $.fn.zoomable = function(options) {
    $(this).css('cursor', 'pointer');
    $(this).click(function(){
        $(this).zoomWindow();
    });
  }
  $.fn.zoomWindow = function(options) {
      
      zoomwindowobj = $(this);
     
      $(window).resize();
    }
  $.fn.zoomWindowClose = function(options) {
      zoomwindowobj = "";
      $().unMask();
    }
    
    $.fn.closeButton = function(options) {

        var obj = $(this);
        obj.append('<div class=\"wkCloseButton\"></div>');
        
        $('.wkCloseButton').css('left', ( obj.width()+ 10) + 'px' );
        $('.wkCloseButton').css('bottom', ''+( obj.height()+ 10) + 'px' );
        $('.wkCloseButton').css('cursor', 'pointer' );
        $('.wkCloseButton').click(options['click']);
        obj.children('img').load(function(){
            $('.wkCloseButton').css('left', ( obj.width()+ 10) + 'px' );
            $('.wkCloseButton').css('bottom', ''+( obj.height()+ 10) + 'px' );
        });
    }
  
  
})(jQuery);

jQuery.fn.extend( {

  outerHtml: function( replacement )
  {
    // We just want to replace the entire node and contents with
    // some new html value
    if (replacement)
    {
      return this.each(function (){$(this).replaceWith(replacement);});
    }

    /*
     * Now, clone the node, we want a duplicate so we don't remove
     * the contents from the DOM. Then append the cloned node to
     * an anonymous div.
     * Once you have the anonymous div, you can get the innerHtml,
     * which includes the original tag.
     */
    var tmp_node = $("<div></div>").append( $(this).clone() );
    var markup = tmp_node.html();

    // Don't forget to clean up or we will leak memory.
    tmp_node.remove();
    return markup;
  }
});
