
jQuery.noConflict();

jQuery(document).ready(function()
{
  // If News-Box is present
  if(document.getElementById('news_tab_content')){
    loadHomeNewsTagHeightHandler();
    loadHomeNewsHandler();
  }
  loadHomeWeatherHandler();

});

// Handler ------------------------------------------------------------------- 

function loadHomeNewsHandler()
{
  jQuery('.tab_bg:first').show(0);
  
  var news_tabs = document.getElementById('news_tabs').getElementsByTagName('li');
  ClassNames = new Array();
  for(i = 0; i < news_tabs.length; i++) {
    // Remove all links from Tab-Buttons if JS is available
    var link_construction = 'javascript:void(0)';
    news_tabs[i].getElementsByTagName('a')[0].setAttribute('href', link_construction);
    ClassNames[i] = news_tabs[i].className;
  }

  // Slide the arrow to position 1
  jQuery('#news_tabs li:eq(0)').click(
    function(){
      if(!jQuery(this).hasClass('active')){
        jQuery('.tab_arrow').stop(true, true).animate({left: "6.25em", color: "blue"}, {duration: 600, easing: 'easeOutBack'});
      }
    }
  );
  
  // Slide the arrow to position 2
  jQuery('#news_tabs li:eq(1)').click(
    function(){
      if(!jQuery(this).hasClass('active')){
        jQuery('.tab_arrow').stop(true, true).animate({left: "18.2em"}, {duration: 600, easing: 'easeOutBack'});
      }
    }
  );
  
  // Slide the arrow to position 3
  jQuery('#news_tabs li:eq(2)').click(
    function(){
      if(!jQuery(this).hasClass('active')){
        jQuery('.tab_arrow').stop(true, true).animate({left: "33.55em"}, {duration: 600, easing: 'easeOutBack'});
      }
    }
  );
  
  jQuery('#news_tabs li').click(
    function() {
      for(i = 0; i < news_tabs.length; i++){
        if(jQuery('#news_tab_content .tab_content:eq('+i+')').hasClass(jQuery(this).attr('class'))) {
          if(!jQuery(this).hasClass('active')){
            // Abort last animation, if new animation starts
            jQuery('#news_tabs li').stop(true, true);
            jQuery('#news_tab_content .tab_content').stop(true, true);
            
            // Hide the background of non-active Tab-Buttons
            jQuery('.tab_bg').fadeOut(500);
            
            jQuery('#news_tabs li').removeClass('active');
            // Slide up (hide) non-active Tab-Contents
            //jQuery('#news_tab_content>div').slideUp('slow').removeClass('active');
            jQuery('#news_tab_content .tab_content').css('position', 'absolute').fadeOut('slow',
              function() {
                // IE7 Bugfix: fadeOut doesn't set "display: none" to IE7
                jQuery(this).removeClass('active').css('display', 'none');
              }
            );
            
            // Slide down the active Tab-Content
            //jQuery('#news_tab_content>div:eq('+i+')').slideDown('slow').addClass('active');
            jQuery('#news_tab_content .tab_content:eq('+i+')').css('position', 'relative').fadeIn('slow').addClass('active');
            
            jQuery(this).show('fast').addClass('active');
            
            // Fade the Color of the non-active Tab-Button to grey
            jQuery('#news_tabs li').filter('li:not(.active)').children('a').children('span').animate({ color: '#4c4c4c' }, 300);
                        
            // Fade the color of the active Tab-Button to white
            jQuery(this).children('a').removeClass('hover').children('span').animate({ color: '#ffffff' }, 300);

            // Background of the active Tab-Button
            jQuery(this).children('.tab_bg').stop(true, true).fadeIn(300);
            
          }
        }
      }
  });
  
  /* change color on tab hover */
  jQuery('#news_tabs ul li').hover(
    function() {
      if(!jQuery(this).hasClass('active')) {
        jQuery(this).stop(true, true).children('a').addClass('hover');
        jQuery(this).children('a').children('span').stop(true, true).css('color', '#c42e00');
      }
    },
    function(){
      if(!jQuery(this).hasClass('active')) {
        jQuery(this).children('a').removeClass('hover').children('span').stop(true, true).css('color', '#4c4c4c');
      }
    }
  );
  
  /* Hover-effect of the news fields */
  jQuery('.news-latest-item').hover(
    function(){
      jQuery(this).addClass('hover');
    },
    function(){
      jQuery(this).removeClass('hover');
    }
  );
  
  /* Link behaviour on click */
  jQuery('.news-latest-item').click(
    function(){
      window.location.href = jQuery(this).children('.news-latest-item-border').children('h3:first').children('a').attr('href');
    }
  );
}

