﻿function jNewsSingleToggle() {

   jQuery('.MoreText').hide();

   jQuery('.news-list-morelink').click(function() {
      jQuery(this).blur().parent().parent().children('.MoreText').slideToggle();
      
      var str = jQuery(this).html();
      if (jQuery(this).html() == '[mehr]')       str = '[weniger]';
      if (jQuery(this).html() == '[weniger]')    str = '[mehr]';
      if (jQuery(this).html() == '[more]')       str = '[less]';
      if (jQuery(this).html() == '[less]')       str = '[more]';
      jQuery(this).text(str);
  });
}

function jNewsVerticalScroller_alt() {

   //Ermitteln der Anzahl an Kategorien
   var news_count = jQuery('div.news-list-item').length;
   var hidden_count = 0;
   
   var box = jQuery('div.news-list-container');
   
   var btn_scrl_up = '<img id="btn_scroll_up" src="fileadmin/images/icons/scroll_up.png" width="16" height="16" border="0" alt="" title="" />';
   var btn_dummy_up = '<div id="btn_dummy_up" style="height: 16px;width:16px;"></div>';
   var vert_line = '<div style="background-color:#BBB;border-left:8px solid #FFF; height:280px;width:1px;"></div>';
   var btn_scrl_down = '<img id="btn_scroll_down" src="fileadmin/images/icons/scroll_down.png" width="16" height="16" border="0" alt="" title="" />';
   var btn_dummy_down = '<div id="btn_dummy_down" style="height: 16px;width:16px;"></div>';

   var slider_area = '<div id="slider_area" style="float:right; height:320px; width:16px;">' +
                        btn_scrl_up + btn_dummy_up + vert_line + btn_scrl_down + btn_dummy_down + '</div>';
   
   jQuery(box).css({
      'height' : '300px',
      'overflow' : 'hidden'
   });
   jQuery(box).before(slider_area);
   jQuery('#btn_scroll_up').hide();
   jQuery('#btn_dummy_down').hide();
   
   jQuery('#btn_scroll_down').click(function() {
      if(hidden_count<news_count) {
         if(hidden_count==0) {
            jQuery('#btn_scroll_up').show();
            jQuery('#btn_dummy_up').hide();
         }
         jQuery('div.news-list-item:eq('+hidden_count+')').slideUp();
         hidden_count++;
         
         if(hidden_count==news_count-2) {
            jQuery('#btn_scroll_down').hide();
            jQuery('#btn_dummy_down').show();
         }
      }
   });
   jQuery('#btn_scroll_up').click(function() {
      if(hidden_count>0) {
         if(hidden_count==news_count-2) {
            jQuery('#btn_scroll_down').show();
            jQuery('#btn_dummy_down').hide();
         }
         
         jQuery('div.news-list-item:eq('+(hidden_count-1)+')').slideDown();
         hidden_count--;
         if(hidden_count==0) {
            jQuery('#btn_scroll_up').hide();
            jQuery('#btn_dummy_up').show();
         }
      }
   });

}

function jNewsVerticalScroller() {

   var box = jQuery('div.news-list-container');
   // Pixelhöhe des gesamten News-Containers:
   var box_height = jQuery(box).height();
   // Scroll-Stepsize:
   var step_size = Math.floor(box_height/10);
   var max_scroll_steps = Math.floor(box_height/step_size);

   // Zusätzliche Höhe durch ein-/ausklappbare "More"-Texte hinzuaddieren:
   var zusatz = jQuery('.MoreText').height();
   zusatz = Math.floor(zusatz/10);
   
   max_scroll_steps += zusatz;

   // Ermitteln der Anzahl an Kategorien
   //var news_count = jQuery('div.news-list-item').length;
   var scroll_step = 0;

   jQuery(box).wrapInner('<div id="inner_box" />');

   var slidebox = '<div class="slidebox" style="height:'+step_size+'px;width:100px;"></div>';
   
   // Füge max_scroll_steps viele slidebare Boxen vor die inner Box :)
   for  (var i=0; i<= max_scroll_steps; i++) {
      jQuery('div.news-list-item:eq(0)').before(slidebox);   
   }
   
   var btn_scrl_up = '<img id="btn_scroll_up" src="fileadmin/images/icons/scroll_up.png" width="16" height="16" border="0" alt="" title="" />';
   var btn_dummy_up = '<div id="btn_dummy_up" style="height: 16px;width:16px;"></div>';
   var vert_line = '<div style="background-color:#BBB;border-left:8px solid #FFF; height:300px;width:1px;"></div>';
   var btn_scrl_down = '<img id="btn_scroll_down" src="fileadmin/images/icons/scroll_down.png" width="16" height="16" border="0" alt="" title="" />';
   var btn_dummy_down = '<div id="btn_dummy_down" style="height: 16px;width:16px;"></div>';

   var slider_area = '<div id="slider_area" style="float:right; height:340px; width:16px;">' +
                        btn_scrl_up + btn_dummy_up + vert_line + btn_scrl_down + btn_dummy_down + '</div>';
   
   jQuery(box).css({
      'height' : '320px',
      'overflow' : 'hidden'
   });
   jQuery('div#inner_box').css({
      'position' : 'relative',
      'left' : '0',
      'top' : -box_height - step_size*(zusatz+1)
   });
   
   jQuery(box).before(slider_area);

   jQuery('#btn_scroll_up').hide();
   jQuery('#btn_dummy_down').hide();
 

   jQuery('#btn_scroll_down').click(function() {
      if(scroll_step<max_scroll_steps) {
         if(scroll_step==0) {
            jQuery('#btn_scroll_up').show();
            jQuery('#btn_dummy_up').hide();
         }
         jQuery('div.slidebox:eq('+scroll_step+')').slideUp();
         scroll_step++;
         
         if(scroll_step==max_scroll_steps+2) {
            jQuery('#btn_scroll_down').hide();
            jQuery('#btn_dummy_down').show();
         }
      }
   });
   jQuery('#btn_scroll_up').click(function() {
      if(scroll_step>0) {
         if(scroll_step==max_scroll_steps+2) {
            jQuery('#btn_scroll_down').show();
            jQuery('#btn_dummy_down').hide();
         }
         
         jQuery('div.slidebox:eq('+(scroll_step-1)+')').slideDown();
         scroll_step--;
         if(scroll_step==0) {
            jQuery('#btn_scroll_up').hide();
            jQuery('#btn_dummy_up').show();
         }
      }
   });

   /* 
   
   // Falls eine Scrollsbar benutzt würde, könnte per Mouse gescrollt werden.. 
   var tempScrollTop, currentScrollTop = 0;

   jQuery('div#inner_box').scroll(function(){
      currentScrollTop = jQuery('div#inner_box').scrollTop();
      
      //scrolling down
      if (tempScrollTop < currentScrollTop) {
         if(scroll_step<max_scroll_steps) {
            if(scroll_step==0) {
               jQuery('#btn_scroll_up').show();
               jQuery('#btn_dummy_up').hide();
            }
            jQuery('div.slidebox:eq('+scroll_step+')').slideUp();
            scroll_step++;
            
            if(scroll_step==max_scroll_steps+2) {
               jQuery('#btn_scroll_down').hide();
               jQuery('#btn_dummy_down').show();
            }
         }
      }

      //scrolling up
      else if (tempScrollTop > currentScrollTop) {
         if(scroll_step>0) {
            if(scroll_step==max_scroll_steps+2) {
               jQuery('#btn_scroll_down').show();
               jQuery('#btn_dummy_down').hide();
            }
            
            jQuery('div.slidebox:eq('+(scroll_step-1)+')').slideDown();
            scroll_step--;
            if(scroll_step==0) {
               jQuery('#btn_scroll_up').hide();
               jQuery('#btn_dummy_up').show();
            }
         }
      }
      tempScrollTop = currentScrollTop;
   });
   
   */
   
}

