/**
 * @project: GEFA
 * @author:  mario diaz @ mario-diaz.com
 * @created: 13-07-2010 20:07
 */

var iLang = 0;

var bLoginOpened = false;

var bLangSelectOpened = false;

var iMainNaviActive = -1;

var iShowSubheadline = -1;

var iShowContactContent = -1;

var iShowMainContent = -1;

var iHeaderImagesSlideshowInterval = 8400;

var aVendorProducts = new Array();

var bAnimationFinished = true;

var bMsie = (document.all) ? true : false;
var bIE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var bIE7 = (navigator.appVersion.indexOf("MSIE 7.") == -1) ? false : true;
var bSafari = navigator.appVersion.indexOf("Safari") != -1;


var bStartTimeout = true;	// timeout for news teaser changing

var iForceDisplaySubcat = -1;	// another help for msie

// ie debugging




// *** startup actions ******************************************************************************* */
$(document).ready(function() {
	
	// other lang logo at bottom if idlang > 0:
	if (iLang > 0) {
		if (document.getElementById('funding')) {
			document.getElementById('funding').innerHTML = '<img src="fileadmin/Layouts/images/bmelv_support.jpg" alt="" />';
		}
	}
	
	// navi left start site
	if (document.getElementById('navi_products_layer')) {
		$('#navi_products_layer').click(function(){
			goToProduct();
		});
		$("#navi_products_layer").mouseleave(function(){
	  		$("#navi_products_layer").hide();
	  		$("#navi_products_alpha").hide();
		});
		$("#navi_products").mouseleave(function(){
	  		$("#navi_products_layer").hide();
	  		$("#navi_products_alpha").hide();
		});
	}
	
	
	// main navi
	if (document.getElementById('navmenu')) {
		// save active menu item for mouseout events (see below)
		for (i = 0; i < 3; i++) {
			if ($('#navi_main_link_' + i).hasClass('active')) {
				iMainNaviActive = i;
				break;
			}
		}
		
		// first menu item: category links layer
		$("#navi_main_0").hover(function(){
			changeDisplayTriangles(false, 'black');
	  		$("#categories_layer").show(); 
	  		$("#navi_main_link_0").addClass('active');
	  		
	  		helpNaviIE7(true);
		});
		$("#navi_main_0").mouseleave(function(){
	  		$("#categories_layer").hide(); 
	  		changeDisplayTriangles(true, 'black');
	  		if (iMainNaviActive != 0)
	  			$('#navi_main_link_0').removeClass('active');
	  		
	  		helpNaviIE7(false);
		});
		
		// second menu item: events links layer
		$("#navi_main_1").hover(function(){
			changeDisplayTriangles(false, 'red');
	  		$("#events_layer").show(); 
	  		$("#navi_main_link_1").addClass('active');
	  		
	  		helpNaviIE7(true);
		});
		$("#navi_main_1").mouseleave(function(){
	  		$("#events_layer").hide(); 
	  		changeDisplayTriangles(true, 'red');
	  		if (iMainNaviActive != 1)
	  			$('#navi_main_link_1').removeClass('active');
	  		
	  		helpNaviIE7(false);
		});
		
		// 3rd menu item:
		$("#navi_main_2").hover(function(){
			changeDisplayTriangles(false, 'red');
	  		$("#intern_layer").show(); 
	  		$("#navi_main_link_2").addClass('active');
	  		
	  		helpNaviIE7(true);
		});
		$("#navi_main_2").mouseleave(function(){
	  		$("#intern_layer").hide(); 
	  		changeDisplayTriangles(true, 'red');
	  		if (iMainNaviActive != 2)
	  			$('#navi_main_link_2').removeClass('active');
	  		
	  		helpNaviIE7(false);
		});
	}
	
	
	
	// lang select
	$("#lang_select_opener").hover(function(){
		changeDisplayLangSelect();
	});
	$("#lang_select_layer").mouseleave(function(){
  		$("#lang_select_layer").hide(); 
	});
	
	
	
	// correct height of event details if necessary:
	if (document.getElementById('event_details')) {
		oNaviSub = document.getElementById('navi_sub');
		oMainContentEvent = document.getElementById('main_content_event');
		iHeightNavSub = oNaviSub.offsetHeight;
		iHeightContent = oMainContentEvent.offsetHeight;
		if (iHeightContent < iHeightNavSub) {
			iDiffY = document.getElementById('event_title').offsetHeight;
			//alert(iDiffY);
			document.getElementById('event_details').style.height = (iHeightNavSub - iDiffY) + 'px';
		}
	} else if (document.getElementById('main_content') && document.getElementById('navi_sub')) {
		oNaviSub = document.getElementById('navi_sub');
		iHeightNavSub = oNaviSub.offsetHeight;
		iHeightContent = document.getElementById('main_content').offsetHeight;
		//alert(iHeightNavSub + ', ' + iHeightContent );
		if (iHeightNavSub < iHeightContent) {
			oNaviSub.style.height = (iHeightContent - 77) + 'px';
		}
	}
	
	if (iShowSubheadline != -1) {
		if (document.getElementById('sn_link_' + iShowSubheadline)) {
			document.getElementById('sn_link_' + iShowSubheadline).className = 'active';
			iMainContentDisplayed = iShowSubheadline;
		}
	}
	
	if (iShowContactContent == 1) {
		showContactContent(1);
	}
	
	if (iShowMainContent > -1) {
		showMainContent(iShowMainContent);
	}
	
	// sroller event calender
	if (document.getElementById('pane1')) {
		$('#pane1').jScrollHorizontalPane({showArrows:true});
	}
	
	// start slideshow of header images:
	if (bHeaderImagesSlightshow) {
		setTimeout("changeHeaderImgSlideshow()", iHeaderImagesSlideshowInterval);
		setTimeout("positionTriangles()", 1000);
	} else {
		// position triangles:
		setTimeout("positionTriangles()", 1000);
	}

	
	// if vendor products then activate fancy img zoom
	for (iIdSubcat in aVendorProducts) {
		aTmp = aVendorProducts[iIdSubcat];
		for (i = 0; i < aTmp.length; i++) {
			//alert(iIdProduct);
			$("a#product_zoom_" + aTmp[i][0]).fancybox({
				'titleShow'		: false
			});
		}
	}
	
	
	// correct event date:
	if (document.getElementById('event_date') && document.getElementById('headline')) {
		//
		//if (document.URL == 'http://www.g-e-f-a.de/news__termine/news/gefa-oktoberfest-promotion_in_den_usa.html') {
			//alert(document.getElementById('headline').offsetHeight);
		//}
		
		if (document.getElementById('headline').offsetHeight < 38) {
			document.getElementById('headline').style.paddingTop = '35px';
		}
	}
	
	
	// correct event img:
	if (document.getElementById('event_img')) {
		if (document.getElementById('event_img').innerHTML == '') {
			document.getElementById('event_img').innerHTML = '<img src="fileadmin/Layouts/images/platzhalter_termine.jpg" alt="" />';
		}
	}
	
	
	// home: if home then set interval for news changing:
	if (document.getElementById('start_top')) {
		setTimeout("showNewsTeaser(2)", 8000);
	}
	
	
	// msie again:
	if (iForceDisplaySubcat != -1) {
		showProductsOfCat(iForceDisplaySubcat);
	}
	
});


