/*!
 jquery scroll - a custom stylable scrollbar
 Version 0.4
 https://github.com/thomd/jquery-scroll
 Copyright (c) 2011 Thomas Duerr (me-at-thomd-dot-net)
 Licensed under the MIT license (https://raw.github.com/thomd/jquery-scroll/master/MIT-LICENSE)
 */(function($, document) {
  var methods = {
    init : function(fn, opts) {
      var options = $.extend({}, $.fn.scrollbar.defaults, opts);
      return this.each(function() {
        var container = $(this), props = {
          arrows : options.arrows
        };
        options.containerHeight != "auto" && container.height(options.containerHeight), props.containerHeight = container.height(), props.contentHeight = $.fn.scrollbar.contentHeight(container);
        if(props.contentHeight <= props.containerHeight)
          return !0;
        this.scrollbar = new $.fn.scrollbar.Scrollbar(container, props, options), this.scrollbar.buildHtml().setHandle().appendEvents(), typeof fn == "function" && fn(container.find(".scrollbar-pane"), this.scrollbar)
      })
    },
    repaint : function() {
      return this.each(function() {
        this.scrollbar.repaint()
      })
    },
    scrollto : function(to) {
      return this.each(function() {
        this.scrollbar.scrollto(to)
      })
    }
  };
  $.fn.scrollbar = function(method) {
    if(methods[method])
      return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    if( typeof method == "function" || method === undefined)
      return methods.init.apply(this, arguments);
    if( typeof method == "object")
      return methods.init.apply(this, [null, method]);
    $.error("method '" + method + "' does not exist for $.fn.scrollbar")
  }, $.fn.scrollbar.defaults = {
    containerHeight : "auto",
    arrows : !0,
    handleHeight : "auto",
    handleMinHeight : 30,
    scrollTimeout : 50,
    scrollStep : 20,
    scrollTimeoutArrows : 40,
    scrollStepArrows : 3
  }, $.fn.scrollbar.Scrollbar = function(container, props, options) {this.container = container, this.props = props, this.opts = options, this.mouse = {}, this.props.arrows = this.container.hasClass("no-arrows") ? !1 : this.props.arrows
  }, $.fn.scrollbar.Scrollbar.prototype = {
    buildHtml : function() {this.container.wrapInner('<div class="scrollbar-pane"/>'), this.container.append('<div class="scrollbar-handle-container"><div class="scrollbar-handle"/></div>'), this.props.arrows && this.container.append('<div class="scrollbar-handle-up"/>').append('<div class="scrollbar-handle-down"/>');
      var height = this.container.height();
      return this.pane = this.container.find(".scrollbar-pane"), this.handle = this.container.find(".scrollbar-handle"), this.handleContainer = this.container.find(".scrollbar-handle-container"), this.handleArrows = this.container.find(".scrollbar-handle-up, .scrollbar-handle-down"), this.handleArrowUp = this.container.find(".scrollbar-handle-up"), this.handleArrowDown = this.container.find(".scrollbar-handle-down"), this.pane.defaultCss({
        top : 0,
        left : 0
      }), this.handleContainer.defaultCss({
        right : 0
      }), this.handle.defaultCss({
        top : 0,
        right : 0
      }), this.handleArrows.defaultCss({
        right : 0
      }), this.handleArrowUp.defaultCss({
        top : 0
      }), this.handleArrowDown.defaultCss({
        bottom : 0
      }), this.container.css({
        position : this.container.css("position") === "absolute" ? "absolute" : "relative",
        overflow : "hidden",
        height : height
      }), this.pane.css({
        position : "absolute",
        overflow : "visible",
        height : "auto"
      }), this.handleContainer.css({
        position : "absolute",
        top : this.handleArrowUp.outerHeight(!0),
        height : this.props.containerHeight - this.handleArrowUp.outerHeight(!0) - this.handleArrowDown.outerHeight(!0) + "px"
      }), this.handle.css({
        position : "absolute",
        cursor : "pointer"
      }), this.handleArrows.css({
        position : "absolute",
        cursor : "pointer"
      }), this.pane.top = 0, this
    },
    setHandle : function() {
      return this.props.handleContainerHeight = this.handleContainer.height(), this.props.contentHeight = this.pane.height(), this.props.handleHeight = this.opts.handleHeight == "auto" ? Math.max(Math.ceil(this.props.containerHeight * this.props.handleContainerHeight / this.props.contentHeight), this.opts.handleMinHeight) : this.opts.handleHeight, this.handle.height(this.props.handleHeight), this.handle.height(2 * this.handle.height() - this.handle.outerHeight(!0)), this.props.handlePosition = {
        min : 0,
        max : this.props.handleContainerHeight - this.props.handleHeight
      }, this.props.handleContentRatio = (this.props.contentHeight - this.props.containerHeight) / (this.props.handleContainerHeight - this.props.handleHeight), this.handle.top == undefined ? this.handle.top = 0 : this.handle.top = -1 * this.pane.top / this.props.handleContentRatio, this
    },
    appendEvents : function() {
      return this.handle.bind("mousedown.handle", $.proxy(this, "startOfHandleMove")), this.handleContainer.bind("mousedown.handle", $.proxy(this, "onHandleContainerMousedown")), this.handleContainer.bind("mouseenter.container mouseleave.container", $.proxy(this, "onHandleContainerHover")), this.handleArrows.bind("mousedown.arrows", $.proxy(this, "onArrowsMousedown")), this.container.bind("mousewheel.container", $.proxy(this, "onMouseWheel")), this.container.bind("mouseenter.container mouseleave.container", $.proxy(this, "onContentHover")), this.handle.bind("click.scrollbar", this.preventClickBubbling), this.handleContainer.bind("click.scrollbar", this.preventClickBubbling), this.handleArrows.bind("click.scrollbar", this.preventClickBubbling), this
    },
    mousePosition : function(ev) {
      return ev.pageY || ev.clientY + (document.documentElement.scrollTop || document.body.scrollTop) || 0
    },
    repaint : function() {this.setHandle(), this.setHandlePosition()
    },
    scrollto : function(to) {
      var distance = 0;
      typeof to == "number" ? distance = (to < 0 ? 0 : to) / this.props.handleContentRatio : typeof to == "string" ? (to == "bottom" && ( distance = this.props.handlePosition.max), to == "middle" && ( distance = Math.ceil(this.props.handlePosition.max / 2))) : typeof to == "object" && !$.isPlainObject(to) && ( distance = Math.ceil(to.position().top / this.props.handleContentRatio)), this.handle.top = distance, this.setHandlePosition(), this.setContentPosition()
    },
    startOfHandleMove : function(ev) {ev.preventDefault(), ev.stopPropagation(), this.mouse.start = this.mousePosition(ev), this.handle.start = this.handle.top, $(document).bind("mousemove.handle", $.proxy(this, "onHandleMove")).bind("mouseup.handle", $.proxy(this, "endOfHandleMove")), this.handle.addClass("move"), this.handleContainer.addClass("move")
    },
    onHandleMove : function(ev) {
      ev.preventDefault();
      var distance = this.mousePosition(ev) - this.mouse.start;
      this.handle.top = this.handle.start + distance, this.setHandlePosition(), this.setContentPosition()
    },
    endOfHandleMove : function(ev) {$(document).unbind(".handle"), this.handle.removeClass("move"), this.handleContainer.removeClass("move")
    },
    setHandlePosition : function() {this.handle.top = this.handle.top > this.props.handlePosition.max ? this.props.handlePosition.max : this.handle.top, this.handle.top = this.handle.top < this.props.handlePosition.min ? this.props.handlePosition.min : this.handle.top, this.handle[0].style.top = this.handle.top + "px"
    },
    setContentPosition : function() {this.pane.top = -1 * this.props.handleContentRatio * this.handle.top, this.pane[0].style.top = this.pane.top + "px"
    },
    onMouseWheel : function(ev, delta) {this.handle.top -= delta, this.setHandlePosition(), this.setContentPosition(), this.handle.top > this.props.handlePosition.min && this.handle.top < this.props.handlePosition.max && ev.preventDefault()
    },
    onHandleContainerMousedown : function(ev) {
      ev.preventDefault();
      if(!$(ev.target).hasClass("scrollbar-handle-container"))
        return !1;
      this.handle.direction = this.handle.offset().top < this.mousePosition(ev) ? 1 : -1, this.handle.step = this.opts.scrollStep;
      var that = this;
      $(document).bind("mouseup.handlecontainer", function() {clearInterval(timer), that.handle.unbind("mouseenter.handlecontainer"), $(document).unbind("mouseup.handlecontainer")
      }), this.handle.bind("mouseenter.handlecontainer", function() {clearInterval(timer)
      });
      var timer = setInterval($.proxy(this.moveHandle, this), this.opts.scrollTimeout)
    },
    onArrowsMousedown : function(ev) {ev.preventDefault(), this.handle.direction = $(ev.target).hasClass("scrollbar-handle-up") ? -1 : 1, this.handle.step = this.opts.scrollStepArrows, $(ev.target).addClass("move");
      var timer = setInterval($.proxy(this.moveHandle, this), this.opts.scrollTimeoutArrows);
      $(document).one("mouseup.arrows", function() {clearInterval(timer), $(ev.target).removeClass("move")
      })
    },
    moveHandle : function() {this.handle.top = this.handle.direction === 1 ? Math.min(this.handle.top + this.handle.step, this.props.handlePosition.max) : Math.max(this.handle.top - this.handle.step, this.props.handlePosition.min), this.handle[0].style.top = this.handle.top + "px", this.setContentPosition()
    },
    onContentHover : function(ev) {ev.type === "mouseenter" ? (this.container.addClass("hover"), this.handleContainer.addClass("hover")) : (this.container.removeClass("hover"), this.handleContainer.removeClass("hover"))
    },
    onHandleContainerHover : function(ev) {ev.type === "mouseenter" ? this.handleArrows.addClass("hover") : this.handleArrows.removeClass("hover")
    },
    preventClickBubbling : function(ev) {
      ev.stopPropagation()
    }
  }, $.fn.scrollbar.contentHeight = function(container) {
    var wrapper = container.wrapInner("<div/>").find(":first"), height = wrapper.css({
      overflow : "hidden"
    }).height();
    return wrapper.replaceWith(wrapper.contents()), height
  }, $.fn.defaultCss = function(styles) {
    var notdef = {
      right : "auto",
      left : "auto",
      top : "auto",
      bottom : "auto",
      position : "static"
    };
    return this.each(function() {
      var elem = $(this);
      for(var style in styles)elem.css(style) === notdef[style] && elem.css(style, styles[style])
    })
  }, $.event.special.mousewheel = {
    setup : function() {
      this.addEventListener ? (this.addEventListener("mousewheel", $.fn.scrollbar.mouseWheelHandler, !1), this.addEventListener("DOMMouseScroll", $.fn.scrollbar.mouseWheelHandler, !1)) : this.onmousewheel = $.fn.scrollbar.mouseWheelHandler
    },
    teardown : function() {
      this.removeEventListener ? (this.removeEventListener("mousewheel", $.fn.scrollbar.mouseWheelHandler, !1), this.removeEventListener("DOMMouseScroll", $.fn.scrollbar.mouseWheelHandler, !1)) : this.onmousewheel = null
    }
  }, $.fn.extend({
    mousewheel : function(fn) {
      return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel")
    },
    unmousewheel : function(fn) {
      return this.unbind("mousewheel", fn)
    }
  }), $.fn.scrollbar.mouseWheelHandler = function(event) {
    var orgEvent = event || window.event, args = [].slice.call(arguments, 1), delta = 0, returnValue = !0, deltaX = 0, deltaY = 0;
    return event = $.event.fix(orgEvent), event.type = "mousewheel", event.wheelDelta && ( delta = event.wheelDelta / 120), event.detail && ( delta = -event.detail / 3), orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS && ( deltaY = 0, deltaX = -1 * delta), orgEvent.wheelDeltaY !== undefined && ( deltaY = orgEvent.wheelDeltaY / 120), orgEvent.wheelDeltaX !== undefined && ( deltaX = -1 * orgEvent.wheelDeltaX / 120), args.unshift(event, delta, deltaX, deltaY), $.event.handle.apply(this, args)
  }
})(jQuery, document)
function slideSwitch() {
  var active = jQuery('#slideshow IMG.active');

  if(active.length == 0)
    active = jQuery('#slideshow IMG:last');

  var next = active.next().length ? active.next() : jQuery('#slideshow IMG:first');

  active.addClass('last-active');
  next.css({
    opacity : 0.0
  }).addClass('active').animate({
    opacity : 1.0
  }, 1000, function() {
    active.removeClass('active last-active');
  });
}

