// Andreas Fels 29.01.2010 IE6-Detection
var thisisie6 = false;
if(typeof(document.body.style.maxHeight) == "undefined" && !window.XMLHttpRequest) thisisie6 = true;

/* Schrift groesser/kleiner Buttons */

function fontsize_decrease()
{
	FontTools.FontSize.decrease();
}

function fontsize_increase()
{
	FontTools.FontSize.increase();
}

function fontsize_reset()
{
	FontTools.FontSize.reset();
}

/* Suchergebnis Fenster */

function searchresults_show()
{
	$('#search_results').css("left", 0);
}

function searchresults_hide()
{
	$('#search_results').hide();
}

/* Compare Buttons */

var comparebuttonsCount = 0;
var comparebuttonsChecked = new Object();

function compareToggle(checked_id,checked_status) {
	switch(checked_status) 	{
		default:
		break;

		case true:
		case 1:
			if(comparebuttonsCount == 3) {
				lightbox_open(Config.dialogs.compareDialog);
				$('#' + checked_id).attr("checked",0);
				return;
			}

			comparebuttonsCount++;
			comparebuttonsChecked[checked_id] = 1;
			break;

		case false:
		case 0:
		comparebuttonsCount--;
		if(typeof(comparebuttonsChecked[checked_id]) != "undefined") delete comparebuttonsChecked[checked_id];
		$('#comparebutton_' + checked_id).hide();
		break;
	}

	if(comparebuttonsCount >= 2)
	{
		for (var object_id in comparebuttonsChecked)
		{
			$('#comparebutton_' + object_id).show();
		}
	}
	else
	{
		$('.comparebutton').hide();
	}
}
/* Shop Buttons Add und View Basket */
var basketbuttonsChecked = new Object();
function baskettbuttonsToggle(checked_id,checked_status)
{
	switch(checked_status)
	{
		default:
		break;

		case true:
		case 1:
		basketbuttonsChecked[checked_id] = 1;
		$('#basketbuttons_' + checked_id).show();
		break;

		case false:
		case 0:
		if(typeof(basketbuttonsChecked[checked_id]) != "undefined") delete basketbuttonsChecked[checked_id];
		$('#basketbuttons_' + checked_id).hide();
		break;
	}

}

/**
 * Verschiebt den sichtbaren Ausschnitt der Tabelle um eine Spalte in die
 * angegebene Richtung.
 *
 * @param {Object[]} rows Zeilen mit zu verschiebenden Spalten
 * @param {String} direction Richtung in die verschoben wird als String ("previous","next")
 */
function moveVisible(rows, direction) {
	rows.each(function() {
		var exit = false;

		$(this).children('td:not(:first-child), th:not(:first-child)').each(function() {
			if(exit) return;
			var $this = $(this);

			if(!$this.hasClass('hidden')) {
				if(direction == 'previous') {
					if($this.prev().hasClass('hidden')) {
						$this.prev().removeClass('hidden').addClass("first").show();
						$this.removeClass('first');

						var lastVisible = $this.nextAll('[class*="hidden"]:first').prev();

						if(lastVisible.size() == 0) {
							 lastVisible = $this.nextAll(':last');
						}

						lastVisible.addClass('hidden').hide();
						exit = true;
					}
				}else if(direction == 'next') {
					if($this.next().hasClass('hidden')) {
						$this.next().removeClass('hidden').show();

						var firstVisible = $this.prevAll('[class*="hidden"]:first').next();

						if(firstVisible.size() == 0) {
							 firstVisible = $this.prevAll(':last').next();
						}

						firstVisible.removeClass('first').addClass('hidden').hide();
						firstVisible.next().addClass('first');
						exit = true;
					}
				}
			}
		});
	});
}

