

//show Box position=relative top=0
function showBoxPosRelTop0(selector){
	if(document.getElementById(selector)){
		  document.getElementById(selector).style.position="relative";
		  document.getElementById(selector).style.top="0";
	}
}



$().ready(function() {


	//main menu overview
	$('#mainMenu ul li').each(function (i) {
		if ($(this).find('ul').html()){
			$(this).find('ul').prepend('<li><a href="' + $(this).find("a").attr("href") + '">' + getCommonLabel('overview') + '</a></li>');
		}
	});
	    //footer menu overview
    $('#footer ul li').each(function (i) {
        if ($(this).find('ul').html()){
            $(this).find('ul').prepend('<li><a href="' + $(this).find("a").attr("href") + '">' + getCommonLabel('overview') + '</a></li>');
        }
    });



	//footer foldout
	$(".footerNavigation > ul > li").live("mouseover mouseout", function(e){
		if (e.type == "mouseover"){
			$(".footerNavigation > ul > li").css("border","1px solid transparent")
			$(this).css({"border":"1px solid #D3DBDD","border-bottom":"none"});
			if ($(this).find("ul").html()){
				$(".footerNavigationLevel2").html("<ul>" + $(this).find("ul").html() + "</ul>");
			}else{
				$(".footerNavigationLevel2").empty();
			}
		}else{
			if (!$(this).find("ul").html()){
				$(".footerNavigation > ul > li").css("border","1px solid transparent");
			}
		}
	});

});



function getCommonLabel(value){
	var overviewLabel = 'Overview';
	$.ajax({
		url: '../translation-common.xml',
		dataType: 'xml',
		async: false,
		success: function(xml){
			overviewLabel = $(xml).find(value).text()
		}
	});
	return overviewLabel;
}



//tabBox
function tabBox(id){
  $("#tabMenu"+ id).show();
  $("#tabBox"+ id +" .tabBoxItem").hide();
  tabMenu = "<ul>";
  $("#tabBox"+ id +" .tabBoxItem .tabBoxItemHeadline").each(function(index){
      linkId = $(this).parent(".tabBoxItem").attr("id");
      tabMenu += "<li><a href=\"#\" onclick=\"showTab('"+ id +"', '"+ linkId +"');return false;\" id=\"link"+ linkId +"\"><span class=\"tabMenuBackgroundLeft\"><span class=\"tabMenuBackgroundRight\"><span class=\"tabMenuItem\">" + $(this).text() + "</span></span></span></a></li>";
  });
  tabMenu += "</ul><div class='tabMenuBottom'><!--background--></div>"
  first = $("#tabBox"+ id +" .tabBoxItem .tabBoxItemHeadline").parent(".tabBoxItem").attr("id");
  $("#tabMenu"+ id).html(tabMenu);
  showTab(id, first);
}
function showTab(menuId, id){
  $("#tabMenu"+ menuId +" a").attr("class", "");
  $("#link"+ id).attr("class", "active");
  $("#tabBox"+ menuId +" .tabBoxItem").hide();
  $("#"+ id).show();
}



//hide text hidden by id, add button
function expandText(id,buttonTextAdd,buttonTextSub){
  $("#textHidden" + id).hide();
  $("#textHiddenButton" + id).append("<ul><li class='button'><a href='#' id='"+id+"_link' onclick='handleExpandText(\""+id+"\",\""+buttonTextAdd+"\",\""+buttonTextSub+"\");return false'></a></li></ul>");
  $("#"+ id +"_link").text(buttonTextAdd);
}
//show or hide text hidden
function handleExpandText(id,buttonTextAdd,buttonTextSub){
  if($("#textHidden"+ id).is(":visible")){
    $("#textHidden" + id).hide();
    $("#"+ id +"_link").text(buttonTextAdd);
  }
  else{
    $("#textHidden" + id).show();
    $("#"+ id +"_link").text(buttonTextSub);
  }
}



//show more
function showMore(id){
	if($("#d_" + id ).is(":visible")){
		$("#d_" + id ).hide();
		$("#a_" + id ).show();
		$("#ml_" + id ).hide();
	}else{
		$("#d_" + id ).show();
		$("#a_" + id ).hide();
		$("#ml_" + id ).show();
	}
}