function validateEmail(elementValue) {
  var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  return emailPattern.test(elementValue);
}


jQuery(document).ready(function() {
  //$('.scrollable').scrollbar();
  $('#save_mail').click(function(e) {
    var $mail = $('#mail');
    var $lastname = $('#name');
    var $firstname = $('#firstname');
    var mail = $mail.val();
    var lastname = $lastname.val();
    var firstname = $firstname.val();
    $lastname.val('');
    $firstname.val('');
    $mail.val('');
    if(validateEmail(mail)) {
      $.post('/index.php?article_id=63', {
        mail : mail,
        firstname : firstname,
        lastname : lastname
      }, function(data) {
        response = jQuery.parseJSON(data);
        if(response.success) {
          alert(unescape('Sie wurden f%FCr die LEA-News eingetragen'));
        } else {
          alert(unescape('Sie wurden schon f%FCr die LEA-News eingetragen oder haben eine falsche Emailadresse angegeben.'));
        }
      });
    } else {
      alert('Bitte geben Sie eine richtige Adresse ein.');
    }
    e.preventDefault();
  });
  var contact_html = '<a href="kontakt.html"><img src="./files/ordner/contact.gif" /></a>'
  //jQuery('#impressum').append(contact_html);
  jQuery('.hideDescription').click(function(event) {
    jQuery('.description').fadeOut();
    event.preventDefault();
  });
  jQuery('.imageWrapper ').live('click', function() {
    descriptionObject = jQuery(this).children('.description');
    if(descriptionObject.is(':hidden')) {

      jQuery('.description').fadeOut();
      descriptionWidth = descriptionObject.width();
      descriptionHeight = descriptionObject.height();
      offsetAr = jQuery(this).offset();
      if((offsetAr.left + descriptionWidth ) > window.screen.availWidth) {
        tooMuch = (offsetAr.left + descriptionWidth ) - window.screen.availWidth + 100;
        jQuery(descriptionObject.css({
          'left' : -tooMuch + 'px'
        }));
      }
      if((offsetAr.top + descriptionHeight ) > window.screen.availHeight) {
        tooMuch = (offsetAr.top + descriptionHeight ) - window.screen.availHeight + 100;
        jQuery(descriptionObject.css({
          'top' : -tooMuch + 'px'
        }));
      }

      descriptionObject.css({
        position : 'absolute',
        width : descriptionWidth,
        height : descriptionHeight
      });
      descriptionObject.fadeIn('slow');
    }
  });
  jQuery('.imageWrapper').hover(function() {
    elementId = jQuery(this).attr('rel');
    jQuery(this).children('img').attr('src', './files/word_images/image_' + elementId + '_off.png');
  }, function() {
    elementId = jQuery(this).attr('rel');
    jQuery(this).children('img').attr('src', './files/word_images/image_' + elementId + '_on.png');
  })

  jQuery(".nav img").hover(function(event) {

    jQuery(".nav img").each(function() {
      var id = jQuery(this).attr("id");
      if(jQuery(this).attr("class") == "current" || jQuery(this).attr("class") == "active") {
        jQuery(this).attr({
          src : "files/ordner/navactive" + id + ".gif"
        });
      } else {
        jQuery(this).attr({
          src : "files/ordner/nav" + id + ".gif"
        });
      }
    });
    var id2 = jQuery(this).attr("id");
    jQuery(this).attr({
      src : "files/ordner/navactive" + id2 + ".gif"
    });
  });

  jQuery("#content").hover(function(event) {
    jQuery(".nav img").each(function() {
      var id = jQuery(this).attr("id");
      if(jQuery(this).attr("class") == "current" || jQuery(this).attr("class") == "active") {
        jQuery(this).attr({
          src : "files/ordner/navactive" + id + ".gif"
        });
      } else {
        jQuery(this).attr({
          src : "files/ordner/nav" + id + ".gif"
        });
      }
    });
  });

  jQuery(".nav img").hover(function(event) {
    jQuery(".nav img").each(function() {
      var id = jQuery(this).attr("id");
      if(jQuery(this).attr("class") == "current" || jQuery(this).attr("class") == "active") {
        jQuery(this).attr({
          src : "files/ordner/navactive" + id + ".gif"
        });
      } else {
        jQuery(this).attr({
          src : "files/ordner/nav" + id + ".gif"
        });
      }
    });
    var id2 = jQuery(this).attr("id");
    jQuery(this).attr({
      src : "files/ordner/navactive" + id2 + ".gif"
    });
  });

  jQuery("#navi img").hover(function() {
    clearInterval(threadId);
  });
  jQuery(function() {
    var threadID;
    threadId = setInterval("slideSwitch()", 5000);
  });
  noScrollable = false;

  if(parseInt(jQuery('#article_id').html()) == 35) {
    if(jQuery('#einblickeSlideShow').html() != null) {
      jQuery('#page_up').remove();
      jQuery('.next').remove();
      jQuery('img[alt=top]').remove();
      jQuery('#content_container').css({
        'height' : '410px',
        'width' : '100%',
        'margin' : 0,
        'margin-top' : '15px',
        'left' : 0

      });
      jQuery('#content').css({
        'height' : '410px',
        'margin-top' : '36px',
        'width' : '100%',
        'text-align' : 'center'
      });

      var divWidth = jQuery('#content_container').width();
      if(document.readyState != "complete") {
        jQuery('#einblickeSlideShow img').each(function() {
          var pic = jQuery(this);
          jQuery(window).load(function() {
            pic.removeAttr("width");
            pic.removeAttr("height");
            pic.css('width', "");
            var imgWidth = pic.width();
            var difference = divWidth - imgWidth;
            pic.css({
              'margin-left' : (difference / 2) + 'px'
            });
          });
        });
      }
    }
    var controls = '<a href="" id="next" ><img src="./files/ordner/next.gif" /></a>' + '<a href="" id="prev" ><img src="./files/ordner/prev.gif" /></a>';
    jQuery('#einblickeSlideShow').before(controls);
    jQuery('#einblickeSlideShow').cycle({
      next : '#next',
      prev : '#prev',
      fx : 'fade',
      fits : false,
      timeout : 0,
      before : function(currSlideElement) {

        var title = $(this).attr('rel');
        if(title && title != '') {
          $('#slideShowTitle').remove();

          if(title != 'Titel') {
            $('#einblickeSlideShow').append('<div id="slideShowTitle">' + title + '</div>');
          }
        }
      }
    });

  } else {
    var noScrollable = true;
  }
  if(noScrollable) {
    jQuery(function() {
      jQuery("div.scrollable").scrollable({
        size : 1,
        vertical : true,
        speed : 800,
        easing : 'linear',
        disabledClass : 'hidden',
        mousewheel : true
      });
      jQuery('#page_down').hover(function(e) {
        return false;
      });
      jQuery('#page_up').hover(function(e) {
        return false;
      });
      jQuery('.prev').click(function() {
        myScrollable = jQuery("div.scrollable").data("scrollable");
        myScrollable.move(-1);
      });
      jQuery('.next').click(function() {
        myScrollable = jQuery("div.scrollable").data("scrollable");
        myScrollable.move(1);
      });
    });
  }
});