function getSearchResults(url, query, link, caption) {
	var options = {
		type     : "GET",
		dataType : "xml"
	};

	RequestHandler.get("searchresults", url, function(data) {
		var currentCategory = "";
		var currentCategoryList = null;
		var resultContainer = $('#search_results');
		var resultList = $('#search_results_list');
		resultContainer.hide();
		resultList.html("");

		var $matches = $(data).find("search_results match");

		if($matches.size() == 0) return;

		$matches.each(function() {
			var $this    = $(this);

			var image    = $this.attr('image');
			var title    = $this.attr('title');
			var category = $this.attr('category');
			var url      = $this.attr('url');
			var copy     = $this.attr('copy');
			var priority = $this.attr('priority');

			var category_id = category.toLowerCase().replace(/[^a-z0-9]+/g,"_");

			if(category != currentCategory) {
				$(resultList).append(
					'<h3 class="sr_header">' + category + '</h3>' +
					'<ul id="search_results_' + category_id + '" class="sr_content sr_' + category_id + '"></ul>'
				)

				currentCategory = category;
				currentCategoryList = $('#search_results_' + category_id);
			}

			currentCategoryList.append(
				'<li class="sr_content_column">' +
				'<a href="' + url + '" title="' + title + '" class="clearfix">' +
				(image ? '<img src="' + image + '" alt="' + title + '" title="' + title + '" />' : '') +
				'<span>' + title + '</span>' +
				copy +
				'</a>'
			);
		});

		resultList.append(
			'<li class="sr_footer">' +
				'<a class="button_container" href="' + link + '?query=' + query + '" target="_self">' +
					'<span class="button_relative">' +
						'<span class="button_inner">' +
							'<span class="button_l">' +
								'<span class="button_r">' +
									'<span class="button_main">' +
										'<span class="button_pfeil_rechts">' + caption + '</span>' +
									'</span>' +
								'</span>' +
							'</span>' +
						'</span>' +
						'<span class="button_tl"></span>' +
						'<span class="button_tr"></span>' +
						'<span class="button_bl"></span>' +
						'<span class="button_br"></span>' +
					'</span>' +
				'</a>' +
			'</li>'
		);

		resultContainer.show();
	}, options);
}

function bindCompareButtons() {
	// compare knoepfe
	$('.productcompare').bind("click", function() {
		compareToggle($(this).attr('id'),$(this).attr('checked'));
	});
	$('.productcompare').removeAttr('checked');
	$('.comparebutton').hide();
}

$('.search_results_close').bind("click", function() {
	$('#search_results').hide();
});

function bindCompareButtons() {
	// compare knoepfe
	$('.productcompare').bind("click", function() {
		compareToggle($(this).attr('id'),$(this).attr('checked'));
	});
	$('.productcompare').removeAttr('checked');
	$('.comparebutton').hide();
}

/* Onload-Befehle */

