var curr_image;
var scrolling = false;
var tmpcounter = 2;
var newsid = 0;
function nextNews()
{
  newsid++;
	$("#news_text").fadeOut('slow', function() {
		$('#news_text').load('/news_balken.php?news='+newsid+'&lang='+$('#news_sprache').html(), function() {
			$("#news_text").fadeIn('slow', function() {
				setTimeout("nextNews()",5000);
				
			});
		});	
	});
}
$(document).ready(function()
{ 
	setTimeout("nextNews()",5000);
  var preloaded_image_a = $('<img />').attr('src', '/images/header_menu/search_button_s.png');
  var preloaded_image_b = $('<img />').attr('src', '/images/header_menu/search_corner_s.png');
  var preloaded_image_c = $('<img />').attr('src', '/images/header_menu/search_input_s.png');
  check_scrolling();
  $(".paragraph").corner("6px");
  $(".events_paragraph").corner("6px");
  var ie6od5 = false;
  jQuery.each(jQuery.browser, function(i, val) {
    if(i=="msie" && jQuery.browser.version.substr(0,1)<7)
      ie6od5 = true;
  });
  //#header_menu
  $("#header_menu ul li:not(.search)").mouseenter(function() {
      $(this).addClass("hover");
  })
  .mouseleave(function() {
      if(!$(this).hasClass("active")) {
        $(this).removeClass("hover");
      }
  });
  $('#header_menu ul li').hover(
			function() { $('ul', this).css('display', 'block'); },
			function() { $('ul', this).css('display', 'none'); }
  );

      
    
  $("#header_menu ul:not(.top_sub_menu) li:not(.first) a").click(function(){
    $("#header_menu ul li:not(.search,.top_sub_menu)").each(function(){
      $(this).removeClass("active");
      $(this).removeClass("hover");
      $(this).children('a').children('img').attr("src",
        $(this).children('a').children('img').attr("src").replace('_w.png', '_s.png'));
    });
    $(this).parent().addClass("active");
    $(this).children('img').attr("src",$(this).children('img').attr("src").replace('_s.png', '_w.png'));
  });
  
  $("#header_menu ul li input:text").focus(function(){
    if($(this).attr("value")==$(this).attr("alt"))
    {
      $(this).attr("value","");
      $(this).css("color","#8a8a8a");
			$(this).css("background-image","url('/images/header_menu/search_input_s.png')");	
			$(this).parent().children("img").attr("src","/images/header_menu/search_corner_s.png");
			$(this).parent().children(".search_submit").css("background-image","url('/images/header_menu/search_button_s.png')");		
			
    }
  })
  .blur(function(){
    if($(this).attr("value")=="")
    {
      $(this).attr("value",$(this).attr("alt"));
      $(this).css("color","#999");
		  $(this).css("background-image","url('/images/header_menu/search_input.png')");
			$(this).parent().children("img").attr("src","/images/header_menu/search_corner.png");
			$(this).parent().children(".search_submit").css("background-image","url('/images/header_menu/search_button.png')");
		}
  });  
  //#side_menu  
  $("#side_menu ul:not(.side_sub_menu)").children("li").children("a").mouseenter(function() {
      $(this).addClass("hover");
			if ($(this).hasClass('first')) {
				$(this).addClass("iefirsthover");
			}			
  })
  .mouseleave(function() {
      if(!$(this).hasClass("active")) {
        $(this).removeClass("hover");
				if ($(this).hasClass('first')) {
					$(this).removeClass("iefirsthover");
				}			
      }
  });
  
  $(".imagelink").mouseenter(function() {
      var image_number = $(this).attr("class").split(" ")[1];
      var image = $(this).parent().parent().parent().parent().parent().parent().children(".images").children("img."+image_number);
      curr_image = image;
      curr_image_src = image.attr("src");
      image.attr("src",image.attr("src").replace('.jpg', "_"+$(this).attr("id")+".jpg"));
  })
  .mouseleave(function() {
    curr_image.attr("src",curr_image_src);
  });
  
  $("#test").mouseenter(function() {
      $(this).attr("src","/images/produkte/bild_kl_1.jpg");
      $(this).attr("src",$(this).attr("src").replace('.jpg', '_1.png'));
  })
  .mouseleave(function() {
      $(this).attr("src","/images/produkte/bild_kl.jpg");
  });
  
  $("#test2").mouseenter(function() {
      $(this).attr("src","/images/produkte/bild_kl_2.jpg").fadeIn('slow');
  })
  .mouseleave(function() {
      $(this).attr("src","/images/produkte/bild_kl.jpg");
  });  
  $("#side_menu ul:not(.side_sub_menu)").children("li").children("a").click(function(){
    $("#side_menu ul:not(.side_sub_menu)").children("li").children("a").each(function(){
      $(this).removeClass("active");
      $(this).removeClass("hover");
			if ($(this).hasClass('first')) {
				$(this).removeClass("iefirstactive");
		}			
      $(this).parent().children("ul").css("display","none");
    });
		if ($(this).hasClass('first')) {
			$(this).addClass("iefirstactive");
		}				
    $(this).addClass("active");
    $(this).parent().children("ul").css("display","inline");
    if($(this).attr("href")=="#")
    {
      return false;
    }
		//$("#content").css("min-height",($("#side_menu").height()+20)+"px");		
  });  
  
  
  $("ul.side_sub_menu li a").mouseenter(function() {
      $(this).addClass("hover");
  })
  .mouseleave(function() {
      if(!$(this).hasClass("active")) {
        $(this).removeClass("hover");
      }
  });
  
  $("ul.side_sub_menu li a").click(function(){
    $("ul.side_sub_menu li a").each(function(){
      $(this).removeClass("active");
      $(this).removeClass("hover");
    });
    $(this).addClass("active");
  });  
  
  $(".car a").click(function(){
    return true; //gleich dem link folgen.
    $(".car a").each(function(){
      $(this).removeClass("active");
      $(this).parent().css("display","none");
    });
    $(this).parent().css("display","inline");
    $(this).addClass("active");

    $(this).parent().parent().children(".farben").css("display","inline");
    
    /*$("#btn_fzg a").html($(this).children("img").attr("title"));*/
    /*tb_remove();*/
    return false;
  });
  
  $(".farbe a").click(function(){
    $(".farbe a").each(function(){
      $(this).removeClass("active");
    });
    $(this).addClass("active");
    $("#btn_fzg a").html($(this).parent().parent().parent().children(".car").children("a").children("img").attr("title")+" / "+$(this).children("img").attr("title"));
    tb_remove();
    return false;
  });  
  function check_scrolling()
  {
    if(($(window).height()-($("#header").height()+5+5+$("#side_menu").height()+5+10+10+5+20))>0&&$(window).width()>1000)
    {
      //alert("gross genug");
      scrolling = true;
      $(".backbutton").css("display","none");
    }
    else
    {
      //alert("zu klein");
      scrolling = false;
      $(".backbutton").css("display","block");
    }
  }
  function scrollstopp()
  {
    if(!ie6od5)
    {
      check_scrolling();
      if(scrolling)
      {
        $("#header").addClass("scrolled");
        $("#main").addClass("scrolled");
      }
      else
      {
        $("#header").removeClass("scrolled");
        $("#main").removeClass("scrolled");
      }
      if($(window).scrollTop()<317 || !scrolling) { 
        $("#side_menu").removeClass("scrolled");
        $("#content_title_bg").removeClass("scrolled");
        $("#content").removeClass("scrolled");
        $("#footer").removeClass("scrolled");
      }
      else {
        $("#side_menu").addClass("scrolled");
        $("#content_title_bg").addClass("scrolled");
        $("#content").addClass("scrolled");
        $("#footer").addClass("scrolled");
      }
    }
  }
  $(window).scroll(function(){
    scrollstopp();
  });
  $(window).resize(function() {
    var vorher = scrolling;
    var vorher_scrollpos = $(window).scrollTop();
    scrollstopp();
    if(vorher!=scrolling)
    {
      $(window).scrollTop(vorher_scrollpos);
    }
  });
});
