var aktuelleID;
var alterBereich;
var neucust;

    var floatname = "#upfloat";
    var menuYloc = null;




menuename = new Array();
menuename[0] = "#newnav4";
menuename[1] = "#newnav42";
menuename[2] = "#newnav43";



$(document).ready(function()
	{

	$('body').append('<div id="upfloat"><img src="/img/nachoben.gif"></div>');

	$('#upfloat').click(function(){
		
                    $('body, html').stop().animate({
                        scrollTop: 0
                    },1000);
		}
		);

//	window.onhashchange = hashChanged;
        menuYloc = parseInt($(floatname).css("top").substring(0,$(floatname).css("top").indexOf("px")))
        $(window).scroll(function () {
            var offset = menuYloc+$(document).scrollTop()+"px";
            $(floatname).animate({top:offset},{duration:500,queue:false});
});
	$(window).bind('hashchange', function(e) {
	var hash = window.location.hash.replace("#i","");
	hash = hash.replace("#b","");
	var art = window.location.hash.substr(1, 1);
	if (art == 'b')
	{
	$('#upfloat').hide();
      neucust = '';
      var neuerBereich = hash;
      if (neuerBereich != aktuellerBereich)
        {
        $("#cstfull").fadeOut(200,function()
        {
        $("#cstfull").html('');

        $(".cstnw").fadeIn(200);
		$('#upfloat').hide();        
        alterBereich = aktuellerBereich;
        aktuellerBereich = neuerBereich;
        $(".twrp" + (alterBereich+1)).hide(200);
        

        if(aktuellerBereich == '2')
          {
//          window.location.hash = 'b2';
          jQuery.bbq.pushState('#b2');
          $(".img0").animate({marginTop:-454});
          $(".img1").animate({marginTop:0},function()
          {
          $(".twrp" + (aktuellerBereich+1)).show(200);

          });
          }
        else if(aktuellerBereich == '1')
          {
          // window.location.hash = 'b1';
          jQuery.bbq.pushState('#b1');
          $(".img1").animate({marginTop:-227});
          $(".img0").animate({marginTop:-227},function()
          {
          $(".twrp" + (aktuellerBereich+1)).show(200);

          });
          
          }
        else if(aktuellerBereich == '0')
          {
          jQuery.bbq.pushState('#b0');
          // window.location.hash = 'b0';
          $(".img1").animate({'marginTop':'-454px'});
          $(".img0").animate({'marginTop':'0px'},function()
          {
          $(".twrp" + (aktuellerBereich+1)).show(200);

          });

          }


        });
        }
      else
        {
        $("#cstfull").fadeOut(200,function()
        {$("#cstfull").html('');
        $(".cstnw").fadeIn(200);
        	$('#upfloat').hide();
        });
        }
      $("#newnav4").scrollTop(0);
      $("#newnav42").scrollTop(0);
      $("#newnav43").scrollTop(0);
      $("select[name=e4]").hide(500); 
		}
	else
	if (art == 'i')
	{
	$('#upfloat').show();
	if(aktuellerBereich == 2)
		{
		$("#newnav43").show(500);
		}
	else if(aktuellerBereich == 1)
		{
		$("#newnav42").show(500);
		}
	else
		{
		$("#newnav4").show(500);
		}
	
	if (hash != neucust)
		{
//		if($("#cstfull").is(":visible"))
//			{
		neucust = hash;

		var data = 'i=' + neucust;

	jQuery.bbq.pushState('#i'+neucust);
		
	$(".cstnw").fadeOut(500);
		$("#cstfull").fadeOut(300,function()
		{
		  //Request abschicken
		  $.ajax({
			url: "/misc/referenz/",
			type: "POST",
			data: data,
			success: function (reqCode) {
				if (reqCode!='') {
			$("#cstfull").html(reqCode);

            // $("#cstfull").fadeIn(300);
			$('#upfloat').show();
            if(jQuery.browser.msie)
            	{
            	$("#cstfull").show();
            	}
			else
            	{
            	$("#cstfull").fadeIn(300);
            	}
			
			$("#cstfull .referenzen .bildbereich img").click(function()
				{
				if ($(this).width() > 634)
					{
					$(this).stop();
					$(this).animate({width:'634px'});
					}
				else
					{
					$(this).animate({width:'957px'});
					}
				
				
				});

				}
				else
				{
				if (neucust != '--')
					{
					// alert('Keine Verbindung zum Referenzserver.');
					}
				}
			}
		});
		});
			
//			}
	
		}
	}
	
	});

	$('.smallnews a').click(function() {
	if ($(this).attr("class") == "small" || $(this).find("img").attr("class") == "newsimg")
	{
	if ($(this).parent().attr("class") == "sntext")
		{
		jetztid = $(this).parent().parent().attr("id");
		}
	else
		{
		jetztid = $(this).parent().attr("id");
		}
	bigid = jetztid.replace("n","b");
	$('#' + jetztid + ' .sntext').slideUp(function() 
		{

	$('#' + bigid).slideDown(function() 
		{
		});
		});

//	alert(bigid);
	return false;
}
	});
	
//	$('#newnav3 option').live('change',function()

	$('.newnav4').change(function()
		{
		
		neucust = $(this).val();
		
		
//		alert($(this).parent().attr("id")+ " " + $(this).attr("id")+ " " + $(this).val());
//		alert(neucust);
//		$(".newnav4 option[value=--]").remove();
		$(".newnav4 option[value=--]").html("");
		
		var data = 'i=' + neucust;

	jQuery.bbq.pushState('#i'+neucust);
		
	$(".cstnw").fadeOut(500);
		$("#cstfull").fadeOut(300,function()
		{
		  //Request abschicken
		  $.ajax({
			url: "/misc/referenz/",
			type: "POST",
			data: data,
			success: function (reqCode) {
				if (reqCode!='') {
			$("#cstfull").html(reqCode);

            // $("#cstfull").fadeIn(300);
            	$('#upfloat').show();
            if(jQuery.browser.msie)
            	{
            	$("#cstfull").show();
            	}
			else
            	{
            	$("#cstfull").fadeIn(300);
            	}
			
			$("#cstfull .referenzen .bildbereich img").click(function()
				{
				if ($(this).width() > 634)
					{
					$(this).stop();
					$(this).animate({width:'634px'});
					}
				else
					{
					$(this).animate({width:'957px'});
					}
				
				
				});

				}
				else
				{
				alert('Keine Verbindung zum Referenzserver.');
				}
			}
		});
		});

		
		});

	$('#newnav3').click(function()
		{
		if ($('#newnav4').length > 0)
			{
			if ($('#newnav3').val() == 'referenzen-arbeitsbeispiele-nach aufgaben')
				{
				var neuerBereich = 1;
				}
			else if ($('#newnav3').val() == 'referenzen-arbeitsbeispiele-nach datum')
				{
				var neuerBereich = 2;
				}
			else
				{
				var neuerBereich = 0;
				}
			if (neuerBereich != aktuellerBereich)
				{
				$("#cstfull").fadeOut(200,function()
				{
				$("#cstfull").html('');

				$(".cstnw").fadeIn(200);
					$('#upfloat').hide();
				alterBereich = aktuellerBereich;
				aktuellerBereich = neuerBereich;
				$(".twrp" + (alterBereich+1)).hide(200);
				

				if(aktuellerBereich == '2')
					{
// 					window.location.hash = 'b2';
					jQuery.bbq.pushState('#b2');
					$(".img0").animate({marginTop:-454});
					$(".img1").animate({marginTop:0},function()
					{
					$(".twrp" + (aktuellerBereich+1)).show(200);

					});
					}
				else if(aktuellerBereich == '1')
					{
					// window.location.hash = 'b1';
					jQuery.bbq.pushState('#b1');
					$(".img1").animate({marginTop:-227});
					$(".img0").animate({marginTop:-227},function()
					{
					$(".twrp" + (aktuellerBereich+1)).show(200);

					});
					
					}
				else if(aktuellerBereich == '0')
					{
					jQuery.bbq.pushState('#b0');
					// window.location.hash = 'b0';
					$(".img1").animate({'marginTop':'-454px'});
					$(".img0").animate({'marginTop':'0px'},function()
					{
					$(".twrp" + (aktuellerBereich+1)).show(200);

					});

					}

//				$(".twrp" + (aktuellerBereich+1)).fadeTo(1,.01,function()

/*
				$("select[name=e4]").not("#"+menuename[aktuellerBereich]).hide(500,function()
				{
				if(aktuellerBereich == '0')
					{
					$("#newnav4").show(500);
					}
				else if(aktuellerBereich == '1')
					{
					$("#newnav42").show(500);
					}
				else if(aktuellerBereich == '2')
					{
					$("#newnav43").show(500);
					}
					});
					*/
				});
				}
			else
				{
				$("#cstfull").fadeOut(200,function()
				{$("#cstfull").html('');
				$(".cstnw").fadeIn(200);
					$('#upfloat').hide();
				});
				}
			$("#newnav4").scrollTop(0);
			$("#newnav42").scrollTop(0);
			$("#newnav43").scrollTop(0);
			$("select[name=e4]").hide(500);	

			}
			else
			{
			if ($(this).val() != "" && $(this).val() != "-" && $(this).val() != "--")
				{
				window.location.href = $(this).val();
				}
			
			}
			}
);
		
$('.totalwrap').live('click',function()		
	{
	neucust = $(this).attr('id').replace("cust","");
	
		
	
	
	if(aktuellerBereich == 2)
		{
		neucust = datum[neucust];
		$("#newnav43").show(500);
		}
	else if(aktuellerBereich == 1)
		{
		neucust = aufgabe[neucust];
		$("#newnav42").show(500);
		}
	else
		{
		$("#newnav4").show(500);
		}

		$("#newnav43").val(neucust);
		$("#newnav42").val(neucust);
		$("#newnav4").val(neucust);
	
	
	$(".cstnw").fadeOut(500);
	
//	$("#cstfull").html('<img src="/img/ladebild.gif" />');
//		alert("/misc/referenz/?i="+neucust);

var data = 'i=' + neucust;
 	jQuery.bbq.pushState('#i'+neucust);
  //Request abschicken
  $.ajax({
	url: "/misc/referenz/",
	type: "POST",
	data: data,
 	success: function (reqCode) {
		if (reqCode!='') {
	$("#cstfull").html(reqCode);
                    $('body, html').stop().animate({
                        scrollTop: 0
                    }, 1000,function()
                    {
            if(jQuery.browser.msie)
            	{
            	$("#cstfull").show();
            	}
			else
            	{
			    $("#cstfull").show(500);

            	}

                    });
	
	
	$("#cstfull .referenzen .bildbereich img").click(function()
		{
		if ($(this).width() > 634)
			{
			$(this).stop();
			$(this).animate({width:'634px'});
			}
		else
			{
			$(this).animate({width:'957px'});
			}
		});
    
		}
		else
		{
        alert('Keine Verbindung zum Referenzserver.');
        }
	}
});

	});
  
		
	function nav3wechsel(verzeichnis)
		{
		
		}
	
	function nav4wechsel(kunde)
		{
		
		}
	});
	
	