$(window).load(function() {
	FontTools.FontSize.init(cookieManager.getCookie('fontsize') || "75%", "75%", ["60%", "65%", "75%", "87%", "97%", "110%", "122%", "137%"]);
	FontTools.registerCallback("fontsize_change", null, function(source,event,params) {
	cookieManager.setCookie("fontsize", FontTools.FontSize.currentSize);
	});

	// icon-hover
	$('.nav_layer_head_link').bind("mouseenter", function() {
		var $img = $(this).children("img");
		var source = $img.attr("src");
		if(!$.data(this, "original_source")) {
			$.data(this, "original_source", source);
		}
		var new_source = source.substr(0,source.lastIndexOf(".")) + "_hover." + source.substr(source.lastIndexOf(".") + 1);
		$img.attr("src",new_source);
	}).bind("mouseleave", function() {
		var $img = $(this).children("img");
		$img.attr("src",$.data(this, "original_source"));
	});

	bindCompareButtons();

	/*
	// Shop Buttons Liste
	$('.product_order_check').bind("click", function() {
		baskettbuttonsToggle($(this).attr('id'),$(this).attr('checked'));
	});

	$('.product_order_check').each(function() {
		baskettbuttonsToggle($(this).attr('id'),$(this).attr('checked'));
	});
	*/
	$('.shop_listing_quantity input').bind("keyup", function() {
	var $input = $('#' + $(this).attr('name').replace(/quantity_/,""));

	if($(this).val() > 0) {
        	$input.attr('checked', true);
	} else {
		$input.attr('checked', false);
	}
	});
	$('.shop_listing_quantity input').each(function() {
		var $input = $('#' + $(this).attr('name').replace(/quantity_/,""));

	if($(this).val() > 0) {
        	$input.attr('checked', true);
	} else {
		$input.attr('checked', false);
	}
	});

	// Details Marginalspalte Klaappfunktion
	$('.loginbox_inner .closed').bind("click", function() {
		alert ('Test');
	});
	//$('.product_order_check').removeAttr('checked');
	//$('.baskettbuttons').hide();

	// eventuell vorhandene onloadCommands ausfuehren
	if(typeof onloadCommands == "object") {
		var onloadString = "";

		for(var i = 0; i < onloadCommands.length; i++) {
			onloadString += onloadCommands[i];
		}

		if(onloadString != "") {
			eval(onloadString);
		}
	}

	// alle grid-Listen durchgehen und die h3s mit der class
	// "product_item_headline" in der Hoehe angleichen
	$('ul.products_list_grid').each(function() {
		// maximale Hoehe auf 0 setzen
		var maxHeight = 0;
		// alle Produkt-Ueberschriften suchen
		var $headlines = $(this).find('h3.product_item_headline');
		// alle Ueberschriften durchgehen und die maximale Hoehe finden
		$headlines.each(function() {
			var outerHeight = $(this).outerHeight();
			if(outerHeight > maxHeight) {
				maxHeight = outerHeight;
			}
		});
		// die Hoehe aller Produktueberschriften auf die gefundene maximale
		// Hoehe angleichen
		$headlines.css("height", maxHeight);
	});

	// Links mit Lightboxen initialisieren
	$('.lightbox_link').click(function(evt) {
		try {
			var url = $(this).attr("rel");
			if(!url) url = $(this).attr("href");
			lightbox_open(url);
			evt.returnValue = false;
			evt.cancelBubble = true;
			return false;
		} catch ( e ) {
			// beim fehler dem link normal folgen, damit wenigstens weitergemacht
			// werden kann
			return true;
		}

	});

	// Autocomplete
	$('#name-sn').autocomplete(
		Config.ajax.autocompleteData,
		{
			max: 10,
			scroll: false,
			mustMatch: false,
			matchContains: false
		}
	);

	// Testen ob Grafikkomponenten vorhanden sind und ggf. jquery-ui nachladen und
	// Komponenten initialisieren
	var uiComponents = checkUIComponents();

	if(uiComponents.length > 0) {
		var script_path = '';

		$(document).find('script').each(function() {
			if($(this).attr("src")) {
				var source = $(this).attr("src").toString();
				script_path = source.substr(0, source.lastIndexOf("/"));
			}
		})

		$.getScript(script_path + "/jquery-ui.js",function() {
			initUIComponents(uiComponents);
		});
	}

	// Fixed Ticket 0002619: Webshop - Column "Menge"
	// t.schirski@kernpunkt.de
	$('input.product_order_check').click(function(){
		var currentQuantity = $(this).parent().parent().find('li.shop_listing_quantity').find('input').attr('value');

		if ($(this).attr('checked') == true)
		{
			if (currentQuantity == "0")
			{
				$(this).parent().parent().find('li.shop_listing_quantity').find('input').attr('value', '1');
			}
		}
		else
		{
			$(this).parent().parent().find('li.shop_listing_quantity').find('input').attr('value', '0');
		}
	});

	$('li.shop_listing_quantity input').keyup(function(){
		if ($(this).attr('value') != "0" && $(this).attr('value') != "")
		{
			$(this).parent().parent().find('li.shop_listing_order').find('input').attr('checked', 'checked');
		}
		else
		{
			$(this).attr("value", "0");
			$(this).parent().parent().find('li.shop_listing_order').find('input').attr('checked', false);
		}
	});

	/* Variante von Christian Schaefer am 29.01.2010
	 * Modifiziert von Kristian Kriehl am 01.02.2010:
	 * - Entfernung der IE6-Bedingung (ist kompatibel)
	 * - IE6-Fehler behoben
	 */
	// Verzoegerung des Ausklappens des Menues durch voruebergehendes Aendern der Klasse
	var activeMenuLayerTimeout;
	var $activeMenuLayer;

	$('.navbalken_inner').children('li').each(function() {
		$(this).bind('mouseenter', function() {
			$activeMenuLayer = $(this).children("ul").eq(0);
			$activeMenuLayer.css("left", -10000);
			activeMenuLayerTimeout = window.setTimeout(function() {
				$activeMenuLayer.css("left", 0);
			}, 300);
		}).bind('mouseleave', function() {
			$activeMenuLayer.css("left", -10000);
			window.clearTimeout(activeMenuLayerTimeout);
			activeMenuLayerTimeout = null;
			$activeMenuLayer = null;
		});
	});
});

/*
 * Geschrieben und entfernt von Kristian Kriehl am 01.02.2010:
 * 2 Funktionen zum zeitversetzten Ein- und Ausblenden von Navigations-Layern.
 * Vorhanden sind diese in der Revision 310, damit die Arbeit nicht ganz umsonst
 * war.
 */

function checkUIComponents() {
	// Akkordion
	var uiComponents = [];
	var i = 0;

	if($('ul.accordion').size() > 0) {
		uiComponents[i] = "accordion";
		i++;
	}

	if ( $(".date-pick").size() > 0 ) {
		uiComponents[i] = "datepicker";
		i++;
	}

	if( $('.slider').size() > 0 ) {
		uiComponents[i] = "slider";
		i++;
	}

	return uiComponents;
}

function onSlideChange() {
	// wird von Kernpunkt implementiert
}

