$(document).ready(function(){

  /* Panel Startseite */
  if($('#bg_slide')[0]){
    var lastitem = 1;
    $('#tn_0').mouseenter(function(){$('#bg_slide').cycle(0).cycle('pause');});
    $('#tn_1').mouseenter(function(){$('#bg_slide').cycle(1).cycle('pause');});
    $('#tn_2').mouseenter(function(){$('#bg_slide').cycle(2).cycle('pause');});
    $('#tn_3').mouseenter(function(){$('#bg_slide').cycle(3).cycle('pause');});
    $('#tn_4').mouseenter(function(){$('#bg_slide').cycle(4).cycle('pause');});
/*     $('#panel2').hide(); */
    function onBefore(){
      $('#tn_' + this.alt).addClass('tn_active');
      $('#tn_' + lastitem).removeClass('tn_active');
      lastitem = this.alt;
      var margin = this.alt*350;
      $('#panel > ol').animate({marginLeft:"-"+margin},750);}; 
    function onAfter(){};      
    $('#bg_slide').cycle({delay:1000,speed:1750,timeout: 7500,before:onBefore,after:onAfter}); 
    var height = $(window).height();
    var width = $(window).width();  
    $('#bg_slide1').attr('width',width);
    $('#bg_slide1').attr('height',width / 1100 * 900);
    $('#bg_slide2').attr('width',width);
    $('#bg_slide2').attr('height',width / 1100 * 900);
    $('#bg_slide3').attr('width',width);
    $('#bg_slide3').attr('height',width / 1100 * 900);
    $('#bg_slide4').attr('width',width);
    $('#bg_slide4').attr('height',width / 1100 * 900);    
    $('#bg_slide5').attr('width',width);
    $('#bg_slide5').attr('height',width / 1100 * 900);    
    if(height<500){
     $('#teaser_home_panel').css('margin-top','30px');
     $('#teaser_home').css('height','200px');}
    else if(height<600){
     $('#teaser_home_panel').css('margin-top','40px');
     $('#teaser_home').css('height','240px');}
    else if(height<700){
     $('#teaser_home_panel').css('margin-top','60px');
     $('#teaser_home').css('height','260px');}
    else if(height<800){
     $('#teaser_home').css('height','340px');}
    else if(height<900){
     $('#teaser_home').css('height','440px');}
    else if(height>=900){
     $('#teaser_home_panel').css('margin-top','120px');
     $('#teaser_home').css('height','500px');}
    $(window).resize(function(){
      window.location = location;});}


  /* Slideshow */
  if($('.slideshow')[0]){
    $('.slideshow').cycle({ fx: 'fade', timeout: 7500 });}

  
  /* Google Maps API */
  var m = $("#map")[0];  
  if (m) {  
    if (GBrowserIsCompatible()) {
      var map = new GMap2(m);
      var point = new GLatLng(latitude,longitude);
      map.setCenter(point, zoomLevel);      
      var extLargeMapControl = new ExtLargeMapControl();
      map.addControl(extLargeMapControl);
      var mgr = new MarkerManager(map);
  	  var batch = [];
      for (var i = 0; i < markers.length; i++){
  	    var point = new GLatLng(parseFloat(markers[i]['latitude']), parseFloat(markers[i]["longitude"]));
        batch[i] = new GMarker(point,{title:markers[i]['name']});
        GEvent.addListener(batch[i],'click',function(){
          map.panTo(this.getPoint());
          marker_action(this.getTitle());
        });}
      mgr.addMarkers(batch,removeLevel);
      mgr.refresh();}
    function marker_action(id){
      if(locChange){
        window.location =  $("#map").attr('title') + '#' + id; }
      $("#mapupdate").load(updateUrl + id);}
    $('#maplist table tr').click(function(){
      marker_action($(this).attr('id'));
      var pointupdate = new GLatLng(parseFloat($('#' + $(this).attr('id') + ' > .lat').text()),parseFloat($('#' + $(this).attr('id') + ' > .lng').text()));
      map.panTo(pointupdate);});}  

});