/**
 * help function for ie7 :(
 * @param bool bHide
 * @return bool
 */
function helpNaviIE7 (bHide) {
	if ((bIE7 || bIE6) && document.getElementById('jScrollPaneContainer')) {
		document.getElementById('jScrollPaneContainer').style.visibility = bHide ? 'hidden' : 'visible';
	}
}


/* *** window resize actions *** */
$(window).bind('resize', function() {
	positionTriangles();
});


// events or vendors nothing found
var bDoorpageNothingFound = false;


// other color of triangle:
var sOtherColorForTriangle = '';


/**
 * positions triangles. Sometimes it must be called again after jQuery actions. So own function for that.
 * @return void
 */
function positionTriangles () {
	
	if (sOtherColorForTriangle != '' && document.getElementById('triangle_red_layer')) {
		document.getElementById('triangle_red_layer').innerHTML = '<img src="fileadmin/Layouts/images/triangle_' + sOtherColorForTriangle + '.png" alt="" />';
	}
	
	if (document.getElementById('triangle_black_layer') && document.getElementById('navi_sub')) {
		oLayerBlack = document.getElementById('triangle_black_layer');
		oLayerNaviSub = document.getElementById('navi_sub');
		aTmp = findPos(oLayerNaviSub);
		oLayerBlack.style.left = (aTmp[0] + oLayerNaviSub.offsetWidth) + 'px';
		iOffsetY = !bDoorpageNothingFound ? 125 : 20;
		oLayerBlack.style.top = (aTmp[1] + iOffsetY) + 'px';
		oLayerBlack.style.visibility = 'visible';
		if (bIE6) {
			oLayerBlack.innerHTML = '<img src="fileadmin/Layouts/images/triangle_black_ie6.png" />';
		}
	}
	if (document.getElementById('triangle_red_layer') && (document.getElementById('navi_sub_layer') || document.getElementById('navi_sub_layer_vendor'))) {
		oLayerRed = document.getElementById('triangle_red_layer');
		oLayerNaviSub = document.getElementById('navi_sub_layer') ? document.getElementById('navi_sub_layer') : document.getElementById('navi_sub_layer_vendor');
		aTmp = findPos(oLayerNaviSub);
		oLayerRed.style.left = (aTmp[0] - oLayerRed.offsetWidth) + 'px';
		oLayerRed.style.top = (aTmp[1] + 26) + 'px';
		oLayerRed.style.visibility = 'visible';
		if (bIE6) {
			oLayerRed.innerHTML = '<img src="fileadmin/Layouts/images/triangle_red_ie6.png" />';
		}
	}
	
	if (2 == 2 || bIE6 || bIE7) {
		setTimeout("positionTriangles()", 1000);
	}
}


// for preloading images:
var aTmpPreload = new Array();


/**
 * preloads images:
 * @param aImgArr
 * @return void
 */
function preloadImages (aImgArr) {
	iStart = aTmpPreload.length;
	for (i = 0; i < aImgArr.length; i++) {
		aTmpPreload[iStart + i] = new Image();
		aTmpPreload[iStart + i].src = aImgArr[i];
	}
}


/**
 * hides or shows triangles (problem with absolute layers and navi layers)
 * @param bool bShow
 * @param string sColor
 * @return void
 */
function changeDisplayTriangles (bShow, sColor) {
	if (bShow) {
		if (document.getElementById('triangle_' + sColor + '_layer')) {
			$("#triangle_" + sColor + "_layer").show(); 
		}
	} else {
		if (document.getElementById('triangle_' + sColor + '_layer')) {
			$("#triangle_" + sColor + "_layer").hide(); 
		}
	}
}


/**
 * changes display of login layer
 * @param object oCaller
 * @return void
 */
function changeDisplayLoginLayer (oCaller) {
	if (bLangSelectOpened) changeDisplayLangSelect();
	bLoginOpened = !bLoginOpened;
	aTmp = findPos(oCaller);
	document.getElementById('login_input').style.left = (aTmp[0] + 0) + 'px';
	document.getElementById('login_input').style.visibility = bLoginOpened ? 'visible' : 'hidden';
}


/**
 * changes display of lang select layer
 * @param object oCaller
 * @return void
 */
function changeDisplayLangSelect () {
	if (bLoginOpened) changeDisplayLoginLayer();
	oCaller = document.getElementById('lang_select_opener');
	aTmp = findPos(oCaller);
	document.getElementById('lang_select_layer').style.left = (aTmp[0] - 10) + 'px';
	document.getElementById('lang_select_layer').style.display = 'inline';
	
}


/**
 * finds position of element
 * @param object obj
 * @return int array
 */
function findPos (obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft, curtop];
}


var sProductsUrl = '';


/**
 * products navi mouseover: show title in absolute layer
 * @param object oCaller
 * @param string sTitle
 * @return void
 */
function showNaviProductTitle (oCaller, sTitle, sUrl) {
	
	aTmp = findPos(oCaller);
	//aPosNavi = findPos(document.getElementById('navproducts'));
	document.getElementById('navi_products_alpha').style.top = aTmp[1] + 'px';
	document.getElementById('navi_products_layer').style.top = aTmp[1] + 'px';
	document.getElementById('navi_products_link').innerHTML = sTitle;
	document.getElementById('navi_products_link').href = sUrl;
	document.getElementById('navi_products_link_arrow').href = sUrl;
	document.getElementById('navi_products_alpha').style.display = 'inline';
	document.getElementById('navi_products_layer').style.display = 'inline';
	
	sProductsUrl = sUrl;
}


/**
 * goes to current start items url
 * @return void
 */
function goToProduct () {
	location.href = sProductsUrl;
}


var iNewsTeaserCurrent = 1;


/**
 * news teaser: change current news teaser 
 * use jquery to fadein or fadeout
 * @param int iNumber
 * @return void
 */
function showNewsTeaser (iNumber, bStopTimeout) {
	if ((arguments.length == 1 && bStartTimeout) || arguments.length == 2) {
		
		// get number:
		iCount = 0;
		for (i = 1; i < 4; i++) {
			if (document.getElementById('news_page_' + i))
				iCount++;
			else
				break;
		}
		
		//alert(iNewsTeaserCurrent + ', ' + iNumber);
		if (document.getElementById('news_item_' + iNewsTeaserCurrent)) {
			$('#news_item_' + iNewsTeaserCurrent).fadeOut(320, function() {
				if (document.getElementById('news_item_' + iNewsTeaserCurrent)) {
					document.getElementById('news_item_' + iNewsTeaserCurrent).style.display = 'none';
				}
				$('#news_item_' + iNumber).fadeIn(400, function() {
					// fading complete.
				});
			});
		}
		for (i = 1; i < 4; i++) {
			if (document.getElementById('news_page_' + i))
				document.getElementById('news_page_' + i).className = i == iNumber ? 'active' : '';
		}
		iNewsTeaserCurrent = iNumber;
		
		if (arguments.length > 1 && bStopTimeout) {
			//alert('test');
			bStartTimeout = false;
		}
		if (bStartTimeout) {
			iNum = iNumber % iCount + 1;
			setTimeout("showNewsTeaser(" + iNum + ")", 8000);
		}
	}
}


/* *** changing of main content (profile) ************************************************************************ */
var iMainContentDisplayed = -1;	// default is 'the_text'
/**
 * changes main content via html ids and jquery
 * @param int iNum
 * @return void
 */
function showMainContent (iNum) {
	//alert(iMainContentDisplayed);
	// hide previous content. Find current displayed content
	sLayerIdOld = iMainContentDisplayed == -1 ? 'the_text' : 'further_content_' + iMainContentDisplayed;
	sHeadlineIdOld = iMainContentDisplayed == -1 ? 'headline' : 'subheadline_' + iMainContentDisplayed;
	sLayerIdNew = 'further_content_' + iNum;
	sHeadlineIdNew = 'subheadline_' + iNum;
	
	//alert(sLayerIdOld + ',' + sLayerIdNew);
	$('#' + sLayerIdOld + ',#' + sHeadlineIdOld).fadeOut(320, function() {
		if (iMainContentDisplayed >= 0) document.getElementById('sn_link_' + iMainContentDisplayed).className = '';
		$('#' + sLayerIdNew + ',#' + sHeadlineIdNew).fadeIn(400, function() {
			// fading complete.
			iMainContentDisplayed = iNum;
			document.getElementById('sn_link_' + iMainContentDisplayed).className = 'active';
		});
	});
}



/* *** special page ******************************************************************************************** */
var iSpecialContentDisplayed = 0;	// default is 'the_text'
/**
 * changes special content via html ids and jquery
 * @param int iNum
 * @return void
 */
function showSpecialContent (iNum) {
	//alert(iSpecialContentDisplayed);
	// hide previous content. Find current displayed content
	sLayerIdOld = 'further_content_' + iSpecialContentDisplayed;
	sLayerIdNew = 'further_content_' + iNum;
	
	//alert(sLayerIdOld + ',' + sLayerIdNew);
	$('#' + sLayerIdOld).fadeOut(320, function() {
		if (iSpecialContentDisplayed >= 1) document.getElementById('sn_link_' + iSpecialContentDisplayed).className = '';
		$('#' + sLayerIdNew).fadeIn(400, function() {
			// fading complete.
			iSpecialContentDisplayed = iNum;
			document.getElementById('sn_link_' + iSpecialContentDisplayed).className = 'active';
		});
	});
}



/* *** img switcher top **************************************************************************************** */
var iHeaderImgDisplayed = 0;
var bHeaderImagesSlightshow = false;	// slideshow only if more than one


/**
 * changes header img via jquery fading
 * @param int iNum
 * @return void
 */
function changeHeaderImg (iNum) {
	if (arguments.length == 1) {
		bHeaderImagesSlightshow = false;
	}
	sLayerIdOld = 'header_image_' + iHeaderImgDisplayed;
	sLayerIdNew = 'header_image_' + iNum;
	$('#' + sLayerIdOld).fadeOut(320, function() {
		if (document.getElementById('hi_caller_' + iHeaderImgDisplayed))
			document.getElementById('hi_caller_' + iHeaderImgDisplayed).className = '';
		$('#' + sLayerIdNew).fadeIn(400, function() {
			// fading complete.
			iHeaderImgDisplayed = iNum;
			if (document.getElementById('hi_caller_' + iHeaderImgDisplayed))
				document.getElementById('hi_caller_' + iHeaderImgDisplayed).className = 'active';
		});
	});
}


/**
 * slideshow of header imgs: checks which number and calls function 
 * @return void
 */
function changeHeaderImgSlideshow () {
	if (bHeaderImagesSlightshow) {		// user might stop it by clicking on icons
		iTmp = iHeaderImgDisplayed + 1;
		if (!document.getElementById('header_image_' + iTmp)) {
			iTmp = 0;
		} 
		changeHeaderImg(iTmp, false);
		setTimeout("changeHeaderImgSlideshow()", iHeaderImagesSlideshowInterval);
	}
}



/* *** google maps ******************************************************************** */
/**
 * shows google maps address
 * @param string address
 * @param string info
 * @return void
 */
function showAddress (address, info) {
	geocoder.getLatLng(address,
						function (point) {
							if (!point) {
								alert("Could not find postcode " + address);
							} else {
								oMap.setCenter(point, 13);
								var marker = new GMarker(point);
								oMap.addOverlay(marker);
								
								marker.openInfoWindowHtml(info);
							}
						}
	);
}



/* *** contact content switcher ***************************************************** */
var iContactContentCurrent = 0;	// form
var sAddressContact = '';


/**
 * changes contact content via html ids. No use of fading effects because of gmaps rendering problems
 * @param int iNum
 * @return void
 */
function showContactContent (iNum, bForce) {
	sTmp = document.URL;
	if (bMsie && arguments.length > 1) {	// be carefull: Add msie8, too
		sBaseHref = document.getElementsByTagName('base')[0].href;
		location.href = sBaseHref + 'index.php?id=' + iIdCurrent + '&L=' + iIdLang + '&show_subcontent=' + iNum;
	} else {
		if (iNum == 1) {
			document.getElementById('contact_1').style.height = "300px";
			document.getElementById('contact_0').style.display = 'none';
			iContactContentCurrent = 1;
			document.getElementById('sn_link_0').className = '';
			document.getElementById('sn_link_1').className = 'active';
		} else {
			document.getElementById('contact_1').style.height = "0px";
			document.getElementById('contact_0').style.display = 'block';
			iContactContentCurrent = 0;
			document.getElementById('sn_link_1').className = '';
			document.getElementById('sn_link_0').className = 'active';
		}
	}
}



/* *** news list ************************************************************************************ */
var iNewsCurrent = 0;


/**
 * shows news preview. Hides active point
 * @param int iNum
 * @return void
 */
function showNewsPreview (iNum) {
	sOld = 'news_list_content_' + iNewsCurrent;
	sNew = 'news_list_content_' + iNum;
	$('#' + sOld).slideUp(240, function() {
		document.getElementById('news_arrow_' + iNewsCurrent).src = 'fileadmin/Layouts/images/arrow_grey_down.png';
		$('#' + sNew).slideDown(200, function() {
		    // Animation complete.
			iNewsCurrent = iNum;
			document.getElementById('news_arrow_' + iNewsCurrent).src = 'fileadmin/Layouts/images/arrow_grey_up.png';
			// safari bug:
			
		}); 
	});
	if (bSafari || bMsie)
		document.getElementById(sNew).style.display = 'block';
}



/* *** vendor contact persons ******************************************************************************** */

var iContactPersonsCurrent = 0;

/**
 * shows vendor contact persons for area
 * @param int iNum
 * @return void
 */
function showContactPersons (iNum) {
	sOld = 'contact_persons_' + iContactPersonsCurrent;
	sNew = 'contact_persons_' + iNum;
	
	$('#' + sOld).slideUp(240, function() {
		document.getElementById('cp_arrow_' + iContactPersonsCurrent).src = 'fileadmin/Layouts/images/arrow_grey_down.png';
		
		$('#' + sNew).slideDown(200, function() {
		    // Animation complete.
			iContactPersonsCurrent = iNum;
			document.getElementById('cp_arrow_' + iContactPersonsCurrent).src = 'fileadmin/Layouts/images/arrow_grey_up.png';
		}); 
	});
	if (bSafari || bMsie)
		document.getElementById(sNew).style.display = 'block';
}



/* *** event calendar layer actions (items for block) ******************************************************* */

/**
 * shows events for one block. Get Details from event js file. Generated by PHP file
 * @param int iCat
 * @param int iStart
 * @param int iEnd
 * @param object oCaller
 * @return void
 */
function showEventBlockDetails (iCat, iStart, iEnd, oCaller) {

	// we got unix timestamp. so convert it
	sPeriod = createGermanDate(iStart) + ' - ' + createGermanDate(iEnd);
	
	aEventsCat = aEvents[iCat];
	aTmp = new Array();
	for (i = 0; i < aEventsCat.length; i++) {
		//alert(createGermanDate(aEventsCat[i][0]) + ' - ' + createGermanDate(aEventsCat[i][1]));
		if (aEventsCat[i][0] >= iStart && aEventsCat[i][1] <= iEnd) {
			sDate = '<div class="pl12">' + createGermanDate(aEventsCat[i][0]) + ' - ' + createGermanDate(aEventsCat[i][1]) + '</div>';
			aTmp.push(sDate + '<div><a href="' + aEventsCat[i][4] + '">' + aEventsCat[i][3] + '</a></div>');
		}
	}
	if (aTmp.length > 0) {
		oClickLayer = document.getElementById('events_click_layer');
		document.getElementById('events_click_layer_date').innerHTML = '&nbsp;';//sPeriod;
		document.getElementById('events_click_layer_inner').innerHTML = aTmp.join('<div class="events_click_layer_sep">&nbsp;</div>') + '<div class="events_click_layer_sep">&nbsp;</div>';
		oClickLayer.style.display = 'inline';
		// position click layer:
		aTmp = findPos(document.getElementById('container'));
		iDiffX = aTmp[0];
		aTmp = findPos(oCaller);
		iLeft = aTmp[0] - iDiffX;
		//alert(iLeft);
		if (iLeft > 690) {
			iLeft = 690;
		}
		oClickLayer.style.left = iLeft + 'px';
		oClickLayer.style.top = aTmp[1] + 'px';
	}
}