function initUIComponents(components) {
	for(key in components) {
		if(components[key] == "accordion") {
			// Headlines fuer die Akkordion-Click-Elemente aus dem Elementtitel ziehen
			// und setzen
			/*
			$('.accordion_header').each(function() {
				$(this).append($('<span>' + $(this).attr('title') + '</span>'))
			});
			*/
			var $accordionElements = $('ul.accordion');

			// neues Akkordion
			$accordionElements.collapsiblelist({
				header        : '.accordion_header',
				activeClass   : 'ui-state-active',
				defaultClass  : 'ui-state-default',
				accordionMode : false
			});

			// Das Click-Event aller Links mit der Relation "previous" innerhalb des
			// Akkordions kapern...
			$accordionElements.find('a[rel="previous"]').click(function() {
				// Die zugehoerige Tabelle finden
				var $table = $(this).closest('table');

				// Alle TDs innerhalb von tbody und thead (ausser mit der Klasse "pager")
				// mit der relation "previous" an die moveVisible-Funktion uebergeben
				moveVisible($table.children('tbody').children('tr:not([class="pager"])'), 'previous');
				moveVisible($table.children('thead').children('tr'), 'previous');
			}).attr('href','javascript:void(0);'); // Verhindert den Sprung an den Seitenanfang beim Klick

			// Hier gilt dasselbe wie zuvor, nur fuer die Relation "next"
			$accordionElements.find('a[rel="next"]').click(function() {
				var $table = $(this).closest('table');

				moveVisible($table.children('tbody').children('tr:not([class="pager"])'), 'next');
				moveVisible($table.children('thead').children('tr'), 'next');
			}).attr('href','javascript:void(0);');
		}

		if(components[key] == "datepicker") {
			var datePickerDefaults = {
				showOn          : "button",
				buttonImage     : Config.images.datepickerButtonImage,
				buttonImageOnly : true,
				firstDay        : 1,
				dateFormat      : "dd.mm.yy",
				dayNames        : [ "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"	],
				dayNamesShort   : [ "Son", "Mon", "Die", "Min", "Don", "Fri", "Sam" ],
				dayNamesMin     : [ "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa" ],
				monthNames      : [	"Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember" ],
				monthNamesShort : [ "Jan", "Feb", "M&auml;r", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez" ]
			}

			$.datepicker.setDefaults(datePickerDefaults);

			$('#deliverydate').datepicker({
				minDate : -0,
				maxDate : "+6W"
			});
			$('.date-pick').datepicker();

			$('.ui-datepicker-trigger').mouseover(function() {
				$(this).attr("src", $(this).attr("src").replace(/kalender/,"kalender_hover"));
			}).mouseout(function() {
				$(this).attr("src", $(this).attr("src").replace(/kalender_hover/,"kalender"));
			});
		}

		if(components[key] == "slider") {
			$('.slider').each(function() {
				if(!$.data(this, 'initialized')) {

					var selectID = $(this).attr('id').replace(/-slider/,'-select');
					var $select = $('select#' + selectID);

					if($select.size() == 0) $select = $('select[name="' + selectID + '"]');
					if($select.size() == 0) $select = $('select.' + selectID);

					var select = $select.get(0);

					if(!select || select.options.length == 0) {
						return;
					}

					var minIndex = 0;
					var maxIndex = 0;
					var firstVal = true;

					$('div.dragbar_inner div.dragbar_skala').replaceWith('<table class="dragbar_skala"><tr></tr></table>');

					var $headlineTable = $('div.dragbar_inner table.dragbar_skala').find('tr').eq(0);

					$select.children('option').each(function() {
						if($(this).val() == '') {
							minIndex++;
						} else if(firstVal) {
							firstVal = false;
							maxIndex = minIndex;
							$headlineTable.append('<td>' + $(this).html() + '</td>');
						} else {
							maxIndex++;
							$headlineTable.append('<td>' + $(this).html() + '</td>');
						}
					});

					var sliderOpts = new Object();
					sliderOpts.min = minIndex;
					sliderOpts.max = maxIndex;
					sliderOpts.step = 1;

					sliderOpts.change = function(event, ui) {
						select.selectedIndex = ui.value;
						onSlideChange();
					};

					$(this).slider(sliderOpts);
					$(this).children('a').html($(this).attr('rel'));

					$.data(this, 'initialized', true);
				}
			});
		}
	}
}

function hidepass(){
   document.loginform.ptext.style.display='none';
   document.loginform.pass.style.display='';
   document.loginform.pass.focus();
 }
function showpass(){
   document.loginform.pass.style.display='none';
   document.loginform.ptext.style.display='';
   document.loginform.ptext.focus();
}
function setEnd (el) {
 if (el.createTextRange) {
   var FieldRange = el.createTextRange();
   FieldRange.moveStart('character', el.value.length);
   FieldRange.collapse();
   FieldRange.select();
 }
}
function opensort() {
document.getElementById('button_save_bookmarks').style.display='block';
document.getElementById('button_sort_bookmarks').style.display='none';
$('.bookmark_functions img.bookmark_delete').show();
$('.bookmark_functions img.bookmark_sort').show();
}
function closesort() {
document.getElementById('button_save_bookmarks').style.display='none';
document.getElementById('button_sort_bookmarks').style.display='block';
$('.bookmark_functions img.bookmark_delete').hide();
$('.bookmark_functions img.bookmark_sort').hide();
}

function openedit() {
document.getElementById('button_edit_data').style.display='block';
document.getElementById('button_save_data').style.display='none';
$('this ul').addClass("edit_active");
}
function opensave() {
document.getElementById('button_edit_data').style.display='none';
document.getElementById('button_save_data').style.display='block';
$('this ul').removeClass("edit_active");
}

function prepare_form() {
	$('a[rel=form_mode_toggle]').click(function() {
		toggle_mode(this);
	});
}

function loadPrintCSS() {
	$('head').find('link[href="' + Config.files.defaultCSS + '"]').replaceWith(
		'<link rel="stylesheet" type="text/css" href="' + Config.files.printCSS + '"/>'
	);
}

function printDialog(params) {
	var url = Config.ajax.dialogPrintView;
	var firstParam = true;

	for(var attr in params) {
		url += (firstParam ? "?" : "&") + attr + "=" + encodeURIComponent(params[attr]);
		if(firstParam) firstParam = false;
	}

	location.href = url;
}

$('.edit_data input.textfeld').attr("readonly","readonly");
function toggle_mode(button) {
	var $container = $(button.parentNode);
	var button_main = $(button).find('.button_main').children('span').get(0);
	var mode = "";

	if($(button_main).hasClass('button_edit_links')) {
		mode = "edit";
   }
   if($(button_main).hasClass('button_diskette_links')) {
		mode = "save";
   }
   if($(button_main).hasClass('button_change_links')) {
		mode = "change";
   }
	if($(button_main).hasClass('button_change')) {
		mode = "change-save";
   }

   if(mode == "edit") {
	   $container.children("ul").addClass("edit_active");
	   $container.find('input').removeAttr("readonly");
	   $(button_main).removeClass("button_edit_links");
	   $(button_main).addClass("button_diskette_links");
   	   $(button_main).html("Save");
	   $(button).attr("title","Save");
   } else if(mode == "change") {
	   $container.children("ul").addClass("edit_active");
	   $container.find('input').removeAttr("readonly");
	   $(button_main).removeClass("button_change_links");
	   $(button_main).addClass("button_diskette_links button_change");
   	   $(button_main).html("Save");
	   $(button).attr("title","Save");
	   $('.password_new_column').css("display","block");
   } else if(mode == "change-save") {
	    $container.children("ul").removeClass("edit_active");
	   $container.find('input').attr("readonly","readonly");
	   $(button_main).removeClass("button_diskette_links button_change");
	   $(button_main).addClass("button_change_links");
   	   $(button_main).html("Change");
	   $(button).attr("title","Change");
	   $('.password_new_column').css("display","none");
   } else if(mode == "save") {
	   $container.children("ul").removeClass("edit_active");
	   $container.find('input').attr("readonly","readonly");
	   $(button_main).removeClass("button_diskette_links");
	   $(button_main).addClass("button_edit_links");
   	   $(button_main).html("Edit");
	   $(button).attr("title","Edit");
   }
}

// Details Marginalspalte Klappfunktion
$('.loginbox_inner .details_closed').bind("click", function() {
	if (!$('.details_linklist').is(':visible')) {
		$('.details_linklist').show();
		$('.details_closed').addClass("details_opened");
	}
	else {
		$('.details_linklist').hide();
		$('.details_closed').removeClass("details_opened");
	}
});

$(window).load(function() {
	prepare_form();
});

$(window).load(function() {
	// Testen auf Google Maps
	if($('#googlemap').size() > 0) {
		loadGMap();
	}

	// ##### Sitemap initialisieren Start #####
		// Sitemap Controls fr oberste Ebene
		var alttext = [ '', '', '', '', '' ];

		if($('.sitemap_out').attr('rel')) {
			alttext = $('.sitemap_out').attr('rel').split(/,/);
		}

		$('.sitemap_head').closest('li').find('.sitemap_liste').each(function() {
			$(this).hide();
			$(this).closest('li').find('.sitemap_head').each(function() {
				var $this = $(this);
				$this.after(
					'<span class="sitemap_control">' +
						'<span>' + alttext[0] + '</span>' +
						'<a href="#" title="' + alttext[1] + '" class="sitemap_liste_open_link">' +
							'<img src="' + Config.images.sitemapOpenConnectionActive + '" class="sitemap_liste_open_img" title="' + alttext[1] + '" alt="' + alttext[1] + '" />' +
						'</a>' +
						'<a href="#" title="' + alttext[2] + '" class="sitemap_liste_close_link">' +
							'<img src="' + Config.images.sitemapCloseConnectionActive + '" class="sitemap_liste_close_img" title="'+alttext[2]+'" alt="'+alttext[2]+'" />' +
						'</a>' +
					'</span>'
				);
			});
		});


		// Sitemap Toggle Event oberste Ebene
		$('.sitemap_head').addClass('sitemap_head_clickable').bind("click", function() {
			var $li = $(this).closest('li');

			$li.find('.sitemap_liste_open_img').attr('src', function() {
				if($(this).attr('src') == Config.images.sitemapOpenConnectionActive) {
					return Config.images.sitemapOpenConnectionInactive;
				} else {
					return Config.images.sitemapOpenConnectionActive;
				}
			});

			$li.find('.sitemap_liste_close_img').attr('src', function() {
				if($(this).attr('src') == Config.images.sitemapCloseConnectionActive) {
					return Config.images.sitemapCloseConnectionInactive;
				} else {
					return Config.images.sitemapCloseConnectionActive;
				}
			});

			$li.children('ul').toggle(300);
		});

		// Sitemap oeffnen Event oberste Ebene
		$('.sitemap_liste_open_link').attr('href','javascript:void(null);').bind("click", function() {
			var $li = $(this).closest('li');
			$li.find('.sitemap_liste_open_img').attr('src', Config.images.sitemapOpenConnectionInactive);
			$li.find('.sitemap_liste_close_img').attr('src', Config.images.sitemapCloseConnectionActive);
			$li.children('ul').removeClass('noscript_visible').show(300);
		});

		// Sitemap Schlieen Event oberste Ebene
		$('.sitemap_liste_close_link').attr('href','javascript:void(null);').bind("click", function() {
			var $li = $(this).closest('li');
			$li.find('.sitemap_liste_open_img').attr('src', Config.images.sitemapOpenConnectionActive);
			$li.find('.sitemap_liste_close_img').attr('src', Config.images.sitemapCloseConnectionInactive);
			$li.children('ul').hide(300);
		});

		var sub_open_close_html = '<img src="' + Config.images.sitemapOpenSub + '" class="sitemap_liste_sub_img" title="' + alttext[3] + '" alt="' + alttext[4] + '" />';

		$('.sitemap_liste li').find('ul').each(function() {
			var $li = $(this).hide().closest('li');

			$li.children('a').after(sub_open_close_html);
			$li.children('.sitemap_liste_sub_img').bind("click", function() {
				var $this = $(this);

				$this.attr('title', alttext[2]);
				$this.attr('src', function() {
					if($this.attr('src') == Config.images.sitemapCloseSub) {
						$this.attr('title', alttext[3]);
						$this.attr('alt', alttext[3]);
						return Config.images.sitemapOpenSub;
					} else {
						$this.attr('title', alttext[4]);
						$this.attr('alt', alttext[4]);
						return Config.images.sitemapCloseSub;
					}
				});

				$this.closest('li').children('ul').toggle(300);
			});
		});

		var preloadImages = new Array(
			 Config.images.sitemapOpenConnectionActive,
			 Config.images.sitemapOpenConnectionInactive,
			 Config.images.sitemapCloseConnectionActive,
			 Config.images.sitemapCloseConnectionInactive,
			 Config.images.sitemapOpenSub,
			 Config.images.sitemapCloseSub
		);

		for(var i=0; i < preloadImages.length; i++)
		{
			var preloadImage = new Image();
			preloadImage.src = preloadImages[i];
		}


	// ##### Sitemap initialisieren Ende #####
});

function loadGMap() {
	 $.getScript("http://maps.google.com/maps/api/js?sensor=false&callback=googleMapsLibraryLoaded");
}

function gmap_label()
{
	if(document.getElementById('pane_5') && $('.installer_vcard_left').length == $('#pane_5 div').length)
	{
		// Hinzufuegen einer Zahl auf dem Symbol
		$('#pane_5 div').each(function() {
			$(this).append('<span class="gmap_label">' + $(this).attr('title') + '</span>');
		});
	}
	else window.setTimeout('gmap_label();',200);
}

function gmap_infowindow_style()
{
	if(document.getElementById('pane_6') && $('img[src="http://maps.gstatic.com/intl/en_us/mapfiles/iw_close.gif"]').length > 0)
	{
		// Aendern des Schlie�en-Knopfs bei den Bubbles
		$('img[src="http://maps.gstatic.com/intl/en_us/mapfiles/iw_close.gif"]').each(function() {
			$(this).attr('src', Config.images.googleMapsClose).width(18).height(18).css('visibility','visible');
		});
	}
	else window.setTimeout('gmap_infowindow_style();',200);
}

function googleMapsLibraryLoaded(object_id)
{
	$('#googlemap').css('height','25em');

	markers = new Array();
	geocoder = new google.maps.Geocoder();
	map = new google.maps.Map($('#googlemap')[0],{
		zoom: 11,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	});

	// Ausschnitt positionieren
	if(geocoder)
	{
		$('.beige_box .installer_vcard_left').each(function() {
			var address = $('.start-street-address').text() + ' ' + $('.start-locality').text();
			markers[address] = new Object();
			markers[address].abbr = $(this).find('.gmap_number').text() + '';
			markers[address].content = $(this).closest('div').html()
			geocoder.geocode({'address': address}, function(results, status)
			{
				if (status == google.maps.GeocoderStatus.OK)
				{
					map.setCenter(results[0].geometry.location);
					var latlng = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());

					var image = new google.maps.MarkerImage(Config.images.googleMapsMarkerSC,
					// This marker is 20 pixels wide by 32 pixels tall.
					new google.maps.Size(32, 47),
					// The origin for this image is 0,0.
					new google.maps.Point(0,0),
					// The anchor for this image is the base of the flagpole at 0,32.
					new google.maps.Point(16,0));

					var contentString = '<div class="gmap_content">' + markers[address].content + '</div>';

					var infowindow = new google.maps.InfoWindow({
						content: contentString,
						maxWidth: 175
					});

					var marker = new google.maps.Marker({
						position: latlng,
						icon: image,
						map: map,
						title: markers[address].abbr
					});

					google.maps.event.addListener(marker, 'click', function() {
						infowindow.open(map,marker);
						gmap_infowindow_style();
					});
				}
			});
		});

		$('.installer_searchresults .installer_vcard_left').each(function() {
			var address = $(this).find('.street-address').text() + ' ' + $(this).find('.locality').text();
			markers[address] = new Object();
			markers[address].abbr = $(this).find('.gmap_number').text() + '';
			markers[address].content = $(this).closest('li').html()
			geocoder.geocode({'address': address}, function(results, status)
			{
				if (status == google.maps.GeocoderStatus.OK)
				{
					var latlng = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());

					var image = new google.maps.MarkerImage(Config.images.googleMapsMarker,
					// This marker is 20 pixels wide by 32 pixels tall.
					new google.maps.Size(32, 44),
					// The origin for this image is 0,0.
					new google.maps.Point(0,0),
					// The anchor for this image is the base of the flagpole at 0,32.
					new google.maps.Point(16,0));

					var contentString = '<div class="gmap_content">' + markers[address].content + '</div>';

					var infowindow = new google.maps.InfoWindow({
						content: contentString,
						maxWidth: 175
					});

					var marker = new google.maps.Marker({
						position: latlng,
						icon: image,
						map: map,
						title: markers[address].abbr
					});

					google.maps.event.addListener(marker, 'click', function() {
					  	infowindow.open(map,marker);
						gmap_infowindow_style();
					});
				}
			});
		});
	}

	gmap_label();

	$(document).bind("unload", function() {
		google.maps.Unload();
	});
}

function lightbox_open(content) {
	$().modaldialog(content, {fadeInTime : 250, fadeOutTime : 250, canvasColor : "black"});
}
/* ##### Funktion erst einmal deaktiviert
function initFinder() {
	var offset = $('#finder_column_out').offset();
	var parent = $('#finder_column_out').parent();

	$('#finder_column_out')
		.bind("mouseenter", function() {
			showFinder();
		})
		.appendTo('body')
		.css({
			top      : offset.top,
			left     : offset.left,
			position : "absolute",
			zIndex   : 350
		});

	updateFinder();

	$('#finder_column_out')
		.find('*[class^="finder_column_"]')
		.find('select')
		.change(function() {updateFinder();});

	$(window).resize(function() {
		$('#finder_column_out').css("left", $(parent).offset().left);
	});
}

function showFinder() {
	$('#finder_column_out').css("height","auto");
	$('#finder_column_out').addClass("finder_column_active");
	$('.finder_button_column').css("display","block");
}

function hideFinder() {
	$('#finder_column_out').css("height",64);
	$('#finder_column_out').removeClass("finder_column_active");
	$('.finder_button_column').css("display","none");
}

function resetFinder() {
	var selects = $('#finder_column_out')
		.find('*[class^="finder_column_"]')
		.find('select');

	var first = true;

	selects.each(function() {
		if(!first) {
			$(this).closest("li").hide();
		} else first = false;

		$(this).find('option:selected').removeAttr('selected');
		$(this).find('option:[value=""]').attr('selected','selected');
	});

	updateFinder();
}

function updateFinder() {
	var previous = true;

	var selects = $('#finder_column_out')
		.find('*[class^="finder_column_"]')
		.find('select');

	selects.each(function() {
		if(previous) {
			$(this).closest("li").show();
			if($(this).val() != "") {
			}
			previous = $(this).val() != "" ? true : false;
		} else {
			$(this).closest("li").hide();
		}
	});
}

##### Funktion erst einmal deaktiviert */
function switchListMode(obj,mode) {
	/*var image_grid = $(obj).closest('.products_list_top').find("img[src*=icon_grid]");
	var image_list = $(obj).closest('.products_list_top').find("img[src*=icon_list]");

	console.log($(obj),$(obj).closest('.products_list_top'), image_grid, image_list);*/

	if(mode == "grid") {
		$('#products_list_changeable').removeClass('products_list_list');
		$('#products_list_changeable').addClass('products_list_grid');
		image_grid.src = image_grid.src.replace("_inact","_act");
		image_list.src = image_list.src.replace("_act","_inact");
	} else {
		$('#products_list_changeable').removeClass('products_list_grid');
		$('#products_list_changeable').addClass('products_list_list');
		image_grid.src = image_grid.src.replace("_act","_inact");
		image_list.src = image_list.src.replace("_inact","_act");
	}
}

