(function($) {
  $.fn.ContentSlider = function(options)
  {
    var defaults = {
      leftBtn : 'images/arrow_left.png',
      rightBtn : 'images/arrow_right.png',
      width : '300px',
      height : '50px',
      speed : 600,
      easing : 'easeOutBack',
      textResize : false,
	  sliderId : 'not'
    }
	
   var defaultWidth = defaults.width;
    var o = $.extend(defaults, options);
    var w = parseInt(o.width);
    var n = this.children('.sel_wrapper').children('.sel_slider').children('.sel_article').length;
	var linkCount=this.find('a').length;
    var x = -1*w*n+w; // Minimum left value
    var p = parseInt(o.width)/parseInt(defaultWidth);
    var thisInstance = this.attr('id');
    var inuse = false; // Prevents colliding animations
	
    function moveSlider(d, b)
    {
      var l = parseInt(b.siblings('.sel_wrapper').children('.sel_slider').css('left'));
      if(isNaN(l)) {
        var l = 0;
      }
      var m = (d=='left') ? l-w : l+w;
      if(m<=0&&m>=x) {
        b
          .siblings('.sel_wrapper')
            .children('.sel_slider')
              .animate({ 'left':m+'px' }, o.speed, o.easing, function() {
                inuse=false;
              });

        if(b.attr('class')=='sel_leftBtn') {
          var thisBtn = $('#'+thisInstance+' .sel_leftBtn');
          var otherBtn = $('#'+thisInstance+' .sel_rightBtn');
        } else {
          var thisBtn = $('#'+thisInstance+' .sel_rightBtn');
          var otherBtn = $('#'+thisInstance+' .sel_leftBtn');
        }
        if(m==0||m==x) {
          thisBtn.css({ 'display':'none' }).hide();
        }
        if(otherBtn.css('display')=='none') {
          otherBtn.show().css({'display':'block'});
        }
      }
    }

    function vCenterBtns(b)
    {
      // Safari and IE don't seem to like the CSS used to vertically center
      // the buttons, so we'll force it with this function
      var mid = parseInt(o.height)/2;
      b
        .find('.sel_leftBtn img').css({ 'top':mid+'px', 'padding':0 }).end()
        .find('.sel_rightBtn img').css({ 'top':mid+'px', 'padding':0 });
    }

    return this.each(function() {
      $(this)
        // Set the width and height of the div to the defined size
        .css({
          width:o.width,
          height:o.height
        })
        // Add the buttons to move left and right
        //.prepend('<a href="#" class="sel_leftBtn"><img src="'+o.leftBtn+'" /></a>')
        //.append('<a href="#" class="sel_rightBtn"><img src="'+o.rightBtn+'" /></a>')
        // Dig down to the article div elements
        .find('.sel_article')
          // Set the width and height of the div to the defined size
          .css({
            width:o.width,
            height:o.height
          })
          .end()
        // Animate the entrance of the buttons
        //.find('.sel_leftBtn')
          //.css('opacity','0')
         // .hide()
         // .end()
       // .find('.sel_rightBtn')
         // .hide()
         // .animate({ 'width':'show' });

      // Resize the font to match the bounding box
      if(o.textResize===true) {
        var h2FontSize = $(this).find('h2').css('font-size');
        var pFontSize = $(this).find('p').css('font-size');
        $.each(jQuery.browser, function(i) {
          if($.browser.msie) {
             h2FontSize = o.IE_h2;
             pFontSize = o.IE_p;
          }
        });
        $(this).find('h2').css({ 'font-size' : parseFloat(h2FontSize)*p+'px', 'margin-left' : '66%' });
        $(this).find('p').css({ 'font-size' : parseFloat(pFontSize)*p+'px', 'margin-left' : '66%' });
        $(this).find('.readmore').css({ 'font-size' : parseFloat(pFontSize)*p+'px', 'margin-left' : '66%' });
      }

      // Store a copy of the button in a variable to pass to moveSlider()
      var leftBtn = $(this).children('.sel_leftBtn');
	 
      leftBtn.bind('click', function() {
        if(inuse===false) {
          inuse = true;
          moveSlider('right', leftBtn);
        }
        return false; // Keep the link from firing
      });

      // Store a copy of the button in a variable to pass to moveSlider()
      var rightBtn = $(this).children('.sel_rightBtn');
      rightBtn.bind('click', function() {									   
        if(inuse===false) {
          inuse=true;
          moveSlider('left', rightBtn);

        }
        return false; // Keep the link from firing
		
      });
// schreibe links

	for (i=0;i<=linkCount;i++){
		$(this).find('td a').attr('href','javascript:void(0);');
		
	}
      vCenterBtns($(this)); // This is a CSS fix function.
    });
  }
})(jQuery)

