var contentadmin = null;
var lastSel = 0;
var currentURL = '';
var ceInsPos = 0;
var ceInsType = 0;
var ceInsCol = 0;
var ceDelId = 0;
var currentSearchOption = 'search1';
//var custom_imgheight=0;

$(document).ready(function() {
	// Intext slideshow BEGIN
	$('.intext-slideshow .csc-textpic-imagewrap').css({position: 'relative', height: '275px', float: 'left'});
	$('.intext-slideshow .csc-textpic-imagewrap').append('<div class="intext_scroll_left"><img title="" alt="" src="fileadmin/g-u/templates/images/gallery_back_small.gif" /></div><div class="intext_scroll_right"><img title="" alt="" src="fileadmin/g-u/templates/images/gallery_next_small.gif" /></div>');
	
	$('.intext-slideshow .csc-textpic-imagerow').css({position: 'absolute', left: '0px', top: '0px', display: 'none'});
	$('.intext-slideshow').find('.csc-textpic-imagerow:first').css({display: 'block'});

	

	$('.intext_scroll_left').click(function() {
		imgs = $(this).parent().find('.csc-textpic-imagerow');
		imgcount = imgs.length;
		imgsi = 0;
		imgs.each(function(){ 
			if ($(this).css('display') === 'block') {
				$(this).fadeOut('fast');
				if (imgsi === 0) {
					// Show last img
					$(imgs[(imgcount-1)]).fadeIn('slow');
					return false;
				} else {
					// Show previous
					$(imgs[(imgsi-1)]).fadeIn('slow');
					return false;					
				}
			}
			imgsi++;
		});		
	});
	$('.intext_scroll_right').click(function() {
		imgs = $(this).parent().find('.csc-textpic-imagerow');
		imgcount = imgs.length;
		imgsi = 0;
		imgs.each(function(){ 
			if ($(this).css('display') === 'block') {
				$(this).fadeOut('fast');
				if (imgsi === imgcount-1) {
					// Show first img
					$(imgs[0]).fadeIn('slow');
					return false;
				} else {
					// Show next
					$(imgs[(imgsi+1)]).fadeIn('slow');
					return false;					
				}
			}
			imgsi++;
		});
	});			
	// Intext slideshow END
	
	// Dropdowns BEGIN
	$.fn.IELongDropDown = function(cln) {
		if (jQuery.browser.msie) { //only IE has problems with long select boxes
			var el = this;
			var previousWidth = el.width();
			var divWrapper = "<div style='padding:0;margin:0;overflow:hidden;width:"+ previousWidth +"px'></div>";
			el.wrap(divWrapper);
			var newWidth = el.width("auto").width();
			el.width(previousWidth);
			if(newWidth > previousWidth) {
				el.bind("mousedown", function(){ return el.width("auto").focus(); }); 
				el.bind("blur", function(){ return el.width(previousWidth); });
				el.bind("change", function(){ return el.width(previousWidth); });
			}
		}
		return this;
	};
	$("select").each(function(){ 
		$(this).IELongDropDown(); 
	});
	// Dropdowns END

	// Rotate header images BEGIN
	function rotateImages(y) {
		$.each(headerimgs, function(key, val) {
			if (key !== y) {
				$(val).fadeOut(4000);
			}else{
				$(val).fadeIn(4000);
			}
		});
	}
	
	var headerimgs = $(".headerImageItem").hide();
	var y=1;
	rotateImages(0);
	
	$(document).everyTime('10s', 'hiTimer', function() {
		if (y >= headerimgs.length) {
			y = 0;
		}
		rotateImages(y);
		y++;
	});
	// Rotate header images END
	
	// Standorte BEGIN
	$('#stregion').change(function() {
		$('#stcountry').val("");
		$('#standorteform').submit();
	});
	$('#stcountry').change(function() {
		$('#standorteform').submit();
	});
	// Standorte END
		
	// References BEGIN
	function opensearch() {
		$("#refSearchform").slideDown('slow',function() {
			$("#refSearch_close").hide();			
			$("#refSearch_open").fadeIn('slow');
			setColCenterHeight();
		});
	}
	function closesearch() {
		$("#refSearchform").slideUp('slow',function() {
			$("#refSearch_open").hide();
			$("#refSearch_close").fadeIn('slow');
			setColCenterHeight();
		});	
	}
	$("#openSearch").click(function() {
		opensearch();
	});
	$("#closeSearch").click(function() {
		closesearch();
		$("#opensearchtab").removeClass("active");
	});
	$(".refSearchTab").click(function() {
		if (!$(this).hasClass("active")) {
			$(this).parent().find(".refSearchTab").removeClass("active");
			$(this).addClass("active");

			if ($(this).attr("id")==="opensearchtab") {
				opensearch();
			} else {
				if ($(this).attr("id")==="tabinternational") {
					$("#countrydrop").slideDown('fast');
					$("#reftab").val("international");
					$("#catchwordindexLayer").css("top","150px");
				} else {
					$("#countrydrop").slideUp('fast');
					$("#reftab").val("national");
					$("#catchwordindexLayer").css("top","120px");
				}
			}
		} else {
			if ($(this).attr("id")==="opensearchtab") {
				closesearch();
			}		
		}
	});
	//$("input[name='tx_indexedsearch[sword]']").indexedsearchAutocomplete("http://" + top.location.host + top.location.pathname + "?eID=cb_indexedsearch_autocomplete&sr=" + sr + "&sh=" + sh + "", { minChars:3, matchSubset:1, matchContains:1, cacheLength:10, selectOnly:1 });
	/*$("#tx-indexedsearch-searchbox-sword").indexedsearchAutocomplete(
		"http://" + top.location.host + top.location.pathname + "?eID=cb_indexedsearch_autocomplete&sr=" + sr + "&sh=" + sh + "",
		{ minChars:3, matchSubset:1, matchContains:1, cacheLength:10, selectOnly:1 }
	);*/
	
	var actimage = 1;
	var imagecount = $("#referenceDetailImagesSlider IMG").size();
	$("#rdi_last").click(function() {
		if (actimage===1) {
			slideto = imagecount; 
		} else {
			slideto = actimage-1;
		}
		$("#imagenumb").html(slideto);
		$(".image_"+actimage).hide();
		$(".image_"+slideto).fadeIn("slow");
		actimage = slideto;
	});
	$("#rdi_next").click(function() {
		if (actimage===imagecount) {
			slideto = 1; 
		} else {
			slideto = actimage+1;
		}
		$("#imagenumb").html(slideto);
		$(".image_"+actimage).hide();
		$(".image_"+slideto).fadeIn("slow");
		actimage = slideto;
	});
	
	$("#catchwordindex").click(function() {
		$("#catchwordindexLayer").fadeIn("fast");
	});
	$("#catchwordindexClose").click(function() {
		$("#catchwordindexLayer").fadeOut("fast");
	});
	$(".cwentry").click(function() {
		$("#catchwordinput").val($(this).html());
		$("#catchwordinputid").val($(this).attr("id").replace('cid_',''));
		$("#catchwordindexLayer").fadeOut("fast");
	});
	// References END
		
	// Accordion BEGIN
	$('#accordion .toggler').click(function() {
		if ($(this).css('background-position')==='211px 6px' || $(this).css('background-position-y')==='6px') {
			$(this).css('background-position','211px -86px');
			$(this).next().slideDown('slow',function() {
				setColCenterHeight();
			});		
		} else {
			$(this).css('background-position','211px 6px');
			$(this).next().slideUp('slow',function() {
				setColCenterHeight();
			});
		}
		
		return false;
	});
	$('#accordion_center .toggler').click(function() {
		if ($(this).css('background-position')==='505px 10px' || $(this).css('background-position-y')==='10px') {
			$(this).css('background-position','505px -82px');
			$(this).next().slideDown('slow',function() {
				setColCenterHeight();
			});		
		} else {
			$(this).css('background-position','505px 10px');
			$(this).next().slideUp('slow',function() {
				setColCenterHeight();
			});
		}
		
		return false;
	});
	
	$('.dlLayer').dialog({
		autoOpen:	false,
		modal:		true,
		width:		567,
		minWidth:	567
	});
	$('UL.download-link-list DIV.dllink').click(function() {
		id = this.id.replace('dl2_','');
		$('#dl2_layer_'+id).dialog({ title: $('#dl2_layer_'+id+' TABLE').attr("title") });
		$('#dl2_layer_'+id).dialog('open');
	});
	// Accordion END
	
	//Cache-Message BEGIN	
	$('#dlg-cache-message').dialog({
		autoOpen:	true,
		modal:		true,
		width:		200,
		minWidth:	200
	});
	//Cache-Message END
	
	// Login BEGIN
	$('#loginBox .toggler').click(function() {
		if ($(this).css('background-position')==='160px 6px' || $(this).css('background-position-y')==='6px') {
			$(this).css({'background-position':'160px -86px','background-color':'#dbdbdb'});
			$(this).next().css({'background-color':'#dbdbdb'}).slideDown('slow',function() {
				setColCenterHeight();
			});
		} else {
			$(this).css({'background-position':'160px 6px','background-color':'#cccccc'});
			$(this).next().css({'background-color':'#cccccc'}).slideUp('slow',function() {
				setColCenterHeight();
			});
		}
		return false;
	});

	var loginButtonText = $('#loginbutton').val();
	if (loginButtonText && loginButtonText.indexOf(' ')>0 && loginButtonText.length>10 && $.browser.msie && $.browser.version=='7.0') {
		$('#loginbutton').val(loginButtonText.replace(' ',"\n"));
		$('#loginbutton').css('height','30px');
	}

	function disableLoginButton() {
		$("#loginbutton").attr("disabled",true);
	}
	function chkLoginForm() {
		//alert("Das System ist derzeit wegen Wartungsarbeiten nicht erreichbar.\\nThe system is unavailable due to maintanance issues.");
		returnvalue = true;
		if ($("#authAction").val() === "logout") {
			disableLoginButton();
			returnvalue = true;
		}
		if ($("#ssodebitor").val()==="" && ($("#ssoname").val()==="" || $("#ssoname").val()===$("#ssoname").attr("alt"))) {
			$('#inputmissingerror').fadeIn('slow');
			returnvalue = false;
		} else {
			$('#inputmissingerror').fadeOut('slow');
		}
		if ($("#ssopasswd").val()==="" || $("#ssopasswd").val()===$("#ssopasswd").attr("alt")) {
			$('#pwmissingerror').fadeIn('slow');
			returnvalue = false;
		} else {
			$('#pwmissingerror').fadeOut('slow');
		}
		if (returnvalue === false) {
			$('#ssodebitor').val($('#ssodebitor').attr('alt'));
		}
		return returnvalue;
	}	
	function submitLogin() {
		value = $('#ssodebitor').val();
		alt = $('#ssodebitor').attr('alt');
		if ($.trim(value) === $.trim(alt)) {
			$('#ssodebitor').val('');
		}
		value = $('#ssoname').val();
		alt = $('#ssoname').attr('alt');
		if ($.trim(value) === $.trim(alt)) {
			$('#ssoname').val('');
		}	
		error = chkLoginForm();
		if (error) {
			$('#frmGULogin').submit();
		}
	}
	
	$('#ssodebitor, #ssoname').focus(function() {
		value = $(this).val();
		alt = $(this).attr('alt');
		if ($.trim(value) === $.trim(alt)) {
			$(this).val('');
		}
	});
	$('#ssodebitor, #ssoname').blur(function() {
		value = $(this).val();
		if ($.trim(value) === '') {
			$(this).val($(this).attr('alt'));
		}
	});
	$('#ssopasswd').focus(function() {
		$('#pwtext').hide();
	});
	$('#ssopasswd').blur(function() {
		value = $(this).val();
		if ($.trim(value) === '') {
			$('#pwtext').show();
		}
	});
	$('#pwtext').click(function() {
		$('#pwtext').hide();
		$('#ssopasswd').focus();
	});
	$('#login INPUT').keyup(function(e) {
		if(e.keyCode === 13) {
			submitLogin();
		}
	});
	$('#loginbutton').click(function() {
		submitLogin();
	});		
	// Login END

	// Search BEGIN
	$('#searchBox .toggler').click(function() {
		if ($(this).css('background-position')==='160px 6px' || $(this).css('background-position-y')==='6px') {
			$(this).css({'background-position':'160px -86px','background-color':'#dbdbdb'});
			$(this).next().css({'background-color':'#dbdbdb'}).slideDown('slow',function() {
				setColCenterHeight();
			});
		} else {
			$(this).css({'background-position':'160px 6px','background-color':'#cccccc'});
			$(this).next().css({'background-color':'#cccccc'}).slideUp('slow',function() {
				setColCenterHeight();
			});
		}
		return false;
	});
	/*$('#searchBoxMenu .searchBoxButtonWrapper').click(function() {
		id = this.id.replace('_m','');
		$('.searchBoxLayer').hide();
		$('#'+id).fadeIn('slow');
		$('.searchBoxButtonWrapper').removeClass('act');
		$(this).addClass('act');
		var height = $('#searchBoxContent').height()+38;
		$("#searchBox").animate({height: height+'px'},100);
	});*/
	$('#searchBox INPUT').focus(function() {
		value = $(this).val();
		alt = $(this).attr('alt');
		if ($.trim(value) === $.trim(alt)) {
			$(this).val('');
		}
	});
	$('#searchBox INPUT').blur(function() {
		value = $(this).val();
		if ($.trim(value) === '') {
			$(this).val($(this).attr('alt'));
		}
	});
	function submitlocatorform() { 
		var cityvalue = $('#tx_locator_pi1_city').val();
		var zipvalue = $('#tx_locator_pi1_zipcode').val();
		if ($.trim(cityvalue) !== '' && cityvalue !== $('#tx_locator_pi1_city').attr('alt')) {
			$('#tx_locator_pi1_zipcode').val('');
			$('#locator').submit();
		} else if ($.trim(zipvalue) !== '' && zipvalue !== $('#tx_locator_pi1_zipcode').attr('alt')) {
			$('#tx_locator_pi1_city').val('');
			$('#locator').submit();		
		} else {
			$('#tx_locator_pi1_city').css('color','red');
		}
	}	
	$('.dealersubmit').click(function() {
		submitlocatorform();
	});
	$('#searchBox .tx-locator-pi1 INPUT').keyup(function(e) {
		if(e.keyCode === 13) {
			submitlocatorform();
		}
	});
	
	function submitsearch() {
		$('#tx-solr-search-form-pi-results').submit();	
	}
	$('.searchsubmit').click(function() {
		submitsearch();
	});	
	$('#searchBox #tx-solr-search-form-pi-results INPUT').keyup(function(e) {
		if(e.keyCode === 13) {
			submitsearch();
		}
	});
	// Search END

	// Fancybox BEGIN
	$("a.fancybox").fancybox({
		'hideOnContentClick': true
	});

	$("a.fancyboxMultiple").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'overlayOpacity':	0.7,
		'overlayColor'	:	'#eaf3f9',
		'cyclic'		:	true,
		'showNavArrows'	:	true,
		'titlePosition'	:	'over'
	});
	

	$("a.fancyboxClickenlarge").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'overlayOpacity':	0.7,
		'overlayColor'	:	'#eaf3f9',
		'cyclic'		:	true,
		'showNavArrows'	:	true,
		'titlePosition'	:	'over'
	});
	// Fancybox END
		
	// Product page BEGIN
	function reflect_mainimage() {
		$(".product-images .mainimage").reflect({
			'height'	: 65,
			'opacity'	: 0.4
		});
		$(".reflection .mainimage").reflect({
			'height'	: 65,
			'opacity'	: 0.4
		});
		$(".reflection .mainimage2").reflect({
			'height'	: 65,
			'opacity'	: 0.4
		});
		if (typeof(custom_imgheight)!=='undefined' && custom_imgheight>0) {
			$('#addimages').css('top',(custom_imgheight+2)+'px');
			$('#colCpad h4').css('clear','both');
			$('#colCpad div:nth-child(4) h4').css('clear','both');
			//$('#colCenter div:nth-child(8) ul').css('margin-left',0);
		}
	}	
	$(".addimg").click(function() {
		$(".addimg").removeClass("active");
		$(this).addClass("active");
			
		clickedimg = $(this).find("IMG");
		clickedid = $(this).attr('id');
		imagesrc = clickedimg.attr('src');
		imagetitle = clickedimg.attr('title');
		newhref = $('#lb_'+clickedid).find('A').attr('href');
		
		$('#addimages .addimg A').attr('rel','imagegroup1');	// set imagegroup to all
		$('#lb_'+clickedid+' A').removeAttr('rel');				// remove imagegroup on active image to avoid duplication on fancybox
		
		// clone image for animation to mainimageframe
		tempimg = clickedimg.clone();
		tempimg.attr("id","tempimg");
		tempimg.css("position", "absolute");
		tempimg.css("top", "0px");
		tempimg.css("left", ((clickedid.replace('img','')-1)*61)+"px");		
		tempimg.css('border', '0px none');
		tempimg.appendTo($(this).parent());
		
		$("#tempimg").animate({
			width	: 248,
			height	: 199,
			top		: "-208px",
			left	: "0px"
		},500,function() {
			// Animation complete
			$(".mainimage IMG").attr('src',imagesrc);
			$(".mainimage IMG").attr('title',imagetitle);
			$(".mainimage").parent().attr('href',newhref);
			$(".mainimage").parent().attr('title',imagetitle);
			$("#tempimg").remove();		
			$(".mainimage IMG").unreflect();
			reflect_mainimage();
		});
	});
	reflect_mainimage();

	if ($('.customimgrel').length > 0) {
		var imgwidth = $('.customimgrel .mainimage').css('width');
		if (imgwidth!='undefined') {
			imgwidth = parseInt(imgwidth.replace('px',''));
			$('.customimgrel ul').css('width',(500-imgwidth)+'px');
		}
	}
	// Product page END		
	
	// Index product page BEGIN
	$(".indexteaseranimation").mouseenter(function() {
		$(this).css("backgroundColor","#e6ecf5");
	});
	$(".indexteaseranimation").mouseleave(function() {
		$(this).css("backgroundColor","transparent");
	});
	// Index product page END	
	
	// Page length BEGIN
	var colCenterminHeight = $('#colCenter').height();
	function setColCenterHeight() {
		//if (contentadmin == false) {
			colleftheight = $('#colLeft').height();
			colrighttheight = $('#colRight').height();
			colcenterheight = $('#colCenter').height();
			//if (document.getElementById('colCpad').style.height) {
				mcolCpadH = $('#colCpad').height();
			//} else {
			//	mcolCpad = 500;
			//}
		
			if (colleftheight > colrighttheight) {
				maxheight = colleftheight;
			} else {
				maxheight = colrighttheight;
			}
			if (mcolCpadH > maxheight) {
				maxheight = mcolCpadH+40;
			}
				
			//console.log("Colleft: "+colleftheight+" / ColCenter: "+colcenterheight+" / Colright: "+colrighttheight+" / mcolCpadH: "+mcolCpadH+" / Max height: "+maxheight+" / MinHeight: "+colCenterminHeight);
			//alert("Colleft: "+colleftheight+" / ColCenter: "+colcenterheight+" / Colright: "+colrighttheight+" / ColCPad: "+colCpad+" / Max height: "+maxheight+" / MinHeight: "+colCenterminHeight);
			//if (maxheight > colcenterheight) {
			if (maxheight) {
				$('#colCenter').css('height',maxheight+'px');
				//console.log("Height set to "+maxheight+'px');
			} else {
				//if (colcenterheight > maxheight && colcenterheight > colCenterminHeight) {
				if (colcenterheight > maxheight) {
					$('#colCenter').css('height',colcenterheight+'px');
					//console.log("Height set to "+colcenterheight+'px');
				}
			}
		//}
	}
	if (!contentadmin) {
		setColCenterHeight();
		// Set height a second time after a second, because of images witch are not loaded yet
		$(document).everyTime('1s', 'secondheight', function() {
			colCenterminHeight = $('#colCenter').height();
			setColCenterHeight();
		},3);
	} 
	// Page length END
	
	// Content Admin Pagestructure BEGIN
	if (document.getElementById('pagestructure')) {
		getJsonPageStructure();
	}
	
	function setFunctionsRight() {
		scrollpos = $(window).scrollTop();
		if (scrollpos <= 0) {
			WscrollTo = 0;
		} else {
			WscrollTo = scrollpos-80;
		}	
		$('#functionsRight').animate({top: WscrollTo+'px'},100);
	}
	
	if ($('#functionsRight').length > 0) {
		setFunctionsRight();
		
		$(document).everyTime(300, 'FunctionsRight', function() {
			setFunctionsRight();
		});	
	}
	
	// Dummy return false for nodes
	$('#pagestructure UL LI A').click(function() {
		return false;
	});
	// Content Admin Pagestructure END	
	
		
	//$('.contenttable tbody tr:odd').addClass('odd');
	//$('.contenttable tbody tr:even').addClass('even');
	
	$('.contenttable tbody tr:nth-child(even)').addClass('odd');
	$('.contenttable tbody tr:nth-child(odd)').addClass('even');

	// erste Tabellenspalte fix auf 120px bei mehr als 4 Spalten
	// geht
	$('.contenttable').each(
		function(idx,el) {
			var trows = $(this).find('tr').length;
			var tcols = $(this).find('td').length / trows;
			if (tcols > 4) {
				$(this).find('thead td:first').addClass('labelcolumn');
			}
		}
	);
	
	// geht nicht: findet nur erstes Element
	//$('#colCpad').find('.contenttable thead td:first').addClass('labelcolumn');
	
	// Datepicker
	$('.datepicker').datepicker({ firstDay: 1, dateFormat: "dd.mm.yy", changeYear: true });
	datepickerpress = $('.pressarticlefilter').find('.datepicker');
	if ($(datepickerpress).length === 2) {
		today = new Date();
		$(datepickerpress[0]).datepicker( "option", "minDate", new Date(2006, 0, 1));
		$(datepickerpress[0]).datepicker( "option", "maxDate", new Date(today.getFullYear(), today.getMonth()-9, today.getDate()));
		$(datepickerpress[1]).datepicker( "option", "minDate", new Date(2006, 0, 1));
		$(datepickerpress[1]).datepicker( "option", "maxDate", new Date(today.getFullYear(), today.getMonth()-9, today.getDate()));
	}
			
	if (sitelang==='de') {
		$('.datepicker').datepicker( "option", "dayNames", ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'] );
		$('.datepicker').datepicker( "option", "dayNamesMin", ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'] );
		$('.datepicker').datepicker( "option", "dayNamesShort", ['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam'] );
		$('.datepicker').datepicker( "option", "monthNames", ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'] );
		$('.datepicker').datepicker( "option", "monthNamesShort", ['Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'] );
	}
	
	// Donwloads
	if($('#downloadlist').length > 0){
		$('#downloadlist').tabs({ show: function(event, ui) {
			setColCenterHeight();
		}});

		if (selecttab >= 0) {
			$('#downloadlist').tabs( "option", "selected", 'downloadcat-'+selecttab );
		}
		
		$("#downloadlist TR").mouseenter(function(){
				$(this).find("TD").css("backgroundColor","#e6ecf5");
		});
		$("#downloadlist TR").mouseleave(function(){
			if ($(this).attr("class")==='rowodd'){
				bgcolor = '#EAF3F9';
			}else{
				bgcolor = 'transparent';
			}
			$(this).find("TD").css("backgroundColor",bgcolor);
		});
	}
	
	$(".doktypefilter").change(function() {
		id = $(this).attr('id').replace('doktypefilter','');
		$('#doktypefilterform'+id).submit();
	});
	
	// Seminare
	if ($('#seminarlist').length > 0) {
		$('#seminarlist').tabs({ show: function(event, ui) {
			setColCenterHeight();
		}});
		if (selecttab >= 0) {
			$('#seminarlist').tabs( "option", "selected", 'seminartable-'+selecttab );
		}
		$("#seminarlist TR").mouseenter(function() {
			$(this).find("TD").css("backgroundColor","#e6ecf5");
		});
		$("#seminarlist TR").mouseleave(function() {
			if ($(this).attr("class")==='rowodd') {
				bgcolor = '#EAF3F9';
			} else {
				bgcolor = 'transparent';
			}
			$(this).find("TD").css("backgroundColor",bgcolor);
		});
	}
	// Jquery Dropdowns
	/*$("#jqdrop_audienceseminartable-1").jqDropDown({
		optionChanged: function() {
			console.log($(this).val());
			$('#audiencefilterform').submit();
		},
		direction: 'down'
	});*/
	$(".audiencefilter").change(function() {
		id = $(this).attr('id').replace('audiencefilter','');
		$('#audiencefilterform'+id).submit();
	});
	$(".locationfilter").change(function() {
		id = $(this).attr('id').replace('locationfilter','');
		$('#locationfilterform'+id).submit();
	});
	
	// Imagescroller right
	var actimage_scroller = 1;
	var imagecount_scroller = $("#imgscroller IMG").size()-2;
	$("#imgscroller #imgscroller_left").click(function() {
		if (actimage_scroller===1) {
			slideto = imagecount_scroller; 
		} else {
			slideto = actimage_scroller-1;
		}
		$("#img_"+actimage_scroller).hide();
		$("#img_"+slideto).fadeIn("slow");
		$("#cap_"+actimage_scroller).hide();
		$("#cap_"+slideto).fadeIn("slow");
		actimage_scroller = slideto;
	});
	$("#imgscroller #imgscroller_right").click(function() {
		if (actimage_scroller===imagecount_scroller) {
			slideto = 1; 
		} else {
			slideto = actimage_scroller+1;
		}
		$("#img_"+actimage_scroller).hide();
		$("#img_"+slideto).fadeIn("slow");
		$("#cap_"+actimage_scroller).hide();
		$("#cap_"+slideto).fadeIn("slow");
		actimage_scroller = slideto;
	});	
	
	// Download section
	$(".ffilter, .ffilter_last").change(function() {
		$("#filedownloadfilter").submit();
	});
	
	$('.csc-default:not(:has(*))').hide();
	
	$("#checkall").click(function() {
		var checked_status = this.checked;
		$(".checkall").each(function() {
			this.checked = checked_status;
		});
	});

	// Coverflow Sortierung
	$(".pi_data_element_move_up").click(function(){
			var toMove = $(this).parents(".pi_data_element");
			var myTarget = $(toMove).prev();
			$(myTarget).before(toMove);
			
			var inputRow = toMove.parents(".inputrow");
			ca_writeDataorder(inputRow);			
	});
	
	$(".pi_data_element_move_down").click(function(){
			var toMove = $(this).parents(".pi_data_element");
			var myTarget = $(toMove).next();
			$(myTarget).after(toMove);
			var inputRow = toMove.parents(".inputrow");
			ca_writeDataorder(inputRow);				
	});
	
	$(".pi_data_element_delete").click(function(){
			var toMove = $(this).parents(".pi_data_element");
			var inputRow = toMove.parents(".inputrow");
			toMove.remove();
			console.log(toMove);

			ca_writeDataorder(inputRow);							
	});
	
	// leere Elemente ausblenden
	$('#colRight .csc-default').each(function (idx,el) {
		if ($(el).find('.csc-text').html() == '') {
			$(el).css('display','none');
		}
	});
	
	// remove unwanted nbsp in h3 - esp. spanish problem
	$('h3.donthyphenate').each(function () {
		$(this).html($(this).html().replace('&nbsp;',' ').replace(/ kg/,'&nbsp;kg').replace(/ mm/,'&nbsp;mm').replace(/ cm/,'&nbsp;cm'));
	});

}); // jQuery document.ready end

// 
function ca_writeDataorder(inputRow) {
	var dataorder = new Array(), i = 0;
	
	$(inputRow).find(".pi_data_element").each(function(index){
		var currentId = $(this).attr('id');
		//var currentId = $(this).attr('id').split("_");
		dataorder[i++] = currentId;
		//dataorder[i++] = currentId[1];
	});
	console.log(dataorder);
	$(inputRow).find(".dataorder").val(dataorder.join(","));
	$(inputRow).find(".current").val(dataorder.join(","));
	
}



// Hyphenator BEGIN

// NOW EXCLUDED DUE TO LANG SPECIFIC CONF OF EXCEPTIONS!
// SEE typo3conf/ext/px_gu/scripts/hyphenator_init.php

/*if (!contentadmin) {	
	Hyphenator.config({
		classname: 'hyphenate', 
		donthyphenateclassname: 'donthyphenate',
		dohyphenation: true, 
		onerrorhandler: function(e) {console.log('Hyphenator: error ocurred! '+e.message);},
		remoteloading: false
	});
	Hyphenator.addExceptions('de','Flügel-gewicht'); 
	Hyphenator.run();
}*/
// Hyphenator END



// Content-Admin Functions BEGIN

var currentImages = new Array();
var currentFiles = new Array();
var currentLinks = new Array();

function addFileuploadField(orig_element, container_id, captionfield, captionfield_id) { 

	var inputelements = document.getElementById(container_id).getElementsByTagName("input").length;
	
	var inputelement = document.createElement("input");
	var ie_name = document.createAttribute("name");
	ie_name.nodeValue = orig_element.getAttribute("name");
	var ie_type = document.createAttribute("type");
	ie_type.nodeValue = "file";
	var ie_class = document.createAttribute("class");
	ie_class.nodeValue = "fileinput";
	inputelement.setAttributeNode(ie_name);
	inputelement.setAttributeNode(ie_type);
	inputelement.setAttributeNode(ie_class);
	inputelement.onchange = function() { 
		addFileuploadField(this, container_id); 
	};
	
	// gaerber
	var onC='ca_emptyUploadForm(this)';
	var trash = new Image();
	trash.src = '/typo3conf/ext/px_gu/res/ce-delete-element.gif';
	
	
	document.getElementById(container_id).appendChild(inputelement);
	document.getElementById(container_id).appendChild(trash);
	
	var inputelement = document.createElement("input");
	var ie_name = document.createAttribute("name");
	ie_name.nodeValue = captionfield_id;
	var ie_type = document.createAttribute("type");
	ie_type.nodeValue = "text";
	var ie_class = document.createAttribute("class");
	ie_class.nodeValue = "fileinput";
	inputelement.setAttributeNode(ie_name);
	inputelement.setAttributeNode(ie_type);
	inputelement.setAttributeNode(ie_class);
	inputelement.onchange = function() { 
		addFileuploadField(this, container_id); 
	};
	
	document.getElementById(container_id).appendChild(inputelement);
	
	// gaerber
	document.getElementById(container_id).lastChild.setAttribute('onclick','ca_emptyUploadForm(this)');
	
	var blub = document.getElementById(container_id).lastChild;
	
	document.getElementById(container_id).style.height = ((inputelements+1)*20)+"px";
}


function addFileuploadFieldPress(orig_element,input_ele) {
	$(orig_element).parent().append($(orig_element).html());
}


function ca_reorderImages(field_id,pid) {
	//alert(currentImages[field_id].join(', '));
	var newHTML = "";
	var i = 0;
	var lkdsjf = currentImages;
	
	var blub = $('#imagelist-'+field_id +' input').each(function(index,value){
		
			$(this).removeAttr('value');
			$(this).attr('value', 'hallo');
			//alert($(this).val());
		});

	for (i=0; i<currentImages[field_id].length; i++) {

		if (document.getElementById("previewimage-"+currentImages[field_id][i])) {
			newHTML += '<div id="previewimage-'+currentImages[field_id][i]+'">'+document.getElementById("previewimage-"+currentImages[field_id][i]).innerHTML+'</div>';
		} else {
			alert("previewimage-"+currentImages[field_id][i] + " does not exist");
		}
	}
	document.getElementById("imagelist-"+field_id).innerHTML = newHTML;
	document.getElementById("p"+pid+"_"+field_id+"_current").value = currentImages[field_id].join(',');
}

function ca_removeImage(field_id,img_index,pid,img_name) {
	var new_order = new Array();
	var j = 0;
	var i = 0;
	for (i=0; i<currentImages[field_id].length; i++) {
		if (img_name!==currentImages[field_id][i]) {
			new_order[j++] = currentImages[field_id][i];
		}
	}
	if (currentImages[field_id].length !== new_order.length) {
		currentImages[field_id] = new_order;
		ca_reorderImages(field_id,pid);
	}	
}

function ca_emptyUploadForm(myself) {
	
	var input = myself.previousSibling;
	if(input.value != '') {
		var parent = myself.parentNode;
		parent.removeChild(input);
		parent.removeChild(myself);
	}

}


function ca_moveImageUp(field_id,img_index,pid,img_name) {
	var changed = false;
	var i = 0;
	//alert(currentImages[field_id].join(', '));
	for (i=1; i<currentImages[field_id].length; i++) {
		if (img_name===currentImages[field_id][i]) {
			var tmp = currentImages[field_id][i-1];
			currentImages[field_id][i-1] = img_name;
			currentImages[field_id][i] = tmp;
			changed = true;
		}
	}
	if (changed) {
		ca_reorderImages(field_id,pid);
	}
}

function ca_moveImageDown(field_id,img_index,pid,img_name) {
	var changed = false;
	var i = 0;
	//alert(currentImages[field_id].join(', '));
	for (i=currentImages[field_id].length-1; i>=0; i--) {
		if (i<(currentImages[field_id].length-1) && img_name===currentImages[field_id][i]) {
			var tmp = currentImages[field_id][i+1];
			currentImages[field_id][i+1] = img_name;
			currentImages[field_id][i] = tmp;
			changed = true;
		}
	}
	if (changed) {
		ca_reorderImages(field_id,pid);
	}
}

function ca_reorderDownloads(field_id,pid) {
	//alert(currentFiles[field_id].join(', '));
	var newHTML = "";
	var i = 0;
	for (i=0; i<currentFiles[field_id].length; i++) {
		if (document.getElementById("previewimage-"+currentFiles[field_id][i])) {
			newHTML += '<div id="previewimage-'+currentFiles[field_id][i]+'">'+document.getElementById("previewimage-"+currentFiles[field_id][i]).innerHTML+'</div>';
		} else {
			alert("previewimage-"+currentFiles[field_id][i] + " does not exist");
		}
	}
	document.getElementById("imagelist-"+field_id).innerHTML = newHTML;
	document.getElementById("p"+pid+"_"+field_id+"_current").value = currentFiles[field_id].join(',');
}

function ca_removeDownload(field_id,img_index,pid,img_name) {
	var new_order = new Array();
	var j = 0;
	var i = 0;
	for (i=0; i<currentFiles[field_id].length; i++) {
		if (img_name!==currentFiles[field_id][i]) {
			new_order[j++] = currentFiles[field_id][i];
		}
	}
	if (currentFiles[field_id].length !== new_order.length) {
		//alert('remove file');
		currentFiles[field_id] = new_order;
		ca_reorderDownloads(field_id,pid);
	}
}

function ca_moveDownloadUp(field_id,img_index,pid,img_name) {
	var changed = false;
	var i = 0;
	//alert(currentFiles[field_id].join(', '));
	for (i=1; i<currentFiles[field_id].length; i++) {
		if (img_name===currentFiles[field_id][i]) {
			var tmp = currentFiles[field_id][i-1];
			currentFiles[field_id][i-1] = img_name;
			currentFiles[field_id][i] = tmp;
			changed = true;
		}
	}
	if (changed) {
		ca_reorderDownloads(field_id,pid);
	}
}

function ca_moveDownloadDown(field_id,img_index,pid,img_name) {
	var changed = false;
	var i = 0;
	//alert(currentFiles[field_id].join(', '));
	for (i=currentFiles[field_id].length-1; i>=0; i--) {
		if (i<(currentFiles[field_id].length-1) && img_name===currentFiles[field_id][i]) {
			var tmp = currentFiles[field_id][i+1];
			currentFiles[field_id][i+1] = img_name;
			currentFiles[field_id][i] = tmp;
			changed = true;
		}
	}
	if (changed) {
		ca_reorderDownloads(field_id,pid);
	}
}

function ca_reorderLinks(field_id,pid) {
	var newHTML = "";
	var i = 0;
	for (i=0; i<currentLinks[field_id].length; i++) {
		if (document.getElementById("pagelink-"+currentLinks[field_id][i])) {
			newHTML += '<div id="pagelink-'+currentLinks[field_id][i]+'">'+document.getElementById("pagelink-"+currentLinks[field_id][i]).innerHTML+'</div>';
		} else {
			alert("pagelink-"+currentLinks[field_id][i] + " does not exist");
		}
	}
	document.getElementById("linklist-"+field_id).innerHTML = newHTML;
}

function ca_removeLink(field_id,link_index,pid) {
	var link_id = pid+"_"+field_id+"_"+link_index;
	var new_order = new Array();
	var j = 0;
	var i = 0;
	for (i=0; i<currentLinks[field_id].length; i++) {
		if (link_id!==currentLinks[field_id][i]) {
			new_order[j++] = currentLinks[field_id][i];
		}
	}
	if (currentLinks[field_id].length !== new_order.length) {
		currentLinks[field_id] = new_order;
		ca_reorderLinks(field_id,pid);
	}	
}

function ca_moveLinkUp(field_id,link_index,pid) {
	var link_id = pid+"_"+field_id+"_"+link_index;
	var changed = false;
	var i = 1;
	//alert(currentFiles[field_id].join(', '));
	for (i=1; i<currentLinks[field_id].length; i++) {
		if (link_id===currentLinks[field_id][i]) {
			var tmp = currentLinks[field_id][i-1];
			currentLinks[field_id][i-1] = link_id;
			currentLinks[field_id][i] = tmp;
			changed = true;
		}
	}
	if (changed) {
		ca_reorderLinks(field_id,pid);
	}
}

function ca_moveLinkDown(field_id,link_index,pid) {
	var link_id = pid+"_"+field_id+"_"+link_index;
	var changed = false;
	var i = 0;
	var tmp;
	//alert(currentFiles[field_id].join(', '));
	for (i=currentLinks[field_id].length-1; i>=0; i--) {
		if (i<(currentLinks[field_id].length-1) && link_id===currentLinks[field_id][i]) {
			tmp = currentLinks[field_id][i+1];
			currentLinks[field_id][i+1] = link_id;
			currentLinks[field_id][i] = tmp;
			changed = true;
		}
	}
	if (changed) {
		ca_reorderLinks(field_id,pid);
	}
}

function ca_showDlgNewCE(inspos,inscol) {
	ceInsPos = inspos;
	ceInsCol = inscol;
	$('#contentelement-selector').dialog('open');
}

function ca_insertContentElement(fieldtypeid) {
	ceInsType = fieldtypeid;
	$('#dialog-confirm-add-ce').dialog('open');
}

function ca_invokeElementInsertion() {
	window.location.href='/'+currentURL+"&tx_pxgu[pos]="+ceInsPos+"&tx_pxgu[inserttype]="+ceInsType+"&tx_pxgu[insertcol]="+ceInsCol;	
}

function ca_prepareCEDelete(delId) {
	ceDelId = delId;
	$('#dialog-confirm-delete-ce').dialog('open');
}

function ca_invokeElementDeletion() {
	window.location.href='/'+currentURL+"&tx_pxgu[del]="+ceDelId;	
}

function ca_ce_moveup(ceId) {
	window.location.href='/'+currentURL+"&tx_pxgu[moveup]="+ceId;	
}

function ca_ce_movedown(ceId) {
	window.location.href='/'+currentURL+"&tx_pxgu[movedown]="+ceId;	
}

function ca_moveElementPos(ceId, colPos) {
	window.location.href='/'+currentURL+"&tx_pxgu[move]="+ceId+"&tx_pxgu[colpos]="+colPos;
}

function ca_insertStdTable(rteID,conf_msg) {
	//for( edId in tinyMCE.editors ) {
		//alert(rteID+":"+edId);
		//pxfm_removeLineBreaks(tinyMCE.editors[edId],true);
	//}
	if (tinyMCE.editors[rteID]) {
		var currentContent = tinyMCE.editors[rteID].getContent();
		//alert(currentContent);
		if ((currentContent!=='' && confirm(conf_msg)) || currentContent==='') {
			tinyMCE.editors[rteID].setContent('<table><thead><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></thead>'
				+ '<tbody><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>'
				+ '</tbody></table>');
		}
	}
}

function ca_removeRTEcontent(rteID,conf_msg) {
	if (tinyMCE.editors[rteID]) {
		var currentContent = tinyMCE.editors[rteID].getContent();
		//alert(currentContent);
		if (currentContent!=='' && confirm(conf_msg)) {
			tinyMCE.editors[rteID].setContent('');
		}
	}	
}

function ca_refreshListExport(opt) {
	$('#acrossaction').val('selectlist');
	document.getElementById('acrosslistselect').submit();
}





function setTemplate(node,setto) {
	//console.log(node);
	liid = node.attr("id");
	liclasses = $("#"+liid).attr("class").split(" ");
	$.each(liclasses, function(key, value) {
		if (value.substring(0,9)==="template_") {
			$("#"+liid).removeClass(value);						
		}
	});
	$("#"+liid).addClass("template_"+setto);
}

function checkTemplate(node) {
	returnid = 0;
	liclasses = node.attr("className").split(" ");
	$.each(liclasses, function(key, value) {
		if (value.substring(0,9)==="template_") {
			returnid = value.substring(9);			
		}
	});
	return returnid;
}

function checkHidden(node) {
	hiddenornot = false;
	liclasses = node.attr("className").split(" ");
	$.each(liclasses, function(key, value) {
		if (value==="hidden") {
			hiddenornot = true;			
		}
	});
	return hiddenornot;				
}

function setHidden(node,setto) {
	liid = node.attr("id");
	if (setto) {
		$("#"+liid).removeClass("visible");
		$("#"+liid).addClass("hidden");
		//$.set_type('hidden',$("#"+liid));
	} else {
		$("#"+liid).removeClass("hidden");
		$("#"+liid).addClass("visible");
		//$.set_type('default',$("#"+liid));
	}
}
// Content-Admin Functions END