/* Funktion zum Switchen zwischen Grid und List */
//src_list = $('#switch_list_button').attr('src');
//src_grid = $('#switch_grid_button').attr('src');
$('#switch_list').bind("click", function() {
	$('#product_list_holder').removeClass("products_list_grid");
	$('#product_list_holder').addClass("products_list_list");
	/*
	$('#switch_list_button').attr('src',src_list.replace('_inact', '_act'));
	$('#switch_grid_button').attr('src',src_grid.replace('_act', '_inact'));
	*/
	$('#switch_list').addClass('list_button_act');
	$('#switch_grid').removeClass('grid_button_act');
});
$('#switch_grid').bind("click", function() {
	$('#product_list_holder').removeClass("products_list_list");
	$('#product_list_holder').addClass("products_list_grid");
	/*
	$('#switch_list_button').attr('src',src_list.replace('_act', '_inact'));
	$('#switch_grid_button').attr('src',src_grid.replace('_inact', '_act'));
	*/
	$('#switch_grid').addClass('grid_button_act');
	$('#switch_list').removeClass('list_button_act');
});

/* Funktion zum Auf- und Zuklappen der Detailbeschreibung in der Produktliste Shop */
$('.shop_listing_desc .button_container').bind("click", function() {
	var $textbutton = ($(this).attr('id'));
	var $textcont = ('text_' + $(this).attr('id'));

	if ($('#'+$textcont).is(':visible')) {
		$('#'+$textbutton +' .button_main span').removeClass("button_minus_links");
		$('#'+$textbutton +' .button_main span').addClass("button_plus_links");
		//$('#'+$textbutton +' .button_main span').html("More");
		$('#'+$textbutton +' .button_main span').html("Mehr");
		//$('#'+$textbutton).attr("title","More");
		$('#'+$textbutton).attr("title","Mehr");
		$('#'+$textcont).removeClass("text_hidden_show");
	}
	else {
		$('#'+$textbutton +' .button_main span').removeClass("button_plus_links");
		$('#'+$textbutton +' .button_main span').addClass("button_minus_links");
		//$('#'+$textbutton +' .button_main span').html("Close");
		$('#'+$textbutton +' .button_main span').html("Weniger");
		//$('#'+$textbutton).attr("title","Close");
		$('#'+$textbutton).attr("title","Weniger");
		$('#'+$textcont).addClass("text_hidden_show");
		$('#'+$textcont).removeClass("noscript_visible");
	}
});
function closealllightbox() {
	$('#box_lightbox').hide();
	$('#canvas').hide();
}