/*
  JS Grundfunktionen | © 2009 by agentur-lanzinger.de
------------------------------------ */

$(document).ready(function(){

	$.fn.agenturLanzingerScripts = function(settings) {

    // .nav1_n, .nav1_h, .nav2_n, .nav2_h | ADD - Add pipes
    $(".nav_pipe").css('opacity', '0.0');
    $("#navi_left span.nav_pipe:eq(0), #navi_right span.nav_pipe:last, .copyright_right span.nav_pipe:last").css('display', 'none');

    // ONLOAD - Build layout
    setTimeout( function() {
      // #navi_left, #navi_right | SLIDE - Slide and fade in
      $("#navi_left").show('drop', { direction: 'right' }, 500);
      $("#navi_right").show('drop', { direction: 'left' }, 500);
      setTimeout( function() {
        // .nav_pipe | FADE - Fade in
        $(".nav_pipe").fadeTo('200', 1.0);
      }, 500);
      setTimeout( function() {
        // #navigation_left, #content | SLIDE - Slide and fade in
        $("#navigation_left").show('drop', { direction: 'right' }, 500);
        $("#stripe_left, #stripe_right").stop()
            .animate({width: '0'}, 500);
        setTimeout( function() {
          // #navigation_left, #content | SLIDE - Slide and fade in
          $("#content, #home_news").show('drop', { direction: 'left' }, 500);
        }, 500);
      }, 700);
    }, 500 * 2);

  	// #navigation_left | BACKGROUND - Animate background
    $(".nav_3_n").hover(
      function () {
    		$(this).stop().animate({
    			width: '352px',
    			height: '87px',
    			paddingLeft: '32px',
    			backgroundPosition: '(0 0)'
        }, '100');
      },
      function() {
    		$(this).stop().animate({
    			width: '320px',
    			height: '21px',
    			paddingLeft: '16px',
    			backgroundPosition: '(320px 0)'
    		}, '100');
    	}
    );

  	// #contactform | BACKGROUND - Animate background
    $(".input_text, .textarea").focus(function(){
      $(this).effect("highlight", {color: '#C50C1F'}, 500);
  	    }, function() {
      return 0;
  	});

  	// #bottom p | OPACITY - Change transparency
  	$("#bottom div").css('opacity', '0.4');
    $("#bottom div").hover(
      function () {
    		$(this).css('opacity', '1.0');
      },
      function() {
    		$(this).css('opacity', '0.4');
    	}
    );

  	// .projects_right, .p_link | OPACITY - Set transparency
    $(".projects_right, .p_link").css('opacity', '0.0');

  	// .projects_left | OPACITY - Change transparency
    $(".projects_left").hover(
      function () {
      	$(this).nextAll(".projects_right:eq(0)").css('opacity', '1.0');
      	$(this).find(".p_link").css('opacity', '1.0');
      },
      function() {
    		$(this).nextAll(".projects_right:eq(0)").css('opacity', '0.0');
      	$(this).find(".p_link").css('opacity', '0.0');
    	}
    );

  	// .clients_right | OPACITY - Set transparency
    $(".clients_right").css('opacity', '0.0');

  	// .clients_left | OPACITY - Change transparency
    $(".clients_left").hover(
      function () {
      	$(this).nextAll(".clients_right:eq(0)").css('opacity', '1.0');
      },
      function() {
    		$(this).nextAll(".clients_right:eq(0)").css('opacity', '0.0');
    	}
    );

    // contactform | CHECKBOX - Replace images
    $(".art_anfrage").click().toggle(function(){
  		$(this).css({background: 'url(user/pix/capture_contact_h.gif) no-repeat 0 2px #4b4b4d'});
      $(this).prev().attr('checked', 'checked');
  	}, function() {
  		$(this).css({background: 'url(user/pix/capture_contact_n.gif) no-repeat 0 2px #4b4b4d'});
      $(this).prev().attr('checked', '');
  	});

    // 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").DefaultValue("Name (benötigt)");
  	$("#vorname").DefaultValue("Vorname (benötigt)");
  	$("#firma").DefaultValue("Firma");
  	$("#tel").DefaultValue("Telefon");
  	$("#mail").DefaultValue("e-Mail (benötigt)");
  	$("#nachricht").DefaultValue("Ihre Nachricht ...");

// --------------------- Referenzen Overlay -------------------------

    if($(".rf_open").length) {

      $("#rf_bg").css('opacity', '0.7');

      $(".rf_open").click(function() {

        $("#rf_bg, #rf_overlay").fadeIn(750);

      });

      $("#rf_overlay, #ref_closebutton").click( function() {
        $("#rf_bg, #rf_overlay").fadeOut(750);
      });

      $("#rf_references").click( function() {
        return false;
      });
    
    };
    
// -------------------------- Fragebogen ----------------------------

    if($("#qn_bg").length) {

      $("#qn_bg").css('opacity', '0.7');

      $(".qn_open").click(function() {

        $("#qn_bg, #qn_overlay").fadeIn(750);
        $('<iframe id="qn_frame" src="http://www.agentur-lanzinger.de/questionnaire/index.php" width="817" height="100%" align="left" scrolling="yes" marginheight="0" marginwidth="0" frameborder="0"><p>Ihr Browser kann leider keine eingebetteten Frames anzeigen!<br /><a href="http://www.agentur-lanzinger.de/questionnaire/" title="Manuell weiter zum Fragebogen">Manuell weiter zum Fragebogen.</a></p></iframe>').appendTo("#qn_questionnaire");

      });

      $("#qn_overlay, #qn_close").click( function() {
        $("#qn_bg, #qn_overlay").fadeOut(750);
      });

      $("#qn_questionnaire").click( function() {
        return false;
      });

    }

	};

  // Activate agenturLanzingerScripts if HTML is ready
  $("html").agenturLanzingerScripts();

});