function initGallery() {
	aColor = "#FFF";
	iColor = "#FFF";
	aFontWeight = "bold";
	iFontWeight = "normal";
	aTD = "underline";
	iTD = "none";
	sliderID = 0;
	$(".sliderCount").val(sliderID);
	$(".gallerySlider").css("display", "none");
	$(".gallerySlider_"+sliderID).css("display", "block");
	$(".scrollbaritem").css("background-color", iColor);
	$(".scrollbaritem_"+sliderID).css("background-color", aColor);
	$(".scrollbaritem").css("font-weight", iFontWeight);
	$(".scrollbaritem_"+sliderID).css("font-weight", aFontWeight);
	$(".scrollbaritem").css("text-decoration", iTD);
	$(".scrollbaritem_"+sliderID).css("text-decoration", aTD);
	$(".galleryArrowLeft").css("display", "none");
	$(".gallerySlider").each(function() {
		imageCount = $(this).children(".imageContainer").length;
		imageWidth = 133;
		sliderWidth = imageCount * imageWidth;
		$(this).css("width", sliderWidth + "px");
		if (imageCount <= 4) {
			grundid = $(this).parent().attr("id").split("_")[1];
			$("#galleryArrowRight_" + grundid).css("display", "none");	
			$("#galleryArrowLeft_" + grundid).css("display", "none");	
		}
	});
	$(".galleryArrowLeft").click(function () {
		thisButton = $(this);
		grundid = $(this).parent().parent().attr("id").split("_")[1];
		$("#galleryArrowRight_" + grundid).css("display", "block");	
		sliderID = 0;
		focusSlider = $("#gallerySliderArea_"+ grundid +" .gallerySlider_"+sliderID);
		focusLeft = $(focusSlider).css("left");
		focusLeft = focusLeft.substring(0, focusLeft.length-2);
		focusSliderWidth = parseInt(focusLeft) + 133;
		sliderCount = $("#sliderCount_" + grundid).val();
		if (parseInt(sliderCount) > 0) {
			if (!$(this).hasClass("disabled")) {
				thisButton.addClass("disabled");
				$(focusSlider).animate({left: [focusSliderWidth+'px', 'swing']}, 500, 'linear', function() {
					thisButton.removeClass("disabled");
					newSliderCount = parseInt(sliderCount)-1;
					$("#sliderCount_" + grundid).val(newSliderCount);
					if (newSliderCount == 0) {
						thisButton.css("display", "none");
					}
				});
			}
		}
	});
	$(".galleryArrowRight").click(function () {
		thisButton = $(this);
		grundid = $(this).parent().parent().attr("id").split("_")[1];
		$("#galleryArrowLeft_"+grundid).css("display", "block");
		$("#galleryArrowLeft_" + grundid).css("display", "block");		
		sliderID = 0;
		focusSlider = $("#gallerySliderArea_"+ grundid +" .gallerySlider_"+sliderID);
		focusLeft = $(focusSlider).css("left");
		focusLeft = focusLeft.substring(0, focusLeft.length-2);
		focusSliderWidth = focusLeft - 133;
		sliderCount = $("#sliderCount_" + grundid).val();
		maxElements = $(focusSlider).children(".imageContainer").length;
		if ((parseInt(sliderCount) + 4) < maxElements) {
			if (!$(this).hasClass("disabled")) {
				thisButton.addClass("disabled");
				$(focusSlider).animate({left: [focusSliderWidth+'px', 'swing']}, 500, 'linear', function() {
					thisButton.removeClass("disabled");
					newSliderCount = parseInt(sliderCount)+1;
					$("#sliderCount_" + grundid).val(newSliderCount);	
					if ((parseInt(newSliderCount) + 4) >= maxElements) {
						thisButton.css("display", "none");
					}					
				});
			}
		}
	});
}

function get_information(gid, wordsid, lang, presentation) {
	if(gid		== ""){return false;}
	Firmensuche=0;
	// Bei Firmensuche ist wordsid leer aber um an Gallerie zu kommen, muss Dummy-WordsID gesetzt werden
	if(wordsid	== ""){wordsid = 2;Firmensuche=1;}
	$.ajax({
		type: "GET", 
		timeout: 7000, 
		data: {
			wid: wordsid, 
			lang: lang,
			gid: gid,
			presentation: presentation,
			Firmensuche: Firmensuche
		}, 
		url: "/ajax/json/get_company_information.php", 
		success: function(result) {
			if(result!="") {
				JSONObj = eval("(" + result + ")");
				if(JSONObj==null){return false;}
				SCHLEIFE = JSONObj.ukatsshort;
				galleryArray = JSONObj.gallery;
				
				$.each(SCHLEIFE, function(grundid, value) {
					// Sven -> Sonderfall SIKO 11.07.2011
					if (grundid == 34435) {
						if ($.trim(JSONObj.proddescshort[grundid]) != "") {
							$("#resultUG_short_"+grundid).html($.trim(JSONObj.proddescshort[grundid]));
							$("#resultUG_long_"+grundid).html(JSONObj.spezifikationen[grundid]);
							$("#resultHeader_3_"+grundid).html('<span><a>'+langvalue_spezifikationen+'</a></span>');
						}
					}
					else {
						if ($.trim(JSONObj.ukatsshort[grundid]) != "") {
							$("#resultUG_short_"+grundid).html($.trim(JSONObj.ukatsshort[grundid]));
						}
						else if ($.trim(JSONObj.proddescshort[grundid]) != "") {
							$("#resultUG_short_"+grundid).html($.trim(JSONObj.proddescshort[grundid]));
						}
						else if ($.trim(JSONObj.wueushort[grundid]) != ""){
							$("#resultUG_short_"+grundid).html($.trim(JSONObj.wueushort[grundid]));
						}
						if ($.trim(JSONObj.spezifikationen[grundid]) != ""){
							$("#resultUG_long_"+grundid).html(JSONObj.spezifikationen[grundid]);
							$("#resultHeader_3_"+grundid).html('<span><a>'+langvalue_spezifikationen+'</a></span>');
							$("#resultHeader_3_"+grundid).removeClass("lpInaktiv");						
						}
						else if ($.trim(JSONObj.www[grundid]) != "") {
							$("#resultHeader_3_"+grundid).html("<span><a href='"+JSONObj.www[grundid]+"' onclick='onw(this.href);return false;' target='_blank'>"+langvalue_spezifikationen+"</a></span>");
						}
						else if ($.trim(JSONObj.email[grundid]) != "") {
							$("#resultHeader_3_"+grundid).html('<span><a>'+langvalue_spezifikationen+'</a></span>');
							$("#resultHeader_3_"+grundid).addClass("spezMailForm");
						}
						else {
							$("#resultUG_long_"+grundid).html("");
						}
					}
				});
				
				$.each(galleryArray, function(grundid, galleryString) {
					$("#resultFooterContentGallery_" + grundid).append(galleryString);
					//$("#resultFooterContentGallery_" + grundid).show();
					$("#resultHeader_2Link_" + grundid).removeClass("resultHeaderInactive");
					bilderlabel=$("#resultHeader_2Link_" + grundid).html();
					$("#resultHeader_2Link_" + grundid).html("<a href='/' class='result_tab_lp_link_remove'>"+bilderlabel+"</a>");
				});
				initGallery();
				initPiroBox();
				InitresultHeaderClickable();
			}
			else{return false; }
		}
	});
}

function initPiroBox() {
	$().piroBox({
		my_speed: 600, //animation speed
		bg_alpha: 0.5, //background opacity
		radius: 4, //caption rounded corner
		scrollImage : false, // true == image follows the page, false == image remains in the same open position
		pirobox_next : 'piro_next', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
		pirobox_prev : 'piro_prev',// Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
		close_all : '.piro_close,.piro_overlay',// add class .piro_overlay(with comma)if you want overlay click close piroBox
		slideShow : 'slideshow', // just delete slideshow between '' if you don't want it.
		slideSpeed : 4 //slideshow duration in seconds(3 to 6 Recommended)
	});
}

function scrollTo(elem) {
	var x = $(elem).offset().top - 100;
	$('html,body').animate({scrollTop: x}, 500);
}

