
// sprungmenü, z.B. für Branchenfinder
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

var resetNecessary = true;

var setBranchenStyles = function(branchenArr) {

	branchenArr.each(function(el) {

		el.addEvent('click', function(event) {


			// alle divs deaktivieren
			$$('#branchenoverviewAll .branchenoverviewOn').each(function(el) {
				el.className = 'branchenoverview';
			});
			$$('#branchendetailAll .branchendetail').each(function(el) {

				el.fade('out');
				el.setStyle('display','none');
				el.setStyle('opacity',0);
			});
			// das aktuelle aktivieren
			event.target.className = 'branchenoverviewOn';
			// id nummer des aktuellen holen
			// b durch bd ersetzen
			var divID = event.target.id.replace(/b/,'bd');
			var showBDiv = $(divID);
			//showBDiv.setStyle('display','block');
			showBDiv.fade('in');
			showBDiv.setStyle('display','block');
		});

	});

};

var showSubnavi = function(naviArr) {

	naviArr.each(function(el) {

		el.addEvent('mouseover', function(event) {
			resetNecessary = false;

			$$('#subnaviAll .subnavigation').each(function(el) {
				el.setStyle('display','none');
			});

			var divID = event.target.id.replace(/main/,'sn');
			var showBDiv = $(divID);
			showBDiv.setStyle('display','block');

		});

	});

};

var resetSubnavi = function(mainCategoryId) {
	if (resetNecessary) {
	  $$('#subnaviAll .subnavigation').each(function(el) {
	    el.setStyle('display','none');
	  });
	  $('sn' + mainCategoryId).setStyle('display','block');
	}
};

var hideSubnavi = function(sArr,mainCategoryId) {

	sArr.each(function(el) {

		el.addEvent('mouseleave', function(event) {
			resetNecessary = true;
      resetSubnavi.delay(7000, this, mainCategoryId);
		});

	});

};

var hideSubnaviRest = function(rArr,mainCategoryId) {

	rArr.each(function(el) {

		el.addEvent('mouseover', function(event) {
			resetNecessary = true;
			resetSubnavi.delay(7000, this, mainCategoryId);
		});

	});

};

var manageToolbox = function(downloads) {
    Element.implement("slideOutAndDisplay", function(style) {
      this.slide("out").get("slide").addEvent("complete", function() { this.setStyle("display", style); this.get("slide").removeEvents("complete"); }.bind(this));
    });
    Element.implement("displayAndSlideIn", function(style) {
      this.setStyle("display", style).slide("in");
    });

    $('mainToolbox1').setStyle("display", "block");
    $("mainToolbox2").slideOutAndDisplay("block");


    $('mainToolbox1').getElement('#shareShow1').addEvent('click',function() {
      $('mainToolbox1').setStyle("display", "none");
      $('share').setStyle("display", "block");

      $('mainToolbox2').displayAndSlideIn("block");
      if (downloads == 1) {
        $('downloads').setStyle("display", "none");
      }

			// IE7-Fix
			if (Browser.Engine.name == "trident" && Browser.Engine.version == 5) {
				if ($("mainToolbox2").getHeight() > $("share").getHeight() + 20) {
					$("mainToolbox2").getParent().setStyle("maxHeight", $("share").getHeight() + 20);
				}
			}
    });


    if (downloads == 1) {
    	 $('mainToolbox1').setStyle("display", "none");
         $('downloads').setStyle("display", "block");
         $('mainToolbox2').displayAndSlideIn("block");
         $('share').setStyle("display", "none");
  		 // IE7-Fix
 	     if (Browser.Engine.name == "trident" && Browser.Engine.version == 5) {
 	        if ($("mainToolbox2").getHeight() > $("downloads").getHeight() + 20) {
 	          $("mainToolbox2").getParent().setStyle("maxHeight", $("downloads").getHeight() + 20);
 	        }
 	     }
 	     
      $('mainToolbox1').getElement('#downloadsShow1').addEvent('click',function() {
        $('mainToolbox1').setStyle("display", "none");

        $('downloads').setStyle("display", "block");

        $('mainToolbox2').displayAndSlideIn("block");
        $('share').setStyle("display", "none");

				// IE7-Fix
	      if (Browser.Engine.name == "trident" && Browser.Engine.version == 5) {
	        if ($("mainToolbox2").getHeight() > $("downloads").getHeight() + 20) {
	          $("mainToolbox2").getParent().setStyle("maxHeight", $("downloads").getHeight() + 20);
	        }
	      }
      });


      $('mainToolbox2').getElement('#downloadsShow2').addEvent('click',function() {
        $('mainToolbox2').get("slide").addEvent("complete", function() {
          if ($('share').getStyle("display") == "block") {
            $('share').setStyle("display", "none");
            $('mainToolbox2').get("slide").removeEvents("complete");
            $('mainToolbox1').getElement('#downloadsShow1').fireEvent("click");
          }
        });

        $('mainToolbox1').setStyle("display", "block");
        $('mainToolbox2').slideOutAndDisplay("none");
      });
    }


    $('mainToolbox2').getElement('.close').addEvent('click',function() {
      $('mainToolbox2').slideOutAndDisplay("none");
      $('mainToolbox1').setStyle("display", "block");
      $('share').setStyle.delay(100, $('share'), ["display", "none"]);
      if (downloads == 1) {
        $('downloads').setStyle.delay(100, $('downloads'), ["display", "none"]);
      }
    });


    $('mainToolbox2').getElement('#shareShow2').addEvent('click',function() {
      $('mainToolbox2').get("slide").addEvent("complete", function() {
        if (downloads == 1 && $('downloads').getStyle("display") == "block") {
          $('downloads').setStyle("display", "none");
          $('mainToolbox2').get("slide").removeEvents("complete");
          $('mainToolbox1').getElement('#shareShow1').fireEvent("click");
        }
      });

      $('mainToolbox1').setStyle("display", "block");
      $('mainToolbox2').slideOutAndDisplay("none");
    });

};

var Background = new Class({
	options: { // HTML-Attribute des img-Tags
		id:           "background",
		src:          "",
		alt:          "",
		style: { // CSS
		  "width":    800,
			"height":   600,
			"position": "fixed",
			"z-index":  1
		}
	},

	element: null, // speichert das img-Tag

	ratio: 1, // ursprüngliches seitenverhältnis des bildes festhalten

  initialize: function(options) {
		this.options = $merge(this.options, options);

		// Image-Tag erstellen
		this.element = new Asset.image(this.options.src, {
		  id: this.options.id,
			onload: function() { this.element.fade("in"); }.bind(this)
		}).setStyles(this.options.style).fade("hide").injectInside($$("body")[0]);
    this.ratio = this.options.style.width / this.options.style.height;

		// resizen aktivieren
    window.addEvent('resize', this.resizeBackground.bind(this));
    this.resizeBackground();

    // IE-fix für position:fixed
    if (Browser.Engine.name == "trident" && Browser.Engine.version < 5) {
      window.addEvent("resize", this.fixPosition.bind(this));
      window.addEvent("scroll", this.fixPosition.bind(this));
      this.fixPosition();
    }
	},

	resizeBackground: function() { // Hintergrundbild resizen, dabei Seitenverhältnis beibehalten
    if (window.getWidth() / window.getHeight() > this.ratio) { // breite beibehalten
      this.element.setStyle("width", window.getWidth()).setStyle("height", window.getWidth() / this.ratio);
    } else { // höhe beibehalten
      this.element.setStyle("width", window.getHeight() * this.ratio).setStyle("height", window.getHeight());
    }
  },

	fixPosition: function() { // position: fixed im IE6 simulieren
    this.element.setStyles({
      "position":  "absolute",
      "top":       (window.getScroll().y + window.getSize().y - this.element.getSize().y)
    });
  }
});

var Slideshowhome = new Class({
  Implements: [Options, Chain],

  options: {
    images:         [],   // welche Bilder sollen angezeigt werden?
    container:      null, // welche ID hat der Container-Div?
    delayNextImage: 5000, // wie lange soll ein Bild angezeigt werden?
		delayFading:    500   // Zeitabstand zwischen Fade-Out des alten und Fade-In des neuen Bildes
  },

  elements: {
    container:      null,
    images:         null
  },

  currentImage: 0,

  initialize: function(options) {
    this.setOptions(options);

		this.elements.container = $(this.options.container);
    this.elements.images = new Asset.images(this.options.images, { // Bilder laden
      onComplete: function(){
        this.elements.images.each(function(el) {
          el.fade('out').setStyle("display", "none").injectInside(this.elements.container);
        }.bind(this));
        this.elements.images[0].setStyle("display", "block").fade('in');

        this.runChain(); // Slideshow starten, wenn alles geladen ist
      }.bind(this)
    });
  },

  runChain: function() { // Slideshow-Ablauf
    this.chain(
      this.fadeOut,
      this.swapImage,
      this.fadeIn
    );
    this.callChain.delay(this.options.delayNextImage, this);
  },

  fadeOut: function() {
		this.getCurrentImage().fade('out');

		this.callChain.delay(this.options.delayFading, this);
  },

  swapImage: function() {
		this.getCurrentImage().setStyle("display", "none");
		this.getNextImage().setStyle("display", "block");

    this.callChain();
  },

  fadeIn: function() {
    this.getCurrentImage().fade('in');

		this.runChain();
  },

	getCurrentImage: function() { // Img-Element holen
    return this.elements.images[this.currentImage];
  },

  getNextImage: function() { // Img-Element holen
    this.currentImage++;
    if (this.currentImage >= this.elements.images.length) this.currentImage = 0;
    return this.getCurrentImage();
  }
});

var doPrint = function() {
	if ($("sn0").getParent().getStyle("height").toInt() > 0) $("sn0").getParent().setStyle("height", "auto");
	window.print();
};

var sendMail = function() {
	$("emailform").get("send").options.method = "post";
	$("emailform").get("send").addEvents({
		"success": function() { $("emailform-feedback").innerHTML = $("emailform").get("send").response.text; },
		"failure": function() { $("emailform-feedback").innerHTML = "Fehler beim Senden"; }
	});
	//$("emailform").send($("emailform").get("send").options.url.replace(/emailFrom/, $("emailform").emailFrom.value).replace(/emailTo/, $("emailform").emailTo.value));
	$("emailform").send( );
};