//clickgallery
function clickGallery(id, inext, innextlight, inexttitle, iprev, iprevlight, iprevtitle, txtcounter){
	$(id).clickGalleryBox({
		iconNext: inext,
		iconNextLight: innextlight,
		iconNextAltTitle: inexttitle,
		iconPrev: iprev,
		iconPrevLight: iprevlight,
		iconPrevAltTitle: iprevtitle,
		textCounter: txtcounter
	});
}

$.fn.clickGalleryBox = function(p){
	var s = $.extend({
		boxItem: ".galleryBox",
		iconNext: "",
		iconNextLight: "",
		iconNextAltTitle: "",
		iconPrev: "",
		iconPrevLight: "",
		iconPrevAltTitle: "",
		textCounter: "",
		defautItem: 1
	}, p);
	$(this).each(function() {
		var galleryId = "#" + this.id;
		var itemCounter = $(galleryId + " > " + s.boxItem).length;
		if (itemCounter > 1){
			showItem(s.defautItem);
		}
		function showItem(itemNr){
			$(galleryId + " .galleryNavigation").empty();
			$(galleryId + " .galleryNavigation").show();
			$(galleryId + " " + s.boxItem).hide();
			$(galleryId + " " + s.boxItem + ":eq(" + (itemNr-1) + ")").show();
			galleryItemId = "#" + $(galleryId + " " + s.boxItem + ":eq(" + (itemNr-1) + ")").attr("id");
			switch(itemNr){
			case 1:
			  $(galleryItemId + " .galleryNavigation").append('<div class="galleryNavigationButton"><a id="galleryNavigationNext" title="' + s.iconNextAltTitle + '" href="#"><img class="imgBlock" src="' + s.iconNext + '" width="18" height="18" alt="' + s.iconNextAltTitle + '" /></a></div><div class="galleryNavigationText">' + itemNr + ' ' + s.textCounter + ' ' + itemCounter + '</div><div class="galleryNavigationButton"><img class="imgBlock" src="' + s.iconPrevLight + '" width="18" height="18" alt="" /></div>');
			  break;
			case itemCounter:
			  $(galleryItemId + " .galleryNavigation").append('<div class="galleryNavigationButton"><img class="imgBlock" src="' + s.iconNextLight + '" width="18" height="18" alt="" /></div><div class="galleryNavigationText">' + itemNr + ' ' + s.textCounter + ' ' + itemCounter + '</div><div class="galleryNavigationButton"><a id="galleryNavigationPrev" title="' + s.iconPrevAltTitle + '" href="#"><img class="imgBlock" src="' + s.iconPrev + '" width="18" height="18" alt="' + s.iconPrevAltTitle + '" /></a></div>');
			  break;
			default:
			  $(galleryItemId + " .galleryNavigation").append('<div class="galleryNavigationButton"><a id="galleryNavigationNext" title="' + s.iconNextAltTitle + '" href="#"><img class="imgBlock" src="' + s.iconNext + '" width="18" height="18" alt="' + s.iconNextAltTitle + '" /></a></div><div class="galleryNavigationText">' + itemNr + ' ' + s.textCounter + ' ' + itemCounter + '</div><div class="galleryNavigationButton"><a id="galleryNavigationPrev" title="' + s.iconPrevAltTitle + '" href="#"><img class="imgBlock" src="' + s.iconPrev + '" width="18" height="18" alt="' + s.iconPrevAltTitle + '" /></a></div>');
			}
		}
		$(galleryId + " #galleryNavigationNext").live("click", function(e) {
			e.preventDefault();
			galleryNavigationTextId = "#" + $(this).parent().parent().parent().parent().attr("id");
			showItem(parseInt($(galleryNavigationTextId + " .galleryNavigationText").text().substring(0, $(galleryNavigationTextId + " .galleryNavigationText").text().indexOf(" "))) + 1);
		});
		$(galleryId + " #galleryNavigationPrev").live("click", function(e) {
			e.preventDefault();
			galleryNavigationTextId = "#" + $(this).parent().parent().parent().parent().attr("id");
			showItem(parseInt($(galleryNavigationTextId + " .galleryNavigationText").text().substring(0, $(galleryNavigationTextId + " .galleryNavigationText").text().indexOf(" "))) - 1);
		});
	});
}



