
/**
* Switch to the URL of the selected Item in the Dropdown-Menu
*/
function go2url(formEl){
 if (formEl.options[formEl.selectedIndex].value != "none") {
  document.location.href = formEl.options[formEl.selectedIndex].value
 }                       
}

function addBookmark(){

  URL = window.location.href;
  Text = document.title;

  if (window.sidebar)
    {
    // firefox
    window.sidebar.addPanel(Text,URL, "");
    }
  else if(window.opera && window.print)
    {
    // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',URL);
    elem.setAttribute('title',Text);
    elem.setAttribute('rel','sidebar');
    elem.click();
    }
  else if(document.all)
    {
    // ie
    window.external.AddFavorite(URL,Text);
    }
    
   return false;
}

jQuery.noConflict();

var subMenuActive = 0;

function menuFading(el, max, min) {
//  alert(max+" "+min+" "+jQuery(el).css("opacity"));
  if(jQuery(el).css("opacity")<max) {
    jQuery(el).stop().fadeTo('fast', max, function() {
      // Animation complete.
    });
  }
  else {
    jQuery(el).stop().fadeTo('fast', min, function() {
      // Animation complete.
      
    });
  }      
  
}

function clickSubmenu(el) {
//  alert(el);
  subMenuActive = el.attr("id").substr(2,1);
  for(var i=1; i<5; i++) {
//    alert(el.attr("id")+" == "+jQuery(".link-section"+i+" img").attr("id"));
    jQuery(".image-section"+i).stop().fadeTo('slow', (subMenuActive==i ? 1. : 0.), function() {});
    jQuery(".link-section"+i).stop().fadeTo('fast', (el.attr("id")==jQuery(".link-section"+i).attr("id") ? 1. : 0.5), function() {});
  }
  
}
jQuery(document).ready(function($) {

  // Slider
  
  $('.slider li').eq(0).attr("id", "slider_0");
  $('.slider li').eq(1).attr("id", "slider_1");
  $('.slider li').eq(2).attr("id", "slider_2");
//  $('<a href="#slider_1"><img src="fileadmin/templates/images/icons/arrow-down.png" class="arrow" /></a>').appendTo(".slider");
  
  // Anker-Scrolling
//  $.localScroll();
  // The default axis is 'y', but in this demo, I want to scroll both
  // You can modify any default like this
  $.localScroll.defaults.axis = 'x';
  
  // Scroll initially if there's a hash (#something) in the url
  $.localScroll.hash({
    target: '#content', // Could be a selector or a jQuery object too.
    queue:true,
    duration:1500
  });
  
  /**
  * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
  * also affect the >> and << links. I want every link in the page to scroll.
  */
  $.localScroll({
    target: '#content', // could be a selector or a jQuery object too.
    queue:true,
    duration:1000,
    onBefore:function( e, anchor, $target ){
      // The 'this' is the settings object, can be modified
    },
    onAfter:function( anchor, settings ){
      // The 'this' contains the scrolled element (#content)
    }
  });   
  
  
  // Hauptnavi
  $(".unternehmen a img").mouseenter(function(){
    $(this).stop().fadeTo(300, 0);
  })
  .mouseleave(function(){
    $(this).stop().fadeTo(300, 1);
  })
  $(".kompetenzen a img").mouseenter(function(){
    $(this).stop().fadeTo(300, 0);
  })
  .mouseleave(function(){
    $(this).stop().fadeTo(300, 1);
  })
  $(".erfolge a img").mouseenter(function(){
    $(this).stop().fadeTo(300, 0);
  })
  .mouseleave(function(){
    $(this).stop().fadeTo(300, 1);
  })
  $(".referenzen a img").mouseenter(function(){
    $(this).stop().fadeTo(300, 0);
  })
  .mouseleave(function(){
    $(this).stop().fadeTo(300, 1);
  })

  
  // Subnavi
  for(var i=1; i<5; i++) {
    // Vertikale ausrichtung
    $(".link-section"+i+" span").css('padding-top', ($(".link-section"+i).height() - $(".link-section"+i+" span").height())/2 + "px");

    $(".link-section"+i).mouseenter(function(){
      if($(this).attr("id").substr(2,1)!=subMenuActive) {
        $(this).stop().fadeTo(300, 1);
      }
    })
    .mouseleave(function(){
      if($(this).attr("id").substr(2,1)!=subMenuActive) {
        $(this).stop().fadeTo(300, 0.5);
      }
    })
    .click(function() {
      clickSubmenu($(this));
    })
      
  }

  // Wenn seite neu geladen => ersten Sub aktiv
  if(subMenuActive<1) {
    $(".link-section1").stop().fadeTo(300, 1);
    subMenuActive = 1
  }
  
	$.extend({
	  getUrlVars: function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
		  hash = hashes[i].split('=');
		  vars.push(hash[0]);
		  vars[hash[0]] = hash[1];
		}
		return vars;
	  },
	  getUrlVar: function(name){
		return $.getUrlVars()[name];
	  }
	});  
});