function jTeaserMenu() {

   //jQuery('#css_teaser_menu>ul>li:not(.marked)').mouseenter(
   //jQuery('#css_teaser_menu>ul>li:not(.li_marked)>a:not(.a_marked)').mouseenter(
   jQuery('#css_teaser_menu>ul>li>a:not(.a_marked)').mouseenter(
      function() {
         if( jQuery(this).parent().hasClass('teaser_cat_selected')) return;
      
         jQuery(this).addClass('a_marked');
         jQuery(this).parent().siblings().children('a.a_marked').removeClass('a_marked');
         
         jQuery(this).parent().addClass('teaser_cat_selected');
         jQuery(this).parent().siblings().removeClass('teaser_cat_selected');
         
         jQuery(this).css({
            'color' : '#fff',
            'z-index' : '9999999'
         });
         jQuery(this).parent().siblings().children('a.teaser_cat_link').css( {
            'color' : '#444',
            'position' : 'relative'
         });
         
         jQuery(this).parent().find('div.teaser_text_title').hide();
         jQuery(this).parent().find('div.teaser_cat_text_1').hide();
         jQuery(this).parent().find('div.teaser_cat_text_2').hide();

         jQuery(this).parent().find('div.teaser_text_title').fadeIn(400);
         jQuery(this).parent().find('div.teaser_cat_text_1').fadeIn(400);
         jQuery(this).parent().find('div.teaser_cat_text_2').fadeIn(400);
        
         /*
         jQuery(this).addClass('teaser_cat_selected');
         jQuery(this).siblings().removeClass('teaser_cat_selected');
         
         jQuery(this).children('a.teaser_cat_link').css({
            'color' : '#fff',
            'z-index' : '9999999'
         });
         jQuery(this).siblings().children('a.teaser_cat_link').css( {
            'color' : '#444',
            'position' : 'relative'
         });

         jQuery(this).find('div.teaser_text_title').hide();
         jQuery(this).find('div.teaser_cat_text_1').hide();
         jQuery(this).find('div.teaser_cat_text_2').hide();

         jQuery(this).find('div.teaser_text_title').fadeIn(400);
         jQuery(this).find('div.teaser_cat_text_1').fadeIn(400);
         jQuery(this).find('div.teaser_cat_text_2').fadeIn(400);
         //*/
		}
	);
}

function jMenu() {

   // Horizontales Menü:
   // Blendet Gif bei Click auf Menüpunkt ein:
 
  jQuery('.unselected a').click(function() {
	jQuery(this).blur().parent().siblings('div.selected').removeClass('selected').addClass('unselected').end().addClass('selected_wait');
    //return true;
  });
 
   // Vertikales Menü:
   // Blendet Gif bei Click auf Menüpunkt ein:

  jQuery('.sub02 a').click(function() {
	jQuery(this).blur().parent().siblings('li.sub02cur').removeClass('sub02cur').addClass('sub02').end().addClass('sub02wait');
    //return true;
  });
  
  jQuery('.sub01 a').click(function() {
	jQuery(this).blur().parent().addClass('sub01wait');
    //return true;
  });
};

function runjQuery() {
  jQuery.noConflict();
  //var j = jQuery.noConflict();
  DEBUG = false;

   jMenu();
   jTeaserMenu();
   jNewsSingleToggle();
   jNewsVerticalScroller();
}