/**
 * creates German date from timestamp
 * @param int iTime
 * @return string
 */
function createGermanDate (iTime) {
	oDate = new Date(iTime * 1000);
	//alert(oDate);
	//return '';
	sDay = oDate.getDate();
	if (sDay < 10) sDay = '0' + sDay;
	sMonth = oDate.getMonth() + 1;
	if (sMonth < 10) sMonth = '0' + sMonth;
	sYear = oDate.getYear() + (!bMsie ? 1900 : 0);
	return sDay + '.' + sMonth + '.' + sYear;
}


/**
 * @return void
 */
function hideEventsClickLayer () {
	document.getElementById('events_click_layer').style.display = 'none';
}



/* *** event sort options ******************************************************************************** */
var bSortOptionsDisplay = false;


/**
 * shows/hides sort options
 * @return void
 */
function showSortOptions () {
	aTmp = findPos(document.getElementById('container'));
	iDiffX = aTmp[0];
	bSortOptionsDisplay = !bSortOptionsDisplay;
	oCaller = document.getElementById('sort_options_link');
	aTmp = findPos(oCaller);
	oOptionsLayer = document.getElementById('sort_options_items');
	oOptionsLayer.style.display = bSortOptionsDisplay ? 'block' : 'none';
	oOptionsLayer.style.top = (aTmp[1] + oCaller.offsetHeight - 1) + 'px';
	oOptionsLayer.style.left = (aTmp[0] - iDiffX) + 'px';
}


/* *** events: downloads or details *** */
/**
 * @param int iNum
 * @return void
 */
function showEventContent (iNum) {
	sOld = iNum == 2 ? 'event_details' : 'downloads_list';
	iInactive = iNum == 0 ? 2 : 0;
	sNew = iNum == 0 ? 'event_details' : 'downloads_list';
	$('#' + sOld).fadeOut(320, function() {
		document.getElementById('sn_link_' + iInactive).className = '';
		$('#' + sNew).fadeIn(400, function() {
			// fading complete.
			document.getElementById('sn_link_' + iNum).className = 'active';
		});
	});
}



/* *** vendor details ***************************************************************************************** */
var iCurrVendorContent = 0;


/**
 * shows vendor title
 * @param int iNum
 * @return void
 */
function showVendorTitle (iNum) {
	if (document.getElementById('vendor_title') && aTitlesCompany[iNum]) {
		oTitleLayer = document.getElementById('vendor_title');
		oTitleLayer.innerHTML = aTitlesCompany[iNum];
	}
}


/**
 * shows one vendor content and hides the active one
 * @param iNum
 * @return bool
 */
function showVendorContent (iNum) {
	
	if (bMsie) {
		location.href = sHrefFirst + iNum;
	} else {
		// distinguish between light and full:
		bFull = false;
		if (!document.getElementById('sn_link_5')) {	// light version
			//var aVendorAreasTop = new Array('vendor_profile_top', 'vendor_contact_top', 'vendor_downloads_top', 'vendor_products_top');
			var aVendorAreas = new Array('#headline,#the_text,#vendor_address', '#vendor_contact', '#vendor_downloads', '#vendor_products', '#vendor_trade');
			var aVendorAreasTop = new Array('vendor_profile_top', 'vendor_profile_top', 'vendor_profile_top', 'vendor_products_top');
		} else {	// full version
			bFull = true;
			var aVendorAreas = new Array('#headline,#the_text,#vendor_address', '#vendor_contact', '#vendor_downloads', '#vendor_products', '#vendor_export', '#vendor_trade');
			var aVendorAreasTop = new Array('vendor_profile_top', 'vendor_contact_top', 'vendor_downloads_top', 'vendor_products_top', 'vendor_export_top', 'vendor_trade_top');
		}
		
		sOld = aVendorAreas[iCurrVendorContent];
		sNew = aVendorAreas[iNum];
		
		
		$(sOld).fadeOut(320, function() {
			//alert(iCurrVendorContent);
			
			if (!document.getElementById('sn_link_' + iCurrVendorContent)) {
				return false;
			}
			
			document.getElementById('sn_link_' + iCurrVendorContent).className = '';
			document.getElementById('paging_top_' + iCurrVendorContent).className = '';
			if (iNum != 1) {	// some conflict between jquery and gmaps (see a few lines below for gmaps solution)
				$(sNew).fadeIn(400, function() {
					// fading complete.
					iCurrVendorContent = iNum;
				});
			} else {
				if (!bMsie) {
					document.getElementById('vendor_contact').style.display = 'block';
					document.getElementById('vendor_contact').style.height = 'auto';
					iCurrVendorContent = iNum;
				} else {
					//alert('IE');
				}
			}
			document.getElementById('sn_link_' + iNum).className = 'active';
			document.getElementById('paging_top_' + iNum).className = 'active';
			bAnimationFinished = true;
			
			// show content at top. All only for full!
			if (bFull) {
				for (i = 0; i < aVendorAreasTop.length; i++) {
					document.getElementById(aVendorAreasTop[i]).style.display = i == iNum ? 'block' : 'none';
				}
			} else {
				if (iNum == 3) {
					document.getElementById(aVendorAreasTop[0]).style.display = 'none';
					document.getElementById(aVendorAreasTop[3]).style.display = 'block';
				} else {
					document.getElementById(aVendorAreasTop[3]).style.display = 'none';
					document.getElementById(aVendorAreasTop[0]).style.display = 'block';
				}
			}
			
			positionTriangles();
		});
	}
	
	showVendorTitle(iNum);
	
	return true;
}


/**
 * shows vendor content the fast way :)
 * @param iNum
 * @return void
 */