function loadHomeNewsTagHeightHandler()
{  
  jQuery('.tx-calendar-pi1 .news-latest-item:first').addClass('first');
  /* Set start-height of the news-content div */
  var highest_news_tab_height = jQuery('#news_tab_content .tab_content:first .news-latest-items').height();
  
      // Show all boxes to calculate the highest box
        jQuery('#news_tab_content .tab_content').filter(':not(.active)').css('display', 'block');
        
        for(var i = 0; i < jQuery('#news_tab_content .tab_content').length; i++) {
          if(highest_news_tab_height < jQuery('#news_tab_content .tab_content:eq('+i+') .news-latest-items').height())
            var highest_news_tab_height = jQuery('#news_tab_content .tab_content:eq('+i+') .news-latest-items').height();
        }
        
      // hide all not visible boxes
        jQuery('#news_tab_content .tab_content').filter(':not(.active)').css('display', 'none');

  // IE6 uses high instead of min-height
  if(window.navigator.userAgent.indexOf("MSIE 6") > -1){
    jQuery('#news_tab_content .tab_content .news-latest-items').css('height', highest_news_tab_height);
    
    /* If other news-content boxes are higher, set new height */
    jQuery('#news_tabs li').click(
      function() {
        if(highest_news_tab_height < jQuery('#news_tab_content .tab_content:visible .news-latest-items').height()) {
          highest_news_tab_height = jQuery('#news_tab_content .tab_content:visible .news-latest-items').height();
          jQuery('#news_tab_content .tab_content .news-latest-items').css('height', highest_news_tab_height);
        }
    });
  } else {
    jQuery('#news_tab_content .tab_content .news-latest-items').css('min-height', highest_news_tab_height);
    
    /* If other news-content boxes are higher, set new height */
    jQuery('#news_tabs li').click(
      function() {
        if(highest_news_tab_height < jQuery('#news_tab_content .tab_content:visible .news-latest-items').height()) {
          highest_news_tab_height = jQuery('#news_tab_content .tab_content:visible .news-latest-items').height();
          jQuery('#news_tab_content .tab_content .news-latest-items').css('min-height', highest_news_tab_height);
        }
    });
  }
}

function loadHomeWeatherHandler()
{
  var jahr, monat, tag, stunden, minuten;
  var AktuellesDatum = new Date();
  jahr = AktuellesDatum.getYear()-2000;
  monat = AktuellesDatum.getMonth ()+1;
  tag = AktuellesDatum.getDate();
  stunden = AktuellesDatum.getHours();
  minuten = AktuellesDatum.getMinutes();
  
  if(jahr < 0) {jahr += 1900;}
  jQuery('.weather #date').text(tag+"."+monat+"."+jahr+", ");

  
  jQuery('.weather').hover(
    function(){
      jQuery('.weather_info .extended').slideDown(500);
      jQuery('.weather_details').slideUp(500);
      jQuery(this).addClass('extended_weather');
    },
    function(){
      jQuery('.weather_info .extended').stop(true, true).slideUp(500);
      jQuery('.weather_details').stop(true, true).slideDown(500);
      jQuery(this).removeClass('extended_weather');
  });
}