var bm = new Object();

/* Dom geladen? Ab dafür! */
document.observe("dom:loaded", function() {
	
	/* Land bei plz Suche dran haengen */
	var funcAddCountryToDealersearchInput = function(){
		
		var reg = new RegExp('^[0-9]{5}$');
		if(reg.exec(this.value))
			this.value += ', Germany';
	}		
	
	if ($('dealer_search_q_mini') != null) $('dealer_search_q_mini').observe('keyup', funcAddCountryToDealersearchInput);
	if ($('dealer_search_q') != null) $('dealer_search_q').observe('keyup', funcAddCountryToDealersearchInput);
	$$('.dealer_search').each(function(element) { element.observe('keyup', funcAddCountryToDealersearchInput); });
		
	// Mehr erfahren links einblenden
	try {
		$$(".js_more").each(function(element) {
			new BigMax.MoreButton(element, $(element).down(".mouseover_more"), {
				delay: 0.4,
				duration: 0.3
			});
		});
	} catch (e) {}
	
	try {
		// Wieder nach oben link
		$("backtotop").href = 'javascript:void(0);';
		$("backtotop").observe("click", function() {
			Effect.ScrollTo("main_container", {
				fps: 30,
				duration: 0.5
			});
		});
	} catch (e) {}
	
	try {
		if ($("product_lightbox_trigger_image")) {
			bm.pl = new BigMax.ProductLightbox("product_lightbox_trigger_image", {
				fps: 40,
				duration: 0.5,
				teaserClass: "product_thumb",
				insertBefore: $("main_container"),
				closeLabel: $("close_label").value,
				thumbsHeadline: $("more_colors_label").value,
				alternativeTrigger: $("product_lightbox_trigger_button")
			});
		}
	} catch (e) {}

	try {
		var callbackFn = function() {
			if (typeof(bm["pl"]) == "undefined")
				return;

			bm.pl.openLayer();
		}
		$$(".product_thumb").each(function(element, index) {
			var thumb = new BigMax.ProductThumbnail(element, "product_lightbox_trigger_image");
			thumb.onChange = callbackFn;
		});
	} catch (e) {}
	try {
		$$(".image_lightbox").each(function(element, index) {
			new BigMax.ProductLightbox(element, {
				type: "small",
				duration: 0.2,
				insertBefore: $("main_container"),
				closeLabel: $("close_label").value
			});
		});
	} catch (e) {}
	try {
		if ($("youtube_lightbox")) {
			var youtubeLightbox = new BigMax.Lightbox($("youtube_lightbox"), {
				duration: 0.2,
				insertBefore: $("main_container"),
				closeLabel: $("close_label").value
			});
			youtubeLightbox.setContent($("youtube_lightbox_content").innerHTML);
			youtubeLightbox.setContentDimensions(640, 385);
		}
	} catch (e) {}

	try {	
		// Produkt info reiter nav
		if ($("product_tabs")) {
			bm.pt = new BigMax.ProductTabs("product_tabs", {
				fps: 30,
				duration: 0.3,
				activeTabIndex: 0,
				morphDuration: 0.3,
				colorClass: "color",
				container: "container",
				tabClassPattern: "tab_",
				tabHeaderClass: "tabheader"
			});
		}
	} catch (e) {}
});

/* Alles was noch auf styles warten muss */
Event.observe(window, "load", function() {
	// Großes Visual
	try {
		if ($("visual_items")) {
			bm.v = new BigMax.Visual("visual_items", {
				fps:          40,
				duration:     1.6,
				interval:     10,
				moreDelay:    1,
				breakDelay:   12,
				moreDuration: 0.5,
				menuID: "visual_nav",
				inactiveColor: "#666",
				activeColor: "#333"
			});
		}
	} catch (e) {}
	
	try {
		// Hauptnavigation erst laden, wenn die Josefin eingesetzt hat
		if ($("main_navigation")) {
			bm.mn = new BigMax.Navigation("main_navigation", "main_navigation_highlight", {
				fps: 80,
				delay: 0.6,
				duration: 0.4,
				layerDelay: 1.2,
				layerFadeDuration: 0.3,
				layerAppearDuration: 0.15,
				layerPattern: "layername_"
			});
		}
	} catch (e) {}
	
	try {
		// Für die Subnavigation gilt das selbe
		if ($("subnavigation")) {
			bm.mn = new BigMax.Navigation("subnavigation", "subnavigation_highlight", {
				fps: 40,
				delay: 0.6,
				duration: 0.3,
				direction: "vertical"
			});
		}
	} catch (e) {}
	
	try {
		// "Produktübersicht" Button
		if ($("btn_prod_overview")) {
			bm.po = new BigMax.ProductOverview("btn_prod_overview_trigger", "btn_prod_overview_layer", {
				fps: 50,
				delay: 0.25,
				duration: 0.175
			});
		}
	} catch (e) {}
});
