jQuery.noConflict();

function externalLinks() {
	if (!document.getElementsByTagName)
		return;
	var anchors = document.getElementsByTagName("a");
	for ( var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href")
				&& anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}
function inputValueEvent() {
	var inputText = jQuery('#GW input.text').val();
	jQuery('#GW input.text').click(function() {
		if (inputText == "z.B. GEHOLIT-K25-Metallgrund") {
			jQuery(this).attr("value", "");
		}
	});
	jQuery('input.text').focusin(function() {
		jQuery(this).css("color", "#000");
	});
	jQuery('input.text').focusout(function() {
		jQuery(this).css("color", "#999");
	});
	jQuery('#GW input.text').blur(function() {
		if (jQuery(this).val() == "") {
			jQuery(this).attr("value", inputText);
		} else {
			inputText = jQuery(this).val();
			jQuery(this).attr("value", inputText);
		}
	});
}
function changeLangParamInSearch() {
	var lang = jQuery('html').attr('lang');
	switch (lang) {
	case 'en':
		var aurl = '/index.php?id=301&L=4&tx_indexedsearch[sword]';
		break;
	case 'fr':
		var aurl = '/index.php?id=301&L=5&tx_indexedsearch[sword]';
		break;
	case 'pl':
		var aurl = '/index.php?id=301&L=6&tx_indexedsearch[sword]';
		break;
	default:
		var aurl = '/index.php?id=301&L=0&tx_indexedsearch[sword]';
	}
	jQuery('#searchpanel form').attr('action', aurl);
}
function lightbox() {
	jQuery('div.content.left a img').each(function(index) {
		var atag = jQuery(this).parent('a');
		var href = atag.attr("href");
		var parts = href.split(".");
		if (parts[parts.length - 1] == "jpg"
			|| parts[parts.length - 1] == "png"
			|| parts[parts.length - 1] == "gif") {
				atag.attr('rel', 'lightbox');
				atag.append('<img alt="plus" src="/fileadmin/templates/img/plus.gif" class="plus">');
		}
	});

	jQuery('div.content.left .csc-frame-frame2 a img.plus').each(function(index) {
		var atag = jQuery(this).parent('a');
		atag.attr('rel', '');
	});

	jQuery(function() {
		jQuery('a[rel*=lightbox]').lightBox();
	});
}
function langSwitcher() {
	jQuery('#sprache').hover(function() {
		jQuery(this).find('li').css('display', 'block');
		jQuery(this).find('ul').css('border', '1px solid #ccc');
	}, function() {
		jQuery(this).find('li').css('display', 'none');
		jQuery(this).find('ul').css('border', '0');
	});
}
function searchSwitcher() {
	jQuery('#wrapSubmit').hover(function() {
		jQuery('#searchSwitcherWrap').css('display', 'block');
	}, function() {
		jQuery('#searchSwitcherWrap').css('display', 'none');
	});
}
function setVolltextSuche() {
	changeLangParamInSearch();
	jQuery('#searchpanel form').attr('method', 'post');
	jQuery('#searchpanel input.text').attr('name', 'tx_indexedsearch[sword]');
}
// function setSucheInDokumenten() {
// 	jQuery('#searchpanel form').attr('method', 'get');
// 	jQuery('#searchpanel form').attr('action', '/suchergebnisse');
// 	jQuery('#searchpanel input.text').attr('name', 'keywords');
// }
function setSucheSonderprodukte() {
	jQuery('#searchpanel form').attr('method', 'get');
	jQuery('#searchpanel form').attr('action', '/metanavigation/dokumente/technische-informationen-und-sicherheitsdatenblaetter/');
	jQuery('#searchpanel input.text').attr('name', 'keywords');
}
function accordion() {
	jQuery("div#GW.pna").accordion({
		collapsible : true,
		autoHeight : false,
		change : function() {
			jQuery(this).find('h3').blur();
		}
	});
	jQuery("div#accordionChapter").accordion({
		active : false,
		collapsible : true,
		autoHeight : false,
		change : function() {
			jQuery(this).find('h2').blur();
		}
	});
	jQuery("div.accordionSection").accordion({
		active : false,
		collapsible : true,
		autoHeight : false,
		change : function() {
			jQuery(this).find('h3').blur();
		}
	});
}
function searchMode() {
	jQuery('#searchMode').change(function(){
		var searchMode = jQuery(this).find("input:checked").attr("value");
		switch (searchMode) {
		case "volltext":
			setVolltextSuche();
			break;
		case "sonderprodukte":
			setSucheSonderprodukte();
			break;
// 		default:
// 			setSucheInDokumenten();
// 			break;
		}
	});
}
function openNachFarbenZeile() {
	jQuery('#GW').find('a.nachfarben').each(function() {
		var multiColor = jQuery(this).parent().parent().next(".multiColor");
		jQuery(this).toggle(function() {
			jQuery(multiColor).attr("class", "multiColor open");
		}, function() {
			jQuery(multiColor).attr("class", "multiColor");
		});
	});
}


jQuery(document).ready(function() {
	searchMode();
	searchSwitcher();
	accordion();
	langSwitcher();
	lightbox();
	inputValueEvent();
	externalLinks();
	openNachFarbenZeile();
});
