
jQuery.noConflict();

jQuery(document).ready(function()
{
  site_url = "http://www.braeunlingen.de/";
  
  loadWesJQueryExtensions();
  
  // Accordion plugin
  /*
  jQuery('.accordion').accordion({
    autoHeight:false,
    header: 'h3'
    //animated: 'bounceslide'
  });
  */
  
  // If News-Box is present
  if(document.getElementById('news_tab_content')){
    //loadHomeNewsAnimatedArrowHandler();
    
    //loadHomeNewsTagHeightHandler();
    // Version 2 is for visiblity:hidden instead of display:none
    loadHomeNewsTagHeightHandler_v2();
    
    if(document.getElementById('news_tabs')) {
      loadHomeNewsHandler_v2();
    }
  }
  loadNavHandler();
  
  loadFancyboxHandler();
  loadCatTreeHandler();
  loadCalHandler(site_url);
  loadUserInteractHandler();
  loadSliderHeader();
  
  loadImageRightClickBlockHandler();

});

// 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: "20.9em"}, {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);
            jQuery('#news_tabs li').filter('li:not(.active)').children('a').children('span');
                        
            // Fade the color of the active Tab-Button to white
            //jQuery(this).children('a').removeClass('hover').children('span').animate({ color: '#ffffff' }, 300);
            jQuery(this).children('a').removeClass('hover').children('span');

            // 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');
        jQuery(this).children('a').children('span').stop(true, true);
      }
    },
    function(){
      if(!jQuery(this).hasClass('active')) {
        //jQuery(this).children('a').removeClass('hover').children('span').stop(true, true).css('color', '#4c4c4c');
        jQuery(this).children('a').removeClass('hover').children('span').stop(true, true);
      }
    }
  );
  
  /* 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 loadHomeNewsHandler_v2()
{
  jQuery('.tab_bg:first').show(0);

  jQuery('.news-latest-items h3.headline:first a span.more').hide();
  jQuery('.news-latest-items h3.headline a').click(
    function() {
      if(!jQuery(this).parent().hasClass('selected'))
        jQuery('.news-latest-items h3').filter('h3:not(this)').children('a').children('span.more').fadeIn(300);

        jQuery(this).children('span.more').fadeOut(300);
    }
  );

  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;
  }

  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');
            
            jQuery('#news_tab_content .active').css({
              'position' : 'absolute',
              'z-index' : '1'
            }).fadeOut('slow',
              function() {
                // IE7 Bugfix: fadeOut doesn't set "display: none" to IE7
                jQuery(this).removeClass('active').css('display', 'none');
              }
            );

            jQuery('#news_tab_content .tab_content:eq('+i+')').css({
              'display' : 'none',
              'position' : 'relative',
              'visibility' : 'visible',
              'z-index' : '10'
            }).fadeIn('slow').addClass('active');
            
            jQuery(this).show('fast').addClass('active');
            jQuery('#news_tabs li').filter('li:not(.active)').children('a').children('span');
            jQuery(this).children('a').removeClass('hover').children('span');

            // 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');
        jQuery(this).children('a').children('span').stop(true, true);
      }
    },
    function(){
      if(!jQuery(this).hasClass('active')) {
        //jQuery(this).children('a').removeClass('hover').children('span').stop(true, true).css('color', '#4c4c4c');
        jQuery(this).children('a').removeClass('hover').children('span').stop(true, true);
      }
    }
  );
  
  /* 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 loadHomeNewsTagHeightHandler_v2()
{
  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').height();
        
        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+')').height())
            var highest_news_tab_height = jQuery('#news_tab_content .tab_content:eq('+i+')').height();
        }

  // IE6 uses high instead of min-height
  if(window.navigator.userAgent.indexOf("MSIE 6") > -1){
    jQuery('#news_tab_content').css('height', highest_news_tab_height);

    jQuery('#news_tabs li').click(
      setNewHeight('height', highest_news_tab_height)
    );
  } else {
    jQuery('#news_tab_content').css('min-height', highest_news_tab_height);
    
    /* If other news-content boxes are higher, set new height */
    jQuery('#news_tabs li').click(
      setNewHeight('min-height', highest_news_tab_height)
    );
  }
}

function loadCalHandler(site_url)
{
  jQuery('.event_header_container').hover(
    function() {
      jQuery(this).parent().addClass('hover');
    },
    function() {
      jQuery(this).parent().removeClass('hover');
    }
  );


  jQuery('.event_list_item').click(
    function() {
      redirect_url = jQuery(this).children().children('.event_title').children('a').attr('href');
      //jQuery(window.location).attr('href', site_url + redirect_url);
      window.location = site_url + redirect_url;
    }
  );
}

function loadUserInteractHandler()
{
  var linked_opener_text = jQuery('#user_interact_opener a span').html();
  
  // checks cookies on reload and call last status of the interact area (openned/closed)
  interactCookieStatus(linked_opener_text);

  // Show login-box
  jQuery('#user_interact_opener a.icon').click(
    function() {
       interactBoxStatusChanger(linked_opener_text);
    }
  );
  
  jQuery('.ui_open').click(
    function() {
      interactBoxStatusChanger(linked_opener_text);
      /* deactivate links with the class ui_open */
      if(jQuery(this).attr('href')) {
        return false;
      }
    }
  );
 
  // Close User Interact, if click on content
  /*
  jQuery("html").click(function(event) {
    var target = jQuery(event.target);
    if (jQuery('#user_interact').is(':visible') && !target.is("#user_interact_container *") && !target.is('#user_interact_opener a') && !target.is('#user_interact_opener a span') && !target.is('.teaser')) {
      jQuery('#user_interact').slideUp(400);
      jQuery('#user_interact_opener a.icon').removeClass('opened').children('span').html(linked_opener_text);
    }
  });
  */
}

function loadFancyboxHandler() {
 
  // copy the rel-attr from <img> into <a>, because impossible in TypoScript
  jQuery('img[rel=image]').parent().parent('a').attr('rel', 'image');
  
  jQuery('a[rel=image]').fancybox({
    'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
    'title'         : this.title,
    'titlePosition' : 'inside',
    // inside titlePosition
    'titleFormat'   : function(title, currentArray, currentIndex, currentOpts) {
      // empty strings, if no title-attr
      if(title == undefined) {
        title = "";
      }
      if(currentArray.length < 2) {
        // no wrap, if no title
        if(title != "") {
          return title;
        }
      } else {
        // wrap Image numbers, if title exists
        return 'Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + ': ' + title;
      }
    }
  });
  
  // FE Editting iframe in fancybox
  jQuery('.edit_entry a.fe_admin').fancybox({
    'width'         : 770,
    'height'        : '75%', 
    'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'autoScale'     : true, 
    'type'          : 'iframe' 
  });
  
  // 
  jQuery('a.fancy_iframe').fancybox({
    'width'         : 956,
    'height'        : 590, 
    'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'autoScale'     : true,
		'titleShow'     : false,
    'type'          : 'iframe'
  });
  
  // Custom link to the 360 view of Bräunlingen
  jQuery('a.fancy_iframe360').fancybox({
    'width'         : 1000,
    'height'        : 700, 
    'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'autoScale'     : false,
		'titleShow'     : false,
    'type'          : 'iframe'
  });
  
}

function loadCatTreeHandler() {
  
  var loader = '<img class="loader_image" src="/fileadmin/images/default/loader.gif" alt="loader" />';
  jQuery('.category_tree_item li a').addClass('loader').append(loader);
  
  // add class="hasSub" on the cat-link if there are sub-categories
  jQuery('.category_tree_item_sub_container').prev().addClass('hasSub');
  
  // keep the second level openned on reload
  jQuery('.category_tree_item_sub .cur').parent().show().parent().parent().parent().addClass('active_sub');

  jQuery('.category_tree_item li a').click(
    function() {
      if(jQuery(this).next().hasClass('category_tree_item_sub_container')) {
        // if already visible, then hide it
        if(jQuery(this).next().is(':visible')) {
          jQuery('.category_tree_item_sub_container').hide().parent('li').removeClass('active_tree_sub');
          
          return false;
        }
        // hide other submenues
        jQuery('.category_tree_item_sub_container').hide().parent('li').removeClass('active_tree_sub');
        jQuery(this).next().show();
        jQuery(this).parent('li').addClass('active_tree_sub');
        return false;
      } else {
        jQuery('.loader_image').fadeOut('fast');
        jQuery(this).children('.loader_image').fadeIn('fast');
        
        // remove loader-image, when finished loading
        jQuery(window).unload(
          function() {
            jQuery('.loader_image').fadeOut('fast');
          }
        );  
      }
    }
  );
  jQuery("html").click(function(event) {
    var target = jQuery(event.target);
    if (!target.is('.category_tree_item') && !target.is('.category_tree_item *')) {
      jQuery('.category_tree_item_sub_container').hide().parent('li').removeClass('active_tree_sub');
    }
  });
  
}


function loadNavHandler()
{
  jQuery('#mainnav li').hover(
    function(){
      if(jQuery(this).hasClass("hasSub") || jQuery(this).hasClass("hasSub_active")) {
        jQuery(this).addClass('hasSub_hover');
      } else {
        jQuery(this).addClass('hover');
      }
    },
    function(){
      jQuery(this).removeClass('hover').removeClass('hasSub_hover');
    }
  );
  
  jQuery('.sub_level2_container').each(
    function() {
      var height = jQuery(this).height();
      jQuery(this).find('.sub_level3').css('minHeight', height);
      //alert(height);
    }
  );
}


function loadImageRightClickBlockHandler()
{
  // IE Fix
  jQuery('.no_contextmenu').find('*').attr('unselectable', 'on');
  
  // Tastenkombinationen verhindern
  jQuery('.no_contextmenu').bind('keydown', 'ctrl+a', function(e){
		e.preventDefault(); // Standardaktion verhindern
	});
	
	jQuery('.no_contextmenu').bind('keydown', 'ctrl+c', function(e){
    e.preventDefault(); // Standardaktion verhindern
	});
  
  jQuery('.no_contextmenu').find('img').bind("contextmenu",function(e){
    return false;
  });
  
  jQuery('body.no_contextmenu').bind("contextmenu",function(e){
    return false;
  });

}

// Helper Functions ------------------------------------------------------------
function setNewHeight(heightType, highest_news_tab_height)
{
  if(highest_news_tab_height < jQuery('#news_tab_content').height()) {
    highest_news_tab_height = jQuery('#news_tab_content').height();
    jQuery('#news_tab_content').css(heightType, highest_news_tab_height);
  }
}

function setTeaserHeight(teaser_height, teaser_number) {
  if(teaser_number >= 1) {
    for(i = 0; i < teaser_number; i++) {
      if(teaser_height < jQuery('.small_teaser_container:eq('+i+')').height()) {
        teaser_height = jQuery('.small_teaser_container:eq('+i+')').height();
      }
      if(window.navigator.userAgent.indexOf("MSIE 6") > -1){
        jQuery('.small_teaser').css('height', teaser_height);
      } else {
        jQuery('.small_teaser').css('min-height', teaser_height);
      }
    }
  }
}

var currentPosition = 0;