function showVendorContentFast (iNum) {
	if (bMsie && 2 == 1) {
		//location.href = sHrefFirst + iNum;
	} else {
		var aVendorAreasFast = new Array();
		aVendorAreasFast[0] = new Array('headline', 'the_text', 'vendor_address');
		aVendorAreasFast[1] = new Array('vendor_contact');
		aVendorAreasFast[2] = new Array('vendor_downloads');
		aVendorAreasFast[3] = new Array('vendor_products');
		if (!document.getElementById('sn_link_5')) {
			//aVendorAreasFast[4] = new Array('vendor_trade');
		} else {
			aVendorAreasFast[4] = new Array('vendor_export');
			aVendorAreasFast[5] = new Array('vendor_trade');
		}
		
		for (i = 0; i < aVendorAreasFast.length; i++) {
			aTmp = aVendorAreasFast[i];
			sDisplay = i != iNum ? 'none' : 'block';
			for (j = 0; j < aTmp.length; j++) {
				document.getElementById(aTmp[j]).style.display = sDisplay;
			}
		}
		iCurrVendorContent = iNum;
	}
	showVendorTitle(iNum);
}


/* *** vendor products *** */


var aLastProductLinkActive = new Array();

/**
 * shows product content at top. 
 * @param int iIdProduct
 * @return void
 */
function showProduct (iIdProduct, iIdSubcat) {
	resetImgAfterFlashLoad();
	//alert(iIdProduct + ', subcat: ' + iIdSubcat);
	if (iIdSubcat != iSubcatCurrent) {
		showProductsOfCat(iIdSubcat);
	}
	// now display wanted product
	aTmp = aVendorProducts[iIdSubcat];
	for (i = 0; i < aTmp.length; i++) {
		document.getElementById('product_top_' + aTmp[i][0]).style.display = aTmp[i][0] != iIdProduct ? 'none' : 'block';
		if (aTmp[i][0] == iIdProduct) {
			//alert(aTmp[i][0] + ', ' + aTmp[i][1]);
			document.getElementById('image_product_top_' + iIdSubcat).src = aTmp[i][1];
		}
	}
	
	// set active bottom:
	
	document.getElementById(aLastProductLinkActive[iIdSubcat]).className = '';
	
	aLastProductLinkActive[iIdSubcat] = 'product_link_bottom_' + iIdSubcat + '_' + iIdProduct;
	document.getElementById(aLastProductLinkActive[iIdSubcat]).className = 'active';
}


/**
 * content products top: switch subcat
 * @param int iIdSubcat
 * @return void
 */
function showProductsOfCat (iIdSubcat) {
	if (iCurrVendorContent != 3) { 
		bAnimationFinished = false;
		iHelpiIdSubcat = iIdSubcat;
		showVendorContent(3); 
		setTimeout("helpShowProductsOfCat()", 50);
	} else {
		//document.getElementById('subcat_paging_' + iSubcatCurrent).className = '';
		document.getElementById('vendor_products_top_' + iSubcatCurrent).style.display = 'none';
		//document.getElementById('subcat_paging_' + iIdSubcat).className = 'active';
		document.getElementById('vendor_products_top_' + iIdSubcat).style.display = 'inline';
		iSubcatCurrent = iIdSubcat;
		// change div in main content:
		// first get index:
		iIndex = -1;
		for (i = 0; i < aSubcats.length; i++) {
			if (aSubcats[i] == iSubcatCurrent) {
				showNewsPreview(i);
				break;
			}
		}
		positionTriangles();
		
		resetImgAfterFlashLoad();
		
		// and now open subitems (lowest level) on left side if subcat has changed:
		iIdToShow = -1;
		for (iId in aNavSubRelations) {
			aTmp = aNavSubRelations[iId];
			for (i = 0; i < aTmp.length; i++) {
				if (aTmp[i] == iIdSubcat) {
					iIdToShow = iId;
					break;
				}
			}
		}
		if (iIdToShow != -1) {
			for (iId in aNavSubRelations) {
				document.getElementById('navsub_items_caller_' + iId).className = iIdToShow == iId ? 'active' : '';
				document.getElementById('navsub_items_' + iId).className = iIdToShow == iId ? '' : 'dn';
				aTmp = aNavSubRelations[iId];
				for (i = 0; i < aTmp.length; i++) {
					document.getElementById('navsub_items_product_' + aTmp[i]).className = aTmp[i] == iIdSubcat ? 'active' : '';
				}
			}
		}
	}
}


var iHelpiIdSubcat = -1;
/**
 * help function for showProductsOfCat: If content bottom is not products then we need to change it. But there is a problem
 * with jquery actions. 
 */
function helpShowProductsOfCat () {
	if (bAnimationFinished) {
		showProductsOfCat(iHelpiIdSubcat);
	} else {
		setTimeout("helpShowProductsOfCat()", 50);
	}
}


/**
 * navigates to next or prev product
 * @param int iIdProduct
 * @param int iDir
 * @return void
 */
function navigateProduct (iIdProduct, iDir) {
	aTmp = aVendorProducts[iSubcatCurrent];
	iProduct = -1;
	if (iDir == -1) {
		for (i = 0; i < aTmp.length; i++) {
			if (aTmp[i][0] == iIdProduct) {
				break;
			}
			iProduct = aTmp[i][0];
		}
	} else {
		bNext = false;
		for (i = 0; i < aTmp.length; i++) {
			if (bNext) {
				iProduct = aTmp[i][0];
				break;
			}
			if (aTmp[i][0] == iIdProduct) {
				bNext = true;
			}
		}
	}
	if (iProduct != -1) {
		showProduct(iProduct, iSubcatCurrent);
	}
}


// for reseting img after flash360 load
var sLastImgProductContent = '';
var bFlashLoaded = false;
var sLastImgProductHtmlId = '';
var oFlashCaller = null;
var sImageViewHtmlId = '';


/**
 * shows flash with flv in certain layer
 * @param string sSwf
 * @param string sHtmlId
 * @return void
 */
function showFlashInLayer (sFlv, sHtmlId, oCaller, sImageViewHtmlIdTmp) {
	//alert(sSwf);
	if (document.getElementById(sHtmlId)) {
		sSwf = 'fileadmin/Layouts/swf/mediaplayer.swf';
		sFlashVars = 'file=http://www.g-e-f-a.de/' + sFlv + '&autostart=true&repeat=true&showdigits=false&showvolume=false&shownavigation=false';
		sLastImgProductContent = document.getElementById(sHtmlId).innerHTML;
		sContent = '<object classid="CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000" width="377" height="260" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=10,0,0,0">';
		sContent += '<param name="movie" value="' + sSwf + '">';
		sContent += '<param name="quality" value="high">';
		sContent += '<param name="scale" value="exactfit">';
		sContent += '<param name="menu" value="false">';
		sContent += '<param name="bgcolor" value="#ffffff">';
		sContent += '<param name="allowFullscreen" value="true">';
		sContent += '<param name="FlashVars" value="' + sFlashVars + '">';
		sContent += '<param name="wmode" value="transparent">';
		sContent += '<embed src="' + sSwf + '" quality="high" scale="exactfit" menu="false" ';
		sContent += 'bgcolor="#ffffff" width="377" height="260" swLiveConnect="false" FlashVars="' + sFlashVars + '" ';
		sContent += 'type="application/x-shockwave-flash" allowFullscreen="true" wmode="transparent" ';
		sContent += 'pluginspage="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">';
		sContent += '</embed>';
		sContent += '</object>';
		document.getElementById(sHtmlId).innerHTML = sContent;
		bFlashLoaded = true;
		sLastImgProductHtmlId = sHtmlId;
		oFlashCaller = oCaller;
		oCaller.style.display = 'none';
		sImageViewHtmlId = sImageViewHtmlIdTmp;
		if (document.getElementById(sImageViewHtmlId)) {
			document.getElementById(sImageViewHtmlId).style.display = 'inline';
		}
		if (oFlashCaller) {
			oFlashCaller.style.display = 'none';
		}
	}
}


/**
 * resets img after flash360 load
 * @return void
 */
function resetImgAfterFlashLoad () {
	if (bFlashLoaded) {
		if (document.getElementById(sLastImgProductHtmlId)) {
			document.getElementById(sLastImgProductHtmlId).innerHTML = sLastImgProductContent;
			bFlashLoaded = false;
			if (document.getElementById(sImageViewHtmlId)) {
				document.getElementById(sImageViewHtmlId).style.display = 'none';
			}
			if (oFlashCaller) {
				oFlashCaller.style.display = 'inline';
			}
		}
	}
}


/* vendor trade form ********************************************************************************************* */

/**
 * @param string sIncoterm
 * @return void
 */
function checkIncoTerm (sIncoterm) {
	oIncoterm = document.getElementById('incoterm_' + sIncoterm);
	if (oIncoterm.innerHTML == '&nbsp;') {
		oIncoterm.innerHTML = '<div class="checko">&nbsp;</div>';
		// last: deactivate others:
		if (sIncoterm == 'NO_INCOTERMS') {
			for (i = 0; i < aIncoterms.length - 1; i++) {
				document.getElementById('incoterm_' + aIncoterms[i]).innerHTML = '&nbsp;';
			}
		} else {
			document.getElementById('incoterm_NO_INCOTERMS').innerHTML = '&nbsp;';
		}
	} else {
		oIncoterm.innerHTML = '&nbsp;';
	}
}


/**
 * resets vendor contact form
 * @return void
 */
function resetVendorContactForm () {
	document.forms['vendor_contact_form'].reset();
	for (i = 0; i < aIncoterms.length - 1; i++) {
		document.getElementById('incoterm_' + aIncoterms[i]).innerHTML = '&nbsp;';
	}
	document.getElementById('incoterm_NO_INCOTERMS').innerHTML = '&nbsp;';
}


/**
 * submits vendor contact form if complete
 * @return bool
 */
function submitVendorContactForm () {
	bComplete = true;
	oForm = document.forms['vendor_contact_form'];
	for (i = 0; i < oForm.elements.length; i++) {
		oElement = oForm.elements[i];
		sName = oElement.name;
		if (document.getElementById('contact_req_' + sName)) {
			if (trimAll(oElement.value) == '') {
				document.getElementById('contact_req_' + sName).style.display = 'inline';
				bComplete = false;
			} else {
				document.getElementById('contact_req_' + sName).style.display = 'none';
			}
		}
	}
	
	if (!bComplete) {
		jAlert(sErrorNotComplete, sErrorNotCompleteHead);
	} else {
		// get incoterms and put them into hidden field:
		var aSel = new Array();
		for (i = 0; i < aIncoterms.length - 1; i++) {
			if (document.getElementById('incoterm_' + aIncoterms[i]).innerHTML != '&nbsp;') {
				aSel.push(aIncoterms[i]);
			}
		}
		// maybe "no incoterms" selected:
		if (document.getElementById('incoterm_NO_INCOTERMS').innerHTML != '&nbsp;') {
			aSel = new Array('NO INCOTERMS');
		}
		oForm.incoterms_selected.value = aSel.join(',');
		oForm.submit();
	}
	
	return true;
}


/**
 * trim function for javascript
 * @param string sString
 * @return string sString
 */
function trimAll (sString) {
	while (sString.substring(0, 1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length - 1, sString.length) == ' ') {
		sString = sString.substring(0, sString.length - 1);
	}
	return sString;
}



// downloads in main content ***************************************************************************************
var iDirCurrent = 0;


/**
 * shows news preview. Hides active point
 * @param int iNum
 * @return void
 */
