/*
  JS Grundfunktionen | © 2009 by aparthotel-am-sonnenhuegel.de
____________________________________________ */

$(document).ready(function(){

	$.fn.SonnenhuegelScripts = function(settings) {
		settings = jQuery.extend( {

      setupAnimationsZeit: '500' // Durschnittliche Zeit aller Animationen

  	},settings);

    // Activate Slider after loading
  	$("#slider").easySlider({
  		auto: true,
  		continuous: true,
  		vertical: true,
  		speed: 1000,
      pause: 2500
  	});
  	
    // Build Slider and Aside
    if ( $("#aside").length > 0 ) {

      if ( $("#slider img").length > 0 ) {
        var firstImgSrc = $("#slider img:first").attr('src');
        var firstImgTitle = $("#slider img:first").attr('alt');
        $("#aside").html('<img src="'+firstImgSrc+'" alt="'+firstImgTitle+'" title="'+firstImgTitle+'" />');
      };

    	$("#hover_gallery img").hover(function () {
        var sliderImgSrc = $(this).attr('src');
        var sliderImgTitle = $(this).attr('alt');
        $("#aside").html('<img src="'+sliderImgSrc+'" alt="'+sliderImgTitle+'" title="'+sliderImgTitle+'" />');
      }, function() {
        return false;
      });

    };

    function animateVirtualView() {
      setTimeout( function() {
      
        $("#virtual_view").css('color', '#f00');
        setTimeout( function() {
        
          $("#virtual_view").css('color', '#FFE19D');
          setTimeout( function() {

            $("#virtual_view").css('color', '#f00');
            setTimeout( function() {

              $("#virtual_view").css('color', '#FFE19D');
              animateVirtualView();

            }, 150);
          }, 150);
        }, 150);
      }, 3500);
    }
    animateVirtualView();

    // Set Table-Background
    if ( $("table").length > 0 ) {
    
      $("table tr:nth-child(even)").css({background: '#F6B759'});
    
    };
  	
  	// Opens Virtual-View-Overlay
    $("#virtual_view").click(function(){
      $("#ajaxshell, #ajaxcontainer").fadeIn('fast');
    });

  	// Closes Virtual-View-Overlay
    $("#ajaxcontainer").click(function(){
      $("#ajaxshell, #ajaxcontainer").fadeOut('fast');
    });
    
// --------------------- KONTAKTFORMULAR --------------------------

    // contactform | INPUT, TEXTAREA - Toggle Value on click and check content on blur
    jQuery.fn.DefaultValue = function(text){
      return this.each(function(){
      	// Make sure we're dealing with text-based form fields
      	if(this.type != 'text' && this.type != 'password' && this.type != 'textarea') {
      		return;
        }

      	// Store field reference
      	var fld_current=this;

      	// Set value initially if none are specified
            if(this.value=='') {
      		this.value=text;
      	} else {
      		// Other value exists - ignore
      		return;
      	}

      	// Remove values on focus
      	$(this).focus(function() {
      		if(this.value==text || this.value=='')
      			this.value='';
      	});

      	// Place values back on blur
      	$(this).blur(function() {
      		if(this.value==text || this.value=='')
      			this.value=text;
      	});

      	// Capture parent form submission
      	// Remove field values that are still default
      	$(this).parents("form").each(function() {
      		// Bind parent form submit
      		$(this).submit(function() {
      			if(fld_current.value==text) {
      				fld_current.value='';
      			}
      		});
      	});
      });
    };

    // contactform | VALUE - Set Text
  	$("#name, #vorname, #mail, #strasse").DefaultValue("(Pflichtfeld)");
  	$("#ort").DefaultValue("(Beides Pflichtfelder)");
  	$("#nachricht").DefaultValue("Ihre Nachricht ...");

	};

  // Activate SonnenhuegelScripts if HTML is ready
  $("html").SonnenhuegelScripts();

});