function InitresultHeaderClickable(){
	$(".result_tab_lp_link_remove").removeAttr("href");
	$(".resultHeader ul li").click(function() {
		thisMenuItem = $(this);
		if (!$(this).children("span").hasClass("resultHeaderInactive")) {
			id 		= $(this).attr("id").split("_")[1];
			grundid	= $(this).attr("id").split("_")[2];
			if (id == "2") 		{	
				$(".closeAll").css("display", "none");
				elem = $("#resultFooterContentGallery_"+grundid);
				$("#resultFooterContentContact_"+grundid).css("display", "none");	
				$("#resultUG_short_"+grundid).css("display", "block");
				$("#resultUG_long_"+grundid).css("display", "none");
				if ($(elem).css("display") == "none") {
					$(elem).css("display", "block");
					$("#closeAll_" + grundid).css("display", "block");
					
					$(".resultHeader ul li").removeClass("activeMenuItem");
					$(thisMenuItem).addClass("activeMenuItem");
				}
				else {
					$(elem).css("display", "none");
					
					$(".resultHeader ul li").removeClass("activeMenuItem");
				}				
			}
			else if (id == "3") {
				$(".closeAll").css("display", "none");
				elemShort 	= $("#resultUG_short_"	+grundid);
				elemLong 	= $("#resultUG_long_"	+grundid);
				if ($.trim($(elemShort).text()) != "") {
					$("#resultFooterContentGallery_"+grundid).css("display", "none");
					$("#resultFooterContentContact_"+grundid).css("display", "none");	
					if ($(this).hasClass("spezMailForm")) {
						elem = $("#resultFooterContentContact_"+grundid);
						if ($(elem).css("display") == "none") {
							$(".resultFooterContentContact").css("display", "none");
							$(elem).css("display", "block");
							$("#closeAll_" + grundid).css("display", "block");
							
							$(".resultHeader ul li").removeClass("activeMenuItem");
							$(thisMenuItem).addClass("activeMenuItem");
						} else {
							$(".resultFooterContentContact").css("display", "none");
							
							$(".resultHeader ul li").removeClass("activeMenuItem");
						}
						contactForm = $("#resultFooterContactForm");
						$("#resultFooterContentGallery_"+grundid).css("display", "none");
						$("#resultFooterContentContactForm_"+grundid).html(contactForm);
						$("#mfgrundid").val(grundid);
						$(".mailformerror").css("display", "none");
						$(".resultFooterContentContactForm").css("display", "block");
					}				
					else {
						if ($(elemLong).css("display") == "none") {
							$(elemShort).css("display", "none");
							$(elemLong).css("display", "block");
							$("#closeAll_" + grundid).css("display", "block");
							
							$(".resultHeader ul li").removeClass("activeMenuItem");
							$(thisMenuItem).addClass("activeMenuItem");
						}
						else {
							$(elemShort).css("display", "block");
							$(elemLong).css("display", "none");
							
							$(".resultHeader ul li").removeClass("activeMenuItem");
						}
					}
				}
			}
			else if (id == "4") {	
				$(".closeAll").css("display", "none");
				elem = $("#resultFooterContentContact_"+grundid);
				$("#resultUG_short_"+grundid).css("display", "block");
				$("#resultUG_long_"+grundid).css("display", "none");
				if ($(elem).css("display") == "none") {
					$(".resultFooterContentContact").css("display", "none");
					$(elem).css("display", "block");
					$("#closeAll_" + grundid).css("display", "block");
					
					$(".resultHeader ul li").removeClass("activeMenuItem");
					$(thisMenuItem).addClass("activeMenuItem");
				} else {
					$(".resultFooterContentContact").css("display", "none");
					
					$(".resultHeader ul li").removeClass("activeMenuItem");
				}
				//contactForm = $("#resultFooterContactForm");
				$("#resultFooterContentGallery_"+grundid).css("display", "none");
				$("#resultFooterContentContactForm_"+grundid).html($("#resultFooterContactForm"));
				$("#mfgrundid").val(grundid);
				$(".mailformerror").css("display", "none");
				$(".resultFooterContentContactForm").css("display", "block");
			}
		}
	});
}