function showDownloads (iNum) {
	sOld = 'download_item_' + iDirCurrent;
	sNew = 'download_item_' + iNum;
	$('#' + sOld).slideUp(240, function() {
		document.getElementById('download_arrow_' + iDirCurrent).src = 'fileadmin/Layouts/images/arrow_grey_down.png';
		$('#' + sNew).slideDown(200, function() {
		    // Animation complete.
			iDirCurrent = iNum;
			document.getElementById('download_arrow_' + iDirCurrent).src = 'fileadmin/Layouts/images/arrow_grey_up.png';
			
			if (bIE7) {
				//document.getElementById('d_event_list_head_').style.background = 'url(fileadmin/Layouts/images/pix.png) repeat-x bottom left';
			}
			
		}); 
	});
	if (bSafari || bMsie)
		document.getElementById(sNew).style.display = 'block';
}


// search **********************************************************************************************************
function showExtendedSearch () {
	document.forms['search_input'].search_option.value = 'all';
	document.forms['search_input'].submit();
}



// vendor export **************************************************************************************************
var iContinentCurrent = 0;
function showContinent (iNum) {
	sOld = 'continent_' + iContinentCurrent;
	sNew = 'continent_' + iNum;
	$('#' + sOld).slideUp(240, function() {
		document.getElementById('continent_arrow_' + iDirCurrent).src = 'fileadmin/Layouts/images/arrow_grey_down.png';
		$('#' + sNew).slideDown(200, function() {
		    // Animation complete.
			iContinentCurrent = iNum;
			document.getElementById('continent_arrow_' + iDirCurrent).src = 'fileadmin/Layouts/images/arrow_grey_up.png';
		}); 
	});
	if (bSafari || bMsie)
		document.getElementById(sNew).style.display = 'block';
}



// logos members start site **************************************************************************************
function showMemberTeaserText (sText) {
	document.getElementById('sbr_teaser_text').innerHTML = sText;
}



// *** ahk unternehmensreisen special ***************************************************************************



/**
 * shows ahk unternehmensreisen special header content
 * @param int iNum
 * @return bool
 */
function showAhkHeaderContent (iNum) {
	if (iNum == iCurrentAhkHeader) {
		return true;
	}
	
	bAnimationFinished = false;
	
	sOld = '#ahk_header_content_' + iCurrentAhkHeader;
	sNew = '#ahk_header_content_' + iNum;
	$(sOld).fadeOut(320, function() {
		document.getElementById('paging_top_' + iCurrentAhkHeader).className = '';
		
		$(sNew).fadeIn(400, function() {
			// fading complete.
			iCurrentAhkHeader = iNum;
			document.getElementById('paging_top_' + iNum).className = 'active';
			bAnimationFinished = true;
			positionTriangles();
		});
	});
	
	return true;
}


/**
 * changes state of ahk item element
 * @param string sIncoterm
 * @return void
 */
function checkAhkItem (iNum) {
	oItem = document.getElementById('ahk_type_el_' + iNum);
	if (oItem.innerHTML == '&nbsp;') {
		oItem.innerHTML = '<div class="checko">&nbsp;</div>';
		for (i = 0; i < 3; i++) {
			if (i != iNum) {
				if (document.getElementById('ahk_type_el_' + i))
					document.getElementById('ahk_type_el_' + i).innerHTML = '&nbsp;';
			}
		}
	} else {
		oItem.innerHTML = '&nbsp;';
	}
}


/**
 * submits ahk contact form if complete
 * @return bool
 */
function submitAhkContactForm () {
	bComplete = true;
	oForm = document.forms['vendor_contact_form'];
	for (i = 0; i < oForm.elements.length; i++) {
		oElement = oForm.elements[i];
		sName = oElement.name;
		if (document.getElementById('contact_req_' + sName)) {
			if (trimAll(oElement.value) == '') {
				document.getElementById('contact_req_' + sName).style.display = 'inline';
				bComplete = false;
			} else {
				document.getElementById('contact_req_' + sName).style.display = 'none';
			}
		}
	}
	
	if (!bComplete) {
		jAlert(sErrorNotComplete, sErrorNotCompleteHead);
	} else {
		// get incoterms and put them into hidden field:
		var aSel = new Array();
		for (i = 0; i < 3; i++) {
			if (document.getElementById('ahk_type_el_' + i)) {
				if (document.getElementById('ahk_type_el_' + i).innerHTML != '&nbsp;') {
					aSel.push(i);
				}
			}
		}
		oForm.types_selected.value = aSel.join(',');
		oForm.submit();
	}
	
	return true;
}


function resetAhkContactForm () {
	document.forms['vendor_contact_form'].reset();
	for (i = 0; i < 5; i++) {
		if (document.getElementById('ahk_type_el_' + i))
			document.getElementById('ahk_type_el_' + i).innerHTML = '&nbsp;';
	}
}


function switchJourneyToDownloads () {
	sNew = 'downloads_list';
	sOld = 'further_content_0';
	$('#' + sOld).fadeOut(240, function() {
		$('#' + sNew).fadeIn(200, function() {
		    // Animation complete.
		}); 
	});
	if (bSafari || bMsie)
		document.getElementById(sNew).style.display = 'block';
}




function switchContent (iNum) {
	// hide previous content. Find current displayed content
	//alert(iMainContentDisplayed);
	if (iMainContentDisplayed < 0) iMainContentDisplayed = 0;
	sLayerIdOld = 'further_content_' + iMainContentDisplayed;
	sLayerIdNew = 'further_content_' + iNum;
	
	//alert(sLayerIdOld + ',' + sLayerIdNew);
	$('#' + sLayerIdOld).fadeOut(320, function() {
		if (document.getElementById('ns_link_' + iMainContentDisplayed)) {
			document.getElementById('ns_link_' + iMainContentDisplayed).className = '';
		}
		$('#' + sLayerIdNew).fadeIn(400, function() {
			// fading complete.
			iMainContentDisplayed = iNum;
			document.getElementById('ns_link_' + iMainContentDisplayed).className = 'active';
		});
	});
}

