

$(document).ready(function() {

	
	var doBlink = function(obj,start,finish) { jQuery(obj).fadeOut(300).fadeIn(300); if(start!=finish) { start=start+1; doBlink(obj,start,finish); } } 	
	
	// Auf Änderungen des Landes reagieren
	$("#land").change(function(){
		var land=$(this).children('option:selected').val();
		var bundesland = 'x0';
        var bezirk = 'x0';
		$("#bundesland").load("/ajax/Land",{land: land });
		$("#bezirk").load("/ajax/Bundesland",{bundesland: bundesland }); 
        $("#ort").load("/ajax/Bezirk",{bezirk: bezirk });        
		doBlink("#bundesland",1,1);
		doBlink("#bezirk",1,1);
        doBlink("#ort",1,1);
		if(document.getElementById('objektart')){
			$("#objektart").load("/ajax/Objektart",{land: land, bundesland: bundesland });
			doBlink("#objektart",1,1);
		}
		
	});
	
	
	// auf Änderungen des Bundeslandes reagieren
    $("#bundesland").change(function(){
      var bundesland=$(this).children('option:selected').val();
      var bezirk = 'x0';
      $("#bezirk").load("/ajax/Bundesland",{bundesland: bundesland });
      doBlink("#bezirk",1,1);
      $("#ort").load("/ajax/Bezirk",{bezirk: bezirk });        
      doBlink("#ort",1,1);
      
      // Falls eine Objektart vorhanden ist
      if(document.getElementById('objektart')){
    	  $("#objektart").load("/ajax/Objektart",{bundesland: bundesland });
    	  doBlink("#objektart",1,1);
      }
      
    });
      	  
  	  // Auf Änderung des Bezirkes reagieren
  	  $("#bezirk").change(function(){
  		  var  bundesland = document.getElementById('bundesland').value;
      	  var land = document.getElementById('land').value;
  		  var bezirk=$(this).children('option:selected').val();

          if(document.getElementById('ort')){
              $("#ort").load("/ajax/Bezirk",{bezirk: bezirk});
              doBlink("#ort",1,1);
          }
  		  // Falls eine Objektart vorhanden ist
  	    if(document.getElementById('objektart')){
  		  $("#objektart").load("/ajax/Objektart",{land: land, bundesland: bundesland, bezirk: bezirk});
  		  
  		  doBlink("#objektart",1,1);
  	    }
  	  });

        // Auf Änderung des Ortes reagieren
        $("#ort").change(function(){
            var  bundesland = document.getElementById('bundesland').value;
            var land = document.getElementById('land').value;
            var bezirk=document.getElementById('bezirk').value;   
            var ort = $(this).children('option:selected').val();

            // Falls eine Objektart vorhanden ist
          if(document.getElementById('objektart')){
            $("#objektart").load("/ajax/Objektart",{land: land, bundesland: bundesland, bezirk: bezirk, ort:ort});
            
            doBlink("#objektart",1,1);
          }
        });  	  
// Suchprofile ########################################
  	  
  	// Auf Änderungen des Landes reagieren
  	$("#sp_land").change(function(){
  		var land=$(this).children('option:selected').val();
  		var bundesland = 'x0';
  		$("#sp_bundesland").load("/ajax/sp_Land",{land: land });
  		$("#sp_bezirk").load("/ajax/sp_clear");
  		$("#sp_ort").load("/ajax/sp_clear");
  		doBlink("#sp_bundesland",1,1);
  		doBlink("#sp_bezirk",1,1);
  		doBlink("#sp_ort",1,1);
  	});
  	
  	
  	// auf Änderungen des Bundeslandes reagieren
      $("#sp_bundesland").change(function(){
        var bundesland=$(this).children('option:selected').val();
        $("#sp_bezirk").load("/ajax/sp_Bundesland",{bundesland: bundesland });
        $("#sp_ort").load("/ajax/sp_clear");
  		doBlink("#sp_bezirk",1,1);
  		doBlink("#sp_ort",1,1);        
        
      });
        	  
    	  // Auf Änderung des Bezirkes reagieren
    	  $("#sp_bezirk").change(function(){
    		  var bezirk=$(this).children('option:selected').val();
    		  $("#sp_ort").load("/ajax/sp_bezirk",{bezirk: bezirk });
    	  		doBlink("#sp_ort",1,1);
    	  });
  	  
    	  
    	  $("a.suchprofilcreate").click(function(){
  	  		var url=$(this).attr('href')+"/js";
  	  		$.fn.colorbox({href:url,width:"460px", height:"480px", open:true, iframe:true});
  	  		return false;
  	  	  })     	  
  	  	  
  	  	  
  	  	  $("input.mailField").focus(function(){
  	  		if($(this).val()=='mail'){
  	  			$(this).val('');
  	  			$('#doggy').removeClass("head"); 
  	  			$('#doggy').addClass("headAktiv");
  	  		}
  	  		return false;
  	  	  })     	  

  	  	  $("input.mailField").blur(function(){
  	  		if($(this).val()==''){
  	  			$(this).val('mail');
  	  			$('#doggy').removeClass("headAktiv"); 
  	  			$('#doggy').addClass("head");  	  			
  	  		}
  	  		return false;
  	  	  })   	  	  
  	  	  

    	  // Auf Änderung des Bezirkes reagieren
    	  $("#orderby").change(function(){
    		  $("form:immoOrder").submit();
    		  return false;
    	  });  	  	  
  	  	  
// ###########################################################################
    	  
  	  $('a.DetailPageRight').click(function(){
  		  var seite = document.getElementById('seite').value;
  		  var last = document.getElementById('lastListPage').value;
  		  if(parseInt(seite) < parseInt(last)){
  			  var height = $("#immoDetailListObjects").height();  		
  			  	$("#immoDetailListObjects").height(height);  		  
  			  	$("#immoDetailListObjects").empty().html('<img src="/images/loading.gif" class="AjaxLoading"/>');
  			  	$("#immoDetailListObjects").load("/ajax/Objektlist",{seite: seite, direction: 'right'});
  		  }
  		
  	  })

  	  $('a.DetailPageLeft').click(function(){
  		  		
  		  var seite = document.getElementById('seite').value;
  		  if(parseInt(seite) > 1){
  			  var height = $("#immoDetailListObjects").height();  		
  		  		$("#immoDetailListObjects").height(height);
  		  		$("#immoDetailListObjects").empty().html('<img src="/images/loading.gif" class="AjaxLoading"/>');
  		  		$("#immoDetailListObjects").load("/ajax/Objektlist",{seite: seite, direction: 'left'});
  		  }
  		
  	  })
  	  
  	  $('a.DetailProjektPageRight').click(function(){
  		  var seite = document.getElementById('seite').value;
  		  var last = document.getElementById('lastListPage').value;
  		  
  		  if(parseInt(seite) < parseInt(last)){
  			  var height = $("#projektDetailListObjects").height();  		
  			  	$("#projektDetailListObjects").height(height);  		  
  			  	$("#projektDetailListObjects").empty().html('<img src="/images/loading.gif" class="AjaxLoading"/>');
  			  	$("#projektDetailListObjects").load("/ajax/Projektlist",{seite: seite, direction: 'right'});
  		  }
  		
  	  })

  	  $('a.DetailProjektPageLeft').click(function(){
  		  		
  		  var seite = document.getElementById('seite').value;
  		  if(parseInt(seite) > 1){
  			  var height = $("#projektDetailListObjects").height();  		
  		  		$("#projektDetailListObjects").height(height);
  		  		$("#projektDetailListObjects").empty().html('<img src="/images/loading.gif" class="AjaxLoading"/>');
  		  		$("#projektDetailListObjects").load("/ajax/Projektlist",{seite: seite, direction: 'left'});
  		  }
  		
  	  })  
  	  
  	  $('div.immoDetailListCountWrapper').find('a').click(function(){
  		var perPage = $(this).html();
  		var height = 120;
  		var multi = Math.floor(perPage/5);
  		if(multi>0){
  			height = multi * 120;
  		}
  			$("#immoDetailListObjects").height(height);  		  
  			$("#immoDetailListObjects").empty().html('<img src="/images/loading.gif" class="AjaxLoading"/>');
  			$("#immoDetailListObjects").load("/ajax/Objektlist",{perPage: perPage});
  	  })

  	  $('div.projektDetailListCountWrapper').find('a').click(function(){
  		var perPage = $(this).html();
  		var height = 120;
  		var multi = Math.floor(perPage/5);
  		if(multi>0){
  			height = multi * 120;
  		}
  			$("#projektDetailListObjects").height(height);  		  
  			$("#projektDetailListObjects").empty().html('<img src="/images/loading.gif" class="AjaxLoading"/>');
  			$("#projektDetailListObjects").load("/ajax/Projektlist",{perPage: perPage});
  	  })  	  
  	  
  	  $("a.empfehlen").click(function(){
  		var url=$(this).attr('href')+"/js";
  		$.fn.colorbox({href:url,width:"420px", height:"410px", open:true, iframe:true});
  		return false;
  	  })
  	  
  	  $("a.kontakt").click(function(){
  		var url=$(this).attr('href')+"/js";
  		$.fn.colorbox({href:url,width:"750px", height:"570px", open:true, iframe:true});
  		return false;
  	  })
	  
  	  $("a.interesse").click(function(){
  		var url=$(this).attr('href')+"/js";
  		$.fn.colorbox({href:url,width:"750px", height:"570px", open:true, iframe:true});
  		return false;
  	  })  	  
  	  $("a.merken").click(function(){
  		var url=$(this).attr('href')+"/js";
  		$.fn.colorbox({href:url,width:"420px", height:"350px", open:true, iframe:true});
  		return false;
  	  })  	  

  	  $("a.drucken").click(function(){
  		  window.open(this.href,'drucken','width=600,height=600,scrollbars=yes');
  		
  		return false;
  	  })    	  
  	  
  	  $("a[rel=\'lostpwForm\']").click(function(){
  		var url=$(this).attr('href')+"/js";
  		$.fn.colorbox({href:url,width:"420px", height:"350px", open:true, iframe:true});
  		return false;
  	  })
  	  
  	  $("a[rel=\'registerForm\']").click(function(){
  		var url=$(this).attr('href')+"/js";
  		$.fn.colorbox({href:url,width:"420px", height:"350px", open:true, iframe:true});
  		return false;
  	  })
  	  
 		
  }); 




	