function loadSliderHeader() {
  
  
  var slideWidth = 1920;
  var slides = jQuery('.slider_image');
  var direction = 1;
  var numberOfSlides = slides.length;
  var slidingTime = 12000;

  jQuery('#header_image_selection_nav li:eq(0) span.active_bg').show();
  
  // Remove scrollbar in JS
  //jQuery('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
    .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      //'float' : 'left',
      //'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  //jQuery('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
  jQuery('.slider_container')
    .prepend('<div class="control" id="leftControl"></div>')
    .append('<div class="control" id="rightControl"></div>');

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  jQuery('.control')
    .bind('click', function (){
    jQuery('#slideInner .slider_image').css('opacity', 1);

    // Determine new position
	  currentPosition = (jQuery(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
    direction = (jQuery(this).attr('id')=='rightControl') ? direction = 1 : direction = -1;

	// Hide / show controls
    manageControls(currentPosition);
    
    if(currentPosition >= numberOfSlides-1 && direction == 1) {
      jQuery('#slideInner').stop(true, true).animate({
        //'marginLeft' : slideWidth*(-currentPosition)
      }, 300, function() {
        //jQuery(this).css('marginLeft', 0);
      });
      currentPosition = 0;
    } else if(currentPosition < 0 && direction == -1) {
      //jQuery('#slideInner').css('marginLeft', slideWidth*(-numberOfSlides+1)).stop(true, true);
      currentPosition = numberOfSlides-2;
      /*jQuery('#slideInner').animate({
        'marginLeft' : slideWidth*(-currentPosition)
      }, 300);*/
    } else {
      jQuery('#slideInner').stop(true, true).animate({
        //'marginLeft' : slideWidth*(-currentPosition)
      }, 300);
      
    }
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    jQuery('#leftControl').show();
    jQuery('#rightControl').show();
    
    // Hide left arrow if position is first slide
	//if(position==0){ jQuery('#leftControl').hide() } else{ jQuery('#leftControl').show() }
	// Hide right arrow if position is last slide
    //if(position==numberOfSlides-1){ jQuery('#rightControl').hide() } else{ jQuery('#rightControl').show() }
  }


    timer = setInterval( function() {
      direction = 1;
      if(currentPosition >= numberOfSlides-2) {
        currentPosition = 0;
      } else {
        currentPosition++;
      }
      
      // Hide / show controls
      manageControls(currentPosition);
      
      // Move slideInner using margin-left
      time_sliding(slideWidth, currentPosition);
    }, slidingTime );

  
  jQuery('.slider_container, #header_image_selection_nav a').hover(
    function() {
      jQuery(this).find('.control').css('visibility', 'visible');
      clearInterval(timer);
    }, function() {
      jQuery(this).find('.control').css('visibility', 'hidden');
      // Timer

        timer = setInterval( function() {
          direction = 1;
          
          if(currentPosition >= numberOfSlides-2) {
            currentPosition = 0;
          } else {
            currentPosition++;
          }

          // Hide / show controls
          manageControls(currentPosition);
          
          // Move slideInner using margin-left
          time_sliding(slideWidth, currentPosition);
        }, slidingTime );

    }
  );
}

function time_sliding(slideWidth, currentPosition) {

  // IE6 Bugfix
  var image_num = currentPosition+1;
  jQuery('#slideInner .slider_image').removeClass('active');
  jQuery('#slideInner .image'+image_num).addClass('active');

  // Image-Navi
  if( jQuery('#header_image_selection_nav li:eq('+(image_num-1)+')').find('span.active_bg').is(':visible') ) {
    return;
  } else {
    jQuery('#header_image_selection_nav li').removeClass('active');
    jQuery('#header_image_selection_nav li span.not_active_bg').fadeIn(300);
    jQuery('#header_image_selection_nav li span.active_bg').fadeOut(500);
  }
  
  jQuery('#header_image_selection_nav li:eq('+(image_num-1)+')').find('span.active_bg').stop(true, true).fadeIn(500).parent().children('span.not_active_bg').stop(true, true).fadeOut(500);

  
  pos = slideWidth*(-currentPosition);
  
  jQuery('#slideInner .slider_image').fadeOut(5000);
  jQuery('#slideInner .image'+image_num).fadeIn(5000);

}


function manual_time_sliding(slideToPosition) {

  slideWidth = 1920;
  
  // IE6 Bugfix
  var image_num = slideToPosition;
  currentPosition = slideToPosition-1;
  jQuery('#slideInner .slider_image').removeClass('active');
  jQuery('#slideInner .image'+image_num).addClass('active');
  
  // Image-Navi
  if( jQuery('#header_image_selection_nav li:eq('+(image_num-1)+')').find('span.active_bg').is(':visible') ) {
    return;
  } else {
    jQuery('#header_image_selection_nav li').removeClass('active');
    jQuery('#header_image_selection_nav li span.not_active_bg').fadeIn(300);
    jQuery('#header_image_selection_nav li span.active_bg').fadeOut(500);
  }
  
  jQuery('#header_image_selection_nav li:eq('+(image_num-1)+')').addClass('active').find('span.active_bg').stop(true, true).fadeIn(500).parent().children('span.not_active_bg').stop(true, true).fadeOut(500);

  
  pos = slideWidth*(-slideToPosition);
  
  jQuery('#slideInner .slider_image').stop(true, true).fadeOut(500);
  jQuery('#slideInner .image'+image_num).stop(true, true).fadeIn(500);
}


function interactBoxStatusChanger(linked_opener_text){
  if(jQuery('body').hasClass('fe_login')) {
    if(jQuery('#user_interact_body').is(':hidden')) {
      jQuery.cookie("wes_interact", 1, { path: '/'});
      jQuery('#user_interact_body').slideDown(400);
      jQuery('#top').scrollTo(600);
      jQuery('#user_interact_opener a.icon').addClass('opened').children('span').html('Schliessen');
    } else {
      jQuery.cookie("wes_interact", 0, { path: '/'});
      jQuery('#user_interact_body').slideUp(400);
      jQuery('#user_interact_opener a.icon').removeClass('opened').children('span').html(linked_opener_text);
    }
  } else {
    if(jQuery('#user_interact').is(':hidden')) {
      jQuery.cookie("wes_interact", 1, { path: '/'});
      jQuery('#user_interact').slideDown(400);
      jQuery('#top').scrollTo(600);
      jQuery('#user_interact_opener a.icon').addClass('opened').children('span').html('Schliessen');
    } else {
      jQuery.cookie("wes_interact", 0, { path: '/'});
      jQuery('#user_interact').slideUp(400);
      jQuery('#user_interact_opener a.icon').removeClass('opened').children('span').html(linked_opener_text);
    }
  }
}

function interactCookieStatus(linked_opener_text){
  if(jQuery('body').hasClass('fe_login')) {
    if(jQuery.cookie("wes_interact") == 1) {
      jQuery('#user_interact_body').show();
      jQuery('#user_interact_opener a.icon').addClass('opened').children('span').html('Schliessen');
    } else {
      jQuery('#user_interact_body').hide();
      jQuery('#user_interact_opener a.icon').removeClass('opened').children('span').html(linked_opener_text);
    }
  } else {
    if(jQuery.cookie("wes_interact") == 1) {
      jQuery('#user_interact').show();
      jQuery('#user_interact_opener a.icon').addClass('opened').children('span').html('Schliessen');
    } else {
      jQuery('#user_interact').hide();
      jQuery('#user_interact_opener a.icon').removeClass('opened').children('span').html(linked_opener_text);
    }
  }
}

// Scroll to window position extension
function loadWesJQueryExtensions() {
  jQuery.fn.extend({
    scrollTo : function(speed, easing) {
      return this.each(function() {
        var targetOffset = jQuery(this).offset().top;
        jQuery('html,body').animate({scrollTop: targetOffset}, speed, easing);
      });
    }
  });
}

function ieSelectBoxWidthFix() {
  //alert(window.navigator.userAgent);
  
  if(window.navigator.userAgent.indexOf("MSIE") > -1){
    jQuery('select').hover(
      function() {
        jQuery(this).addClass('ie_width_fix_hover');
        //jQuery(this).children('option:first').focus();
        jQuery(this).css('width', 'auto');
      }, function() {
        jQuery(this).removeClass('ie_width_fix_hover');
        jQuery(this).removeAttr('style');
      }
    );
    
    jQuery('select').focus(
      function() {
        jQuery(this).addClass('ie_width_fix_focus');
        jQuery(this).css('width', 'auto');
        //jQuery(this).children('option:first').focus();
      }
    );
    jQuery('select').blur(
      function() {
        jQuery(this).removeClass('ie_width_fix_focus');
        jQuery(this).removeAttr('style');
      }
    );
  }
}