$(document).ready(function() {
	minFooterHeight 	= 0;
	maxFooterHeight 	= 200;
	footerSpeed 		= 200;
	$("#sortSelect").change(function() {
		$("#sortForm").submit();
	});
	
	$(".resultUG").click(function() {
		version = $(this).attr("id").split("_")[1]; // short/long
		grundid = $(this).attr("id").split("_")[2];
		$("#resultFooterContentGallery_"+grundid).css("display", "none");
		$("#resultFooterContentContact_"+grundid).css("display", "none");	
		if (version == "short") {
			$("#resultUG_short_"+grundid).css("display", "none");
			$("#resultUG_long_"+grundid).css("display", "block");
			$("#closeAll_" + grundid).css("display", "block");
			
			$(".resultHeader ul li").removeClass("activeMenuItem");
			$("#resultHeader_3_"+grundid).addClass("activeMenuItem");
		}
	});
	$(".closeAll").click(function() {
		$(".resultHeader ul li").removeClass("activeMenuItem");
		$(this).css("display", "none");
		grundid = $(this).attr("id").split("_")[1];
		$("#resultUG_long_"+grundid).css("display", "none");
		$("#resultUG_short_"+grundid).css("display", "block");
		$("#resultFooterContentContact_"+grundid).css("display", "none");
		$("#resultFooterContentGallery_"+grundid).css("display", "none");
		scrollTo($("#resultWrapper_" + grundid));
	});
	$(".result_header div").click(function() {
		grundID 	= $(this).attr("id").split("_")[3];
		tabID 		= $(this).attr("id").split("_")[2];
		
		currentTab	= $(this);
		thisFooter 	= $("#result_footer_" + grundID);
		if (thisFooter.hasClass("result_footer_auf_" + tabID) || tabID == 1) {
			hideFooter(grundID);
			currentTab.removeClass("result_tab_active");
		}
		else {
			hideFooter(grundID);
			$("#result_footer_content_tab_5_kurz_" + grundID).show();
			if ($(this).hasClass("firsttab")) {  } 
			else {
				$(this).parent().children(".result_tab").removeClass("result_tab_active");
				currentTab.addClass("result_tab_active");
				footer = $(this).parent().parent().children(".result_body").children("#result_footer_" + grundID);
				if (footer.hasClass("result_footer_auf_" + tabID)) {
					hideFooter(grundID);
					currentTab.removeClass("result_tab_active");
				}
				else {
					$(footer).children(".result_footer_content").css("display", "none");
					$(footer).children(".result_footer_content_tab_" + tabID).css("display", "block");
					$(footer).show();
					$(currentTab).removeClass("result_tab_active");
					footer.removeClass("result_footer_auf_1");
					footer.removeClass("result_footer_auf_2");
					footer.removeClass("result_footer_auf_3");
					footer.removeClass("result_footer_auf_4");
					footer.addClass("result_footer_auf_" + tabID);
					currentTab.addClass("result_tab_active");
					$("#result_footer_close_" + grundID).show();
				}
				return false;
			}
		}
	});
	
	
	function showFooter(tabID, grundID) {
		$("#result_footer_close_" + grundID).show();
	}
	function hideFooter(grundID) {
		$("#result_footer_content_tab_1_" + grundID).hide();
		$("#result_footer_content_tab_2_" + grundID).hide();
		$("#result_footer_content_tab_3_" + grundID).hide();
		$("#result_footer_content_tab_4_" + grundID).hide();
		$("#result_footer_content_tab_5_" + grundID).hide();
		$("#result_footer_content_tab_5_kurz_" + grundID).show();
		$("#result_footer_" + grundID).removeClass("result_footer_auf_1");
		$("#result_footer_" + grundID).removeClass("result_footer_auf_2");
		$("#result_footer_" + grundID).removeClass("result_footer_auf_3");
		$("#result_footer_" + grundID).removeClass("result_footer_auf_4");
		$("#result_tab_1_" + grundID).removeClass("result_tab_active");
		$("#result_tab_2_" + grundID).removeClass("result_tab_active");
		$("#result_tab_3_" + grundID).removeClass("result_tab_active");
		$("#result_tab_4_" + grundID).removeClass("result_tab_active");
		$("#result_footer_close_" + grundID).hide();
	}
	$(".result_footer_content_tab_5_kurz").click(function() {
		grundID 	= $(this).attr("id").split("_")[6];
		hideFooter(grundID);
		$("#result_footer_" + grundID).children(".result_footer_content").css("display", "none");
		if ($(this).hasClass("tab_5_plus")) {
			$(this).hide();
			$("#result_footer_content_tab_5_" + grundID).css("display", "block");
			$("#result_footer_" + grundID).show();
			$("#result_footer_close_" + grundID).show();
		}
	});
	$(".bakresult_footer_content_tab_5").click(function() {
		grundID 	= $(this).attr("id").split("_")[5];
		hideFooter(grundID);
		$(this).css("display", "none");
		$("#result_footer_content_tab_5_kurz_" + grundID).show();
	});
	$(".result_footer_close").click(function() {
		grundID 	= $(this).attr("id").split("_")[3];
		hideFooter(grundID);
	});
});

