$(document).ready(function(){
  
  /* Adding a class so that things can be styled specifically if JS is enabled */
  $('body').addClass('js');
  if ($("#player").length > 0) {
	flowplayer("player", "/fr/assets/flowplayer/flowplayer-3.1.5.swf",{
		key: '$53d36664f37d760229d',
		logo: null,
	  play: null,
	  clip : {
            autoPlay: false, 
            autoBuffering: true, 
    },
		plugins: { 
        controls: null
    },
    onLoad: function(){
      $('#play-movie').show();
    },
    onFinish: function(){
      $('#pause-movie').hide();
      $('#play-movie').show();
    }  
	});
  $('#play-movie').click(function(){
    $(this).hide();
    $f("player").play(); 
    $('#pause-movie').show();
    return false;
  });
  
  $('#pause-movie').click(function(){
    $(this).hide();
    $f("player").pause(); 
    $('#play-movie').show();
    return false;
  });
  }


  
  /* Flash banner JS */

    $('.home #banner, .einkaufszentrum #banner, .impressum #banner, .kontakt #banner, .aktuelles #banner').flash({
      swf: '/fr/assets/flash/LADENFLAECHEN_PRAXEN.swf', width: 966, height: 278
    });

  
  if ($('body').hasClass('ladenflaechen')) {
    var swfFile = "/fr/assets/flash/LADENFLAECHEN_PRAXEN.swf";
    if ($('#flaechen').length > 0) { swfFile = "/fr/assets/flash/LADENFLAECHEN_PRAXEN_static1.swf"; }
    if ($('#lage').length > 0) { swfFile = "/fr/assets/flash/LADENFLAECHEN_PRAXEN_static1.swf"; }
    $('.ladenflaechen #banner').flash({
      swf: swfFile, width: 966, height: 278
    });    
  }
  
  if ($('body').hasClass('praxisraeume')) {
    var swfFile = "/fr/assets/flash/PRAXEN_static.swf";
    if ($('#flaechen').length > 0) { swfFile = "/fr/assets/flash/PRAXEN_static.swf"; }
    if ($('#lage').length > 0) { swfFile = "/fr/assets/flash/PRAXEN_static.swf"; }
    $('.praxisraeume #banner').flash({
      swf: swfFile, width: 966, height: 278
    });    
  }
  

    $('.wohnungen #banner').flash({
      swf: '/fr/assets/flash/WOHNUNGEN.swf', width: 966, height: 278
    });

  

    $('.buroraume #banner').flash({
      swf: '/fr/assets/flash/BUEROS.swf', width: 966, height: 278
    });

  /* 
    GOOGLE MAPS
    gmaps_lat – A VALID LATITUDE VALUE IS EXPECTED
    gmaps_long – A VALID LONGITUDE VALUE IS EXPECTED
  */
  
  var gmaps_lat = "46.80128";
  var gmaps_long = "7.151764";
  
  if (typeof(GBrowserIsCompatible) == "function") {
    if (GBrowserIsCompatible()) {
      $('body').append('<div id="map-wrapper"><div id="map"></div></div>');
      var map = new GMap2(document.getElementById('map'));
      map.setCenter(new GLatLng(gmaps_lat, gmaps_long), 13);
      map.setUIToDefault();
      var latlng = new GLatLng(gmaps_lat, gmaps_long);
      map.addOverlay(new GMarker(latlng));
      $('#sidebar-map').css("display", "block");
    }
  
    /* Initialize the lightbox for the map. */
    if ($("#sidebar-map").length > 0) {
      $('#sidebar-map').colorbox({
        close: "Fermer", inline:true, href:"#map"
      });
    }
  }

  /* Initialize the lightbox for the sidebar gallery photos. */
  $('.gallery-group a').colorbox({
    close: "Fermez le diaporama",
    current: "{current}/{total}"
  });
  
  if ($("#sidebar-form").length > 0){
    $("#sidebar-form input[type=image]").click(function(){
      $("#sidebar-form .text").each(function(){
        if ($(this).val() == $(this).data("storedValue")) $(this).val('');
      });
    });
    
    /* 
      In the following, replace the word true with a string containing any message you wish to display.
      Example:
			  gesundheitsdienstleistung: {
  			  required: "This is a required field!"
  			},      
			
			if left as true, the output will result in "This field is required".
			You can also delete the entire line, if the field is not required. 
			
			
			You can also replace the "email: true" as above, supplying your own message for an invalid email.
			The default is: Please enter a valid email address.  
			
    */
    
      $('#sidebar-form').validate({
        rules: {
        			gesundheitsdienstleistung: {
                required: true, 
                minlength: 1, 
                maxlength: 100
        			},
        			grosse: {
        			  required: true, minlength: 1, maxlength: 100
        			},
        			email: {
        			  required: true, minlength: 1, maxlength: 100, email: true
        			}
        },
        onkeyup: false, 
        invalidHandler: function(e, validator) {
        			var errors = validator.numberOfInvalids();
        			if (errors) {
        			  $(this).find('div.error-message').remove();
        				var message = 'Bitte pr&uuml;fen Sie Ihre Eingabe';
        				$(this).find('.submit').after('<div class="error-message"><p>'+message+'</p></div>');
        			} else {
        				$("div.error-message").hide().remove();
        			}
        },     
        submitHandler: function() {
          $("div.error-message").hide().remove();
          $('#sidebar-form fieldset').fadeOut(function(){
            $('#sidebar-form #sidebar-success').fadeIn();
          });
          $(this).submit();
          return true;     
        },
    		errorPlacement: function(error, element) {} /* Resets the error placement, allowing the custom placement of just the required message. */
      });
    }
    
    $('#sidebar-success a').click(function(){
      $('#sidebar-success').fadeOut(function(){
        $(this).parents('form').find('fieldset').fadeIn();
      });
      return false;
    });

    if ($("#kontakt-form").length > 0){
      $("#anliegen").msDropDown();
      $('#kontakt-form').validate({
        rules: {
          anliegen: {
            required: true
          },
          name: {
            required: true, minlength: 1, maxlength: 100
          },
          firmenname: {
            required: true, minlength: 1, maxlength: 100
          },
          strasse: {
            required: true, minlength: 1, maxlength: 100
          },
          ort: {
            required: true, minlength: 1, maxlength: 100
          },
          telefon: {
            required: true, minlength: 1, maxlength: 100
          },
          telefon_private: {
            required: true, minlength: 1, maxlength: 100
          },
          email: {
            required: true, minlength: 1, maxlength: 100, email: true
          }
        },
        invalidHandler: function(e, validator) {
    			var errors = validator.numberOfInvalids();
    			if (errors) {
    				var message = 'Bitte pr&uuml;fen Sie Ihre Eingabe';
      			if (errors) {
      			  $(this).parent().find('div.error-message').remove();
      				var message = 'Bitte pr&uuml;fen Sie Ihre Eingabe';
      				$(this).after('<div class="error-message"><p>'+message+'</p></div>');
      			} else {
      				$("div.error-message").hide().remove();
      			}
    			} else {
    				$("div.error-message").hide().remove();
    			}
        },
        submitHandler: function() {
          $("div.error-message").hide().remove();
          $('#contact-success').fadeIn(function(){
            setTimeout(function(){
              $('#contact-success').fadeOut(1000);
            }, 3000);
          });    
          $(this).submit();
          return true;          
        },
        onkeyup: false,      
    		errorPlacement: function(error, element) {} /* Resets the error placement, allowing the custom placement of just the required message. */
      });
    }


    $('form').bind('submit', function() {
			$(this).ajaxSubmit();
			return false;
		});

  
  $('input').each(function(){
    if ($(this).attr('value') != "") $(this).data("storedValue", $(this).attr('value'));
    
    $(this)
      .focus(function(){ if ($(this).val() == $(this).data("storedValue")) $(this).val(""); })
      .blur(function(){ if ($(this).val() == "") $(this).val($(this).data("storedValue")); });
    
  });
  
});

function hasQuicktime(){
  var haveqt = false;
  if (navigator.plugins) {
  for (i=0; i < navigator.plugins.length; i++ ) {
  if (navigator.plugins[i].name.indexOf
  ("QuickTime") >= 0)
  { haveqt = true; }
  }
  }
  return haveqt;
}

