/* --- Teaser Boxes (start) --- */

function hideTeaserBox(el) {
    $(el).parent().animate({
        marginTop: '175px'
    }, 1000);
    $(el).find('img.toggle').attr('src', IMG_TOGGLE);
}
function showTeaserBox(el) {
    $(el).parent().animate({
        marginTop: '0px'
    }, 1000);
    $(el).find('img.toggle').attr('src', IMG_TOGGLED);
}

/* --- Teaser Boxes (products) --- */

/**
 * Hides a single product teaser box
 *
 * @param el element div.headline
 */
function hideProdTeaserBox(el) {
    $(el).parent().animate({
        height: '35px'
    }, 1000);
    $(el).find('img.toggle').attr('src', IMG_TOGGLE);
}
/**
 * Shows a single product teaser box
 *
 * @param el object div.headline element
 */
/*
function showProdTeaserBox(el) {
    // unbind event handler and rebind in the animations callback handler
    // to avoid event flooding
//     $('div.prodBox div.headline').unbind('mouseover');
    $(el).parent().animate({
        height: '210px'
    }, 1000, 'linear', function() {
//          $('div.prodBox div.headline').bind('mouseover', mouseoverProdBox);
    });
    $(el).find('img.toggle').attr('src', IMG_TOGGLED);
}
*/
function showProdTeaserBox(el) {
    /* 
		unbind event handler and rebind in the animations callback handler
		to avoid event flooding
	*/
    $('div.prodBox div.headline').unbind('mouseover');
    $(el).parent().animate({
        height: '210px'
    }, 1000, 'linear', function() {
        $('div.prodBox div.headline').bind('mouseover', mouseoverProdBox);
    });
    $(el).find('img.toggle').attr('src', IMG_TOGGLED);
}

/**
 * Hides all open product teaser boxes except the one with the passed id
 * (supposed to be the open one)
 *
 * @param curId string product box id (e.g. "prod-1")
 */
function hideOtherProdTeaserBoxes(curId) {
    $('div.prodBox').each(function(i) {
        if($(this).attr('id') != curId) {
           hideProdTeaserBox($(this).find('div.headline')[0]);
        }
    });
}

var timerProdboxToggle;

function mouseoverProdBox() {
    if($(this).find('img.toggle').attr('src') == IMG_TOGGLE) {
        showProdTeaserBox(this);
		if(timerProdboxToggle) {
			window.clearTimeout(timerProdboxToggle);
		}
		timerProdboxToggle = window.setTimeout("hideProdbox($(this).parent().attr('id'))", 5000);
        hideOtherProdTeaserBoxes($(this).parent().attr('id'));
    }
}

function hideProdbox(element) {
	hideOtherProdTeaserBoxes(element);
}

function mouseoutProdBox() {
    $('div.prodBox').each(function(i) {
        hideProdTeaserBox($(this).find('div.headline')[0]);
    });
}


function showThema(themaId) {
	var liliste = $("#themaNavi").children("ul").children("li");
	for( i=0; i < liliste.length; i++){
		$(liliste[i]).removeClass("active");
	}
	$(liliste[themaId-1]).addClass("active");
	$("#idBgLayer"+visibleThema).fadeOut("slow",function(){
		$("#thema"+visibleThema).fadeOut("slow");
		$("#idBgLayer"+themaId).fadeIn("slow");
		if ( $.browser.msie && ($.browser.version == '7.0') ) {
			/* $("#thema"+themaId).show(); */
			$("#thema"+themaId).fadeIn("slow",function(){
    				this.style.removeAttribute("filter");
			});
		}		
		else {
			$("#thema"+themaId).fadeIn("slow");
		}
		visibleThema = themaId;
	});
}

function themenWechsel() {
	if(anzahlThemen > 1) {
		var themaId;
		if( parseInt(visibleThema) == parseInt(anzahlThemen) ) {
			themaId = 1;
		}
		else {
			themaId = visibleThema + 1;
		}
		showThema(themaId);
	}
}

var hiddenField;
var numberBoxLayer;
var activeBoxLayer;

var prodID;

/* window.onresize = resizeElements(); */

$(document).ready(function(){

	$("#search").attr({ autocomplete:"off" });
	
	$(".dragImg").css("z-index","999");
	$(".dragImg").draggable({
		appendTo:'#hiddenLayer',
		zIndex:1000,
		revert:true
	});

	$(".quadrat").droppable({
		accept: ".dragImg",
		/* accept: "#gz_radio,#gz_auto,#gz_einkauf,#gz_flakon,#gz_kamm,#gz_tee,#gz_kalender,#gz_birne,#gz_lupe,#gz_computer,#gz_fueller,#gz_geschenk", */
		over: function(ev, ui) {
			$(this).css("background","#009DE0");
		},
		out: function(ev, ui) {
			$(this).css("background","#fff");
			if($(ui.draggable).attr("id") == $(this).children("img").attr("id") ) {
				hiddenField = $(this).children("input");
			}
		},
			drop: function(ev, ui) {
				if(!$(this).children("img").attr("id")) {
					$(ui.draggable).remove().appendTo($(this));
					$(ui.draggable).css("position","absolute");
					$(ui.draggable).css("top","0px");
					$(ui.draggable).css("left","0px");
					$(ui.draggable).css("z-index","999");
					$(ui.draggable).draggable({
						appendTo: '#hiddenLayer',
						zIndex:1000,
						revert:true
						});
					$(hiddenField).val("");
					$(this).children("input").val($(ui.draggable).attr("src"));
				}
		}
	});	


	/*
	$("#gz_radio").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_auto").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_einkauf").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_flakon").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_kamm").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_tee").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_kalender").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_birne").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_lupe").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_computer").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_fueller").draggable({appendTo: 'body',zIndex:1500,revert:true});
	$("#gz_geschenk").draggable({appendTo: 'body',zIndex:1500,revert:true});
	*/

	
	/* ----- Teaserboxes ----- */

    /*IMG_TOGGLE  = '/media/layout/img/boxen/toggle.gif';
    IMG_TOGGLED = '/media/layout/img/boxen/toggled.gif';*/
    IMG_TOGGLE  = '/media/layout/img/boxen/toggle_210.gif';
    IMG_TOGGLED = '/media/layout/img/boxen/toggled_210.gif';
	
	/*
	// Boxen auf der Startseite werden nacheinander eingeblendet -
	// Reihenfolge:
	// 1. rechte Boxen
	// - rechts oben
	// - rechts unten
	// 2. Slider von rechts nach links
	*/
	alleBoxen = $('#rechteBox1').children();
	objekt1 = $(alleBoxen[0]);
	setTimeout("objekt1.slideDown('slow')", 1000);
	objekt2 = $(alleBoxen[1]);
	setTimeout("objekt2.slideDown('slow')", 2000);
	setTimeout("$('body#start .boxLayer .box').slideDown('slow')", 7000);

    setTimeout("$('body#start div#teaserBox-3').slideDown('fast')", 3000);
    setTimeout("$('body#start div#teaserBox-2').slideDown('fast')", 4000);
    setTimeout("$('body#start div#teaserBox-1').slideDown('fast')", 5000);
	

	/* wenn im Homeobjekt der Boxwechsel aktiviert ist */
	if( $('#rechteBox2').length ) {
		activeBoxLayer = 1;
		if( $('#rechteBox2').length ) {
			numberBoxLayer = 2;
		}
		if( $('#rechteBox3').length ) {			
			numberBoxLayer = 3;
		}
		setTimeout("boxLayerRotation()", 10000);
	}
	
	/*
    // --- Start / 1stLvlNav
	// Slidereffekt auf der Startseite deaktiviert - um wieder zu aktivieren: if/else-Bedingung rausnehmen -- fz-09-12-16
	// if( $('#start div.teaserBox div.headline').length == 0 ) {
	*/
		$('div.teaserBox div.headline').mouseover(function() {
	        if($(this).find('img.toggle').attr('src') == IMG_TOGGLE) {
	            if($(this).parent().attr('id') == 'teaserBox-1') {
	                showTeaserBox(this);
	                hideTeaserBox($('div#teaserBox-2').find('div.headline'));
	                hideTeaserBox($('div#teaserBox-3').find('div.headline'));
	            } else if($(this).parent().attr('id') == 'teaserBox-2') {
	                showTeaserBox(this);
	                hideTeaserBox($('div#teaserBox-1').find('div.headline'));
	                hideTeaserBox($('div#teaserBox-3').find('div.headline'));
	            } else if($(this).parent().attr('id') == 'teaserBox-3') {
	                showTeaserBox(this);
	                hideTeaserBox($('div#teaserBox-1').find('div.headline'));
	                hideTeaserBox($('div#teaserBox-2').find('div.headline'));
	            }
	        }
		});
	/* }
	else {
		showTeaserBox($('div#teaserBox-1'));
		showTeaserBox($('div#teaserBox-2'));
		showTeaserBox($('div#teaserBox-3'));
		$('div#teaserBox-1').removeClass("teaserBoxToggled");
		$('div#teaserBox-2').removeClass("teaserBoxToggled");
		$('div#teaserBox-3').removeClass("teaserBoxToggled");
	} */
	
    /* --- Products */

    $('div.prodBox div.headline').mouseover(mouseoverProdBox);
    /* hide open box on mouseout */
    /* $('div.prodBox div.body').mouseout(mouseoutProdBox); */

	/* ----- Toolbox ----- */

    /* Increase/decrease font size */
    var init = true;
    $('img#incFontsize').click(function() {
        /*
			ie em bug: reports wrong initial font-size for content 
			9px instead of 12px, add the difference on page init
		*/
        var curFontSize = $('div#content').css('font-size');
        if($.browser.msie && init) {
            curFontSize = (parseInt(curFontSize) + 3) + 'px';
            init = false;
        }
        var curFontSizeNum = parseInt(curFontSize, 10);
        var newFontSize = curFontSizeNum + 1;
        $('div#content').css('font-size', newFontSize);
        return false;
    });
    $('img#decFontsize').click(function() {
        var curFontSize = $('div#content').css('font-size');
        var curFontSizeNum = parseInt(curFontSize, 10);
        var newFontSize = curFontSizeNum - 1;
        $('div#content').css('font-size', newFontSize);
        return false;
    });
    /* Print */
    /*
    $('img#print').click(function() {
        window.print();
        return false;
    });
    */

	/* ----- Search ----- */

    /* Clear search text */
    $('input.searchText').click(function() {
        if($(this).attr('value') == 'Suchbegriff eingeben') {
            $(this).attr('value', '');
        }
    });
    /* Search suggest */
    $('#search').keyup(function() {
        /* var searchText = encodeURIComponent($('input.searchText').attr('value')); */
        var searchText = $('input.searchText').attr('value');
        if( searchText.length > 1 ) {
            $.get('/de/meta/suche/ajaxsuche.html', { q: searchText, js: 1 }, function(data) {
                $('div#searchSuggest').html(data);
                /* $('div#searchSuggest').text(data); */
            });
            if($('div#searchSuggest').css('display') == 'none') {
                $('div#searchSuggest').css('display', 'block');
            }
        }
    });
    $('body').click(function() {
        if($('div#searchSuggest').css('display') == 'block') {
            $('div#searchSuggest').css('display', 'none');
        }
    });

	/* ----- Misc ----- */

	/* Recommend product */
    $('a.prod-recommend').click(function() {
		arrayScrollDimension = getPageScroll();			
		$('div#prod-recommend-container').css('top', arrayScrollDimension[1]+"px");
        $('div#prod-recommend-container').toggle();
        if($('div#prod-recommend-container').css('display') == 'block') {
            $('div#prod-recommend-container input').removeAttr('disabled');
            $('div#prod-recommend-container textarea').removeAttr('disabled');
        }
		showOverlayLayer(1);
		
		/*
		transLayer = document.createElement('div');
		var width = document.body.clientWidth;
		var height = document.body.clientHeight;

		leftPosTransLayer = (992 - document.body.clientWidth)/2;

		// inline css fuer IE:
		$(transLayer).css("left",leftPosTransLayer+"px");
		$(transLayer).css("width",width);
		$(transLayer).css("height",height);
		$(transLayer).css("background-color","#000");
		$(transLayer).css("-moz-opacity","0.3");
		$(transLayer).css("opacity",".3");
		$(transLayer).css("filter","alpha(opacity=30)");
		$(transLayer).css("display","none");
		$(transLayer).addClass("transLayer");
		$("#contentLayer").append($(transLayer));		
		$(transLayer).css("display","block");
		*/
        return false;
    });
	
    $('input#prod-recommend-close').click(function() {
        $('div#prod-recommend-container').hide();
        $('form#prod-recommend').clearForm();
        $('div#prod-recommend-container p#prod-recommend-output').removeClass('prod-recommend-error');
        $('div#prod-recommend-container p#prod-recommend-output').html('Bitte f&uuml;llen Sie das Formular vollst&auml;ndig aus.');
		showOverlayLayer(0);
		/* $(transLayer).css("display","none"); */
		/* $(transLayer).remove(); */
        return false;
    });
	
    $('input#prod-recommend-close-z').click(function() {
        $('div#prod-recommend-container').hide();
        $('form#prod-recommend').clearForm();
        $('div#prod-recommend-container p#prod-recommend-output').removeClass('prod-recommend-error');
        $('div#prod-recommend-container p#prod-recommend-output').html('Bitte f&uuml;llen Sie das Formular vollst&auml;ndig aus.');
		showOverlayLayer(0);
		/* $(transLayer).css("display","none"); */
		/* $(transLayer).remove(); */
		$('#theForm').css("display","block");
		$('#theCloseForm').css("display","none");
        return false;
    });

    /* Product recommend form */
    $('form#prod-recommend').ajaxForm({
        target:       'div#prod-recommend-container p#prod-recommend-output', /* target element(s) to be updated with server response */
        beforeSubmit: validate, /* pre-submit callback */
        success:      showSuccess, /* post-submit callback */
        clearForm:    true
    });
    function validate(formData, jqForm, options) {
        var form = jqForm[0];
        if(!form['rec-firstname-sender'].value || !form['rec-lastname-sender'].value || !form['rec-email-sender'].value ||
           !form['rec-firstname-recipient'].value || !form['rec-lastname-recipient'].value || !form['rec-email-recipient'].value
        ) {
            $('div#prod-recommend-container p#prod-recommend-output').addClass('prod-recommend-error');
            return false;
        }
    }
    function showSuccess(responseText, statusText)  {
		$('#theForm').css("display","none");
		$('#theCloseForm').css("display","block");
        $('div#prod-recommend-container p#prod-recommend-output').removeClass('prod-recommend-error');
        $('div#theForm input').attr('disabled', true);
        $('div#theForm textarea').attr('disabled', true);
        $('div#theForm input#prod-recommend-close').removeAttr('disabled');		
    }
	
    $('input.breakProdBewertung').click(function() {
        $('div#prodBewertPopup').hide();
		$(".popup_overlay").css("z-index","1000");
		showOverlayLayer(0);
		return false;
    });	
	
    /* Produktbwertung */
    $('form#formProdBewertung').ajaxForm({
        /* target:       '#prodBewertPopup p#prod-recommend-output', // target element(s) to be updated with server response */
        beforeSubmit: validateBewertung, /* pre-submit callback */
        success:      showSuccessBewertung, /* post-submit callback */
        clearForm:    true
    });
    function validateBewertung(formData, jqForm, options) {
        var form = jqForm[0];
		/* alert(form['bewertung'].value); */
        if(form['bewertung'].value == '-1' ) {
            $('#prodBewertPopup p.errorText').css('display','block');
            return false;
        }
		else {
			prodID = form['prodid'].value;
			$('#prodBewertPopup p.errorText').css('display','none');
			return true;
		}
    }
    function showSuccessBewertung(responseText, statusText)  {
		$.ajax({
			type: "POST",
			url: "/de/meta/includes/produktbewertungajax.html",
			data: "prodID="+prodID,
			success: function(data){
				$("#bewertungsContainer").html(data);
			}
		});
		$('#bewertungsLayer').css('display','none');
		$('#bewertungErfolgtLayer').css('display','block');
    }
	
	if(typeof themaWechsel != "undefined") {
		timer = window.setInterval("themenWechsel()", themaWechselInterval);
	}
	getTeaserLayer();
    /* Contact form */
    /*$('input#contactCancel').click({
        //$('input#contactCancel input').attr('value', '');
        //return false;
    });*/
	
	
	$(".pblLevel220 .spalte").click(function () {
		var hrefBoxlink = $(this).children(".headline").children(".boxLink").attr("href");
		window.location.href = hrefBoxlink;
	});
	
	$(".pblLevel220 .spalte").mouseover(function () {
		$(this).css("cursor","pointer");
	});
	
	/* Landingpage Produktteaser */
	$(".prodBild").css("cursor","pointer");
	$(".prodBild").click(function () {
		var prodLink = $(this).parent().children(".nextThemeLink").children("a").attr("href");
		window.location.href = prodLink;
	});
	$(".prodName").css("cursor","pointer");
	$(".prodName").click(function () {
		var prodLink = $(this).parent().children(".nextThemeLink").children("a").attr("href");
		window.location.href = prodLink;
	});
	
	/* InitialWert für Slider */
	rightLimit = $(".sliderContentContainer").width() - $(".sliderContent").width();
	checkNavRightToShow();
	
	$(window).resize(function() {
		resizeElements();
	});

	$(window).scroll(function() {
		resizeElements();
	});
});

var direction;
var sliderPos = 0;
var timerSlider = null;
var directionTMP;
var stepSize = 7;
var navLeftIsVis = false;
var navRightIsVis = true;
var rightLimit = 0;

function checkNavRightToShow() {
	if(rightLimit > 0 ) {
		$(".sliderLayer .navRight").css("display","none");
		navRightIsVis = false;		
	}
}


function slide(direction, job) {
	directionTMP = direction;
	if( job == 1 ) {
		timerSlider = window.setInterval("slideAction()", 5);
	}
	else {
		window.clearInterval(timerSlider);
	}
}

function slideAction() {
	/* Slide links/rechts wird bestimmt */
	if( directionTMP == "left" ) {
		sliderPos = sliderPos + stepSize;
	}
	else {
		sliderPos = sliderPos - stepSize;
	}
	/* SlideEffekt darf nur so lange laufen wie auch Element da sind */
	/* Linke Begrenzung */
	if ( sliderPos > 0 ) {
		sliderPos = 0;
		window.clearInterval(timerSlider);
	}
	/* rechte Begrenzung */
	if ( sliderPos < rightLimit ) {
		sliderPos = rightLimit;
		window.clearInterval(timerSlider);
	}
	/* linker NavButton wird ein/ausgeblendet bei bestimmten LayerPositionen */
	if ( sliderPos < 0 && !navLeftIsVis ) {
		$(".sliderLayer .navLeft").fadeIn("slow");
		navLeftIsVis = true;
	}
	if ( sliderPos == 0 && navLeftIsVis ) {
		$(".sliderLayer .navLeft").fadeOut("slow");
		navLeftIsVis = false;
	}
	/* rechter NavButton wird ein/ausgeblendet bei bestimmten LayerPositionen */
	if ( sliderPos > rightLimit && !navRightIsVis ) {
		$(".sliderLayer .navRight").fadeIn("slow");
		navRightIsVis = true;
	}
	if ( sliderPos == rightLimit && navRightIsVis ) {
		$(".sliderLayer .navRight").fadeOut("slow");
		navRightIsVis = false;
	}
	$(".sliderContent").css("left", sliderPos+"px")
}


var elBlocked = false;
var tmpElement = null;
var arrElements = new Array();
arrElements[1] = new Object();
var timerIsRunning = false;

function showChildren(element,level) {
	if(!elBlocked ) {
		if( $(element).parent("li").children("ul").attr("class").indexOf("open"+level) == -1) {
			tmpElement = element;
			elBlocked = true;
			/*
			$("ul.open"+level).slideToggle(700,function() {
				$("ul").removeClass("open"+level);
				//elBlocked = false;
			});
			*/
			$(element).children("img").css("background","url(/media/layout/img/arrow_expand.gif)");
			$(element).parent("li").children("ul").slideToggle(700,function() {
				$(element).parent("li").children("ul").addClass("open"+level);
				arrElements[1][$(element).parent("li").children("ul").attr("id")] = 10;
				elBlocked = false;
			});
			if(!timerIsRunning) {
				timerIsRunning = true;
				/* window.setInterval("hideChildren()", 1000); */
			}
		}
		else {
			/* arrElements[1][$(element).parent("li").children("ul").attr("id")] = 10; */
			$(element).children("img").removeAttr("style");
			$(element).parent("li").children("ul").removeClass("open"+level);
			$(element).parent("li").children("ul").slideToggle(700,function() {
				$(this).removeAttr("class");
			});		
		}
	}
}

function hideChildren() {
	/* console.log(arrElements.length); */
	$.each(arrElements[1], function(key,value) {
		/* console.log(value); */
		value = value-1;
		if( value == 0 ) {
			$("ul#"+key).slideToggle(700,function() {
				$(this).removeAttr("class");
			});
			arrElements[1][key] = -1;
		}
		else {
			arrElements[1][key] = value;
		}
	});
}

var teaserLayerArray = new Array();

function getTeaserLayer() {
	homeTeaserLayerList = $("#contentLayer").children(".homeTeaserLayer");
	counter = 0;
	for( var i = 0; i < homeTeaserLayerList.length; i++) {
		var teaserLayerList = $(homeTeaserLayerList[i]).children(".teaserLayer").children("div");
		if(teaserLayerList.length > 1 ) {
			teaserLayerArray[counter] = new Array();
			teaserLayerArray[counter][0] = 1;
			for( var j = 0; j < teaserLayerList.length; j++) {
				teaserLayerArray[counter][j+1] = $(teaserLayerList[j]).attr("id") ;
			}
			counter++;
		}
	}
	if(typeof teaserWechselInterval != "undefined") {
		timerHTWechsel = window.setInterval("startHomeTeaserWechsel()", teaserWechselInterval);
	}
}

function startHomeTeaserWechsel() {
	for( var i = 0; i < teaserLayerArray.length; i++) {
		if( (teaserLayerArray[i][0])  == teaserLayerArray[i].length - 1 ) {
			showLayer = 1;
		}
		else {
			showLayer = teaserLayerArray[i][0] + 1 ;
		}
		$("#"+teaserLayerArray[i][showLayer]).css("display","block");
		$("#"+teaserLayerArray[i][teaserLayerArray[i][0]]).css("display","none");
		teaserLayerArray[i][0] = showLayer;
	}
}


/* Boxwechsel rechte Boxen Startseite */
function boxLayerRotation() {
	$('#rechteBox'+this.activeBoxLayer).css("display","none");
	if( this.activeBoxLayer ==  this.numberBoxLayer ) {
		this.activeBoxLayer = 1;
	}
	else {
		this.activeBoxLayer = this.activeBoxLayer+1;
	}
	$('#rechteBox'+activeBoxLayer).fadeIn("slow");
	setTimeout("boxLayerRotation()", 5000);
}


function addEvents(){
	var dasElement = document.getElementById("mainnav").childNodes;
	for (i = 0; i < dasElement.length; i++){
		if(dasElement[i].tagName == "UL"){
			dieLiKinder = dasElement[i].childNodes;
			for (j = 0; j < dieLiKinder.length; j++){
				if(dieLiKinder[j].tagName == "LI"){
					dieUlEnkel = dieLiKinder[j].childNodes;
					$(dieLiKinder).mouseover( function() { zeige(this,1,1); } );
					$(dieLiKinder).mouseout( function() { zeige(this,0,1); } );
					for (k = 0; k < dieUlEnkel.length; k++){
						if(dieUlEnkel[k].tagName == "UL"){
							dieLiEnkel = dieUlEnkel[k].childNodes;
							for (l = 0; l < dieLiEnkel.length; l++){
								if(dieLiEnkel[l].tagName == "LI"){
									$(dieLiEnkel).mouseover( function() { zeige(this,1,2); } );
									$(dieLiEnkel).mouseout( function() { zeige(this,0,2); } );
								}
							}
						}
					}
				}
			}
		}
	}
}

/*
function addEvents(){
	$("#mainnav ul li").mouseover( function() { zeige(this,1,1); } );
	$("#mainnav ul li").mouseout( function() { zeige(this,0,1); } );
	$("#mainnav ul li ul li").mouseover( function() { zeige(this,1,2); } );
	$("#mainnav ul li ul li").mouseout( function() { zeige(this,0,2); } );
}
*/

function toggleLayer(objekt) {
	divToggleLayer = $(objekt).parent("h2").parent("div").parent("div");
	divChild = $(objekt).parent("h2").parent("div").parent("div").children("div.toggleBody");
	if(! divToggleLayer.hasClass("noexpand")) {
		divChild.slideToggle("slow",function(){
			divToggleLayer.addClass("noexpand");
			if(divToggleLayer.parent("div").attr("id") == "contentMain" ) {
				divToggleLayer.animate({marginBottom:10},"fast");
			}
		});		
	}
	else {
		if(divToggleLayer.parent("div").attr("id") == "contentMain" ) {
			divToggleLayer.animate({marginBottom:0},"fast");
		}
		divChild.slideToggle("slow",function(){
			divToggleLayer.removeClass("noexpand");
		});
	}	
}

var timer;
var ulObjekt;

function zeige(objekt,aktion,ebene,mausaktion) {
/*
	if( ebene == 2 && aktion == 1 ) {
		$(objekt).children("a").addClass("overSecond");
	}
	if( ebene == 2 && aktion == 0 ) {
		$(objekt).children("a").removeClass("overSecond");
	}
*/
	if( ebene == 1 && aktion == 1 ) {
		$(objekt).children("a").addClass("overFirst");
	}
	if( ebene == 1 && aktion == 0 ) {
		$(objekt).children("a").removeClass("overFirst");
	}
	ulObjekt = objekt;
	if(timer) {
		clearTimeout(timer);
	}
	if(aktion == 1){
		$(objekt).children("ul").css("display","block");
	}

	if( aktion == 0 ){
		if($(objekt).children('ul'))$(objekt).children('ul').css('display','none');
		/* timer = setTimeout("verstecke(ulObjekt);", 100); */
	}
}

function zeigeMegaDropdown(objekt,aktion,ebene,mausaktion) {
/*
	if( ebene == 2 && aktion == 1 ) {
		$(objekt).children("a").addClass("overSecond");
	}
	if( ebene == 2 && aktion == 0 ) {
		$(objekt).children("a").removeClass("overSecond");
	}
*/
	if( ebene == 1 && aktion == 1 ) {
		$(objekt).children("a").addClass("overFirst");
	}
	if( ebene == 1 && aktion == 0 ) {
		$(objekt).children("a").removeClass("overFirst");
	}
	ulObjekt = objekt;
	if(timer) {
		clearTimeout(timer);
	}
	if(aktion == 1){
		$(objekt).children(".mgp").css("display","block");
		if ( $.browser.msie && ( ($.browser.version == '7.0') || ($.browser.version == '6.0') ) ) {
			$("#contentLayer").css("z-index","-1");
		}
	}

	if( aktion == 0 ){
		if($(objekt).children('.mgp')) {
			$(objekt).children('.mgp').css('display','none');
		}
		/* timer = setTimeout("verstecke(ulObjekt);", 100); */
	}
}


function insertMgaElement(mgaElement,theUrl) {
	$.get('/de/meta/includes/megadropdown_fuer_ajax.php', { mgaElement: mgaElement, theUrl: theUrl }, function(data) {
		$("#li_"+mgaElement).append(data);
	});
}


function verstecke(objekt) {
	/* $(objekt).children('ul').css('display','none'); */
	setTimeout("$(objekt).children('ul').css('display','none';", 150);
}

function showLayer(aktion,layer) {
	if( $("#"+layer).css("display") == "block" && (aktion == 1) ) {
		document.getElementById(layer).style.display = "none";
	}
	else if(aktion==1){
		document.getElementById(layer).style.display = "block";
	}
	else if(aktion==0){
		document.getElementById(layer).style.display = "none";
	}
}

/* Listen to various events */
function addthisEventHandler(evt) {
	switch (evt.type) {
        case "addthis.menu.open":
			$(".popup_overlay").css("z-index","10020");
			showOverlayLayer(1);
            break;
        case "addthis.menu.close":
			$(".popup_overlay").css("z-index","1000");
			showOverlayLayer(0);
            break;
    }
}

function resizeElements() {
	arrayPageDimension = getPageSize();
	arrayScrollDimension = getPageScroll();			
	/* Produkt weiterempfehlen */
	if($('div#prod-recommend-container').css('display') == 'block') {	
		$('div#prod-recommend-container').css('top', arrayScrollDimension[1]+"px");
	}
	/* Produktbewertung */
	if($('#prodBewertPopup').css('display') == 'block') {	
		$('#prodBewertPopup').css('top', arrayScrollDimension[1]+"px");
	}
	left = (arrayPageDimension[0] - 992) / 2;
	var poWidth = arrayPageDimension[0];
	if( poWidth < 992 ) {
		poWidth = 992;
		left = 0;
	}
	$(".popup_overlay").css({
			width	: 	poWidth,	
			left	:	-(left+41)
	});
}

function showOverlayLayer(action) {
    arrayPageDimesion = getPageSize();
	arrayScrollDimesion = getPageScroll();
	if (action == 1) {
		$("#content").prepend("<div class=\"popup_overlay\" id=\"layerPopBG\"></div>");
		/*
		--- wer bock hat, kann es richten und die werte dynamisch auslesen, im ie funzt das so nicht 
		top = parseInt($("#mainLayer").css("padding-top").replace("px",""));
		top = top + parseInt($("#mainLayer").css("padding-bottom").replace("px",""));
		top = top + parseInt($("#headLayer").css("height").replace("px",""));
		top = top + parseInt($("#headLayer").css("margin-bottom").replace("px",""));
		top = top + parseInt($("#headLayer").css("padding-bottom").replace("px",""));
		top = top + parseInt($("#bodyLayer").css("padding-bottom").replace("px",""));
		top = top + parseInt($("#navsearchLayer").css("height").replace("px",""));
		top = top + parseInt($("#navsearchLayer").css("margin-bottom").replace("px",""));
		left = parseInt($("#mainLayer").css("padding-bottom").replace("px",""));
		left = left + parseInt($("#bodyLayer").css("padding-left").replace("px",""));
		left = left + (arrayPageDimesion[0] - parseInt($("#stage").css("width").replace("px",""))) / 2;
		*/
		left = (arrayPageDimesion[0] - 992) / 2;
		$(".popup_overlay").css({
			height	: 	arrayPageDimesion[1],
			width	: 	arrayPageDimesion[0],
			top		:	-(137),
			left	:	-(left+41),
			opacity	:	0.3
		});
		$(".popup_overlay").fadeIn(300, function(){
			/* showLayer(action,layer); */
		});
	}
	if (action == 0) {
		$(".popup_overlay").fadeOut("slow", function(){
	        $(this).remove();    
	    });
	}		
}


var wertungsAnzeige = 0;

/* function wertung('over',1,1) { */
function wertung(action,job,wertung) {
	if(action == "over") {
		if( job == 1) {
			wertungsAnzeigeTMP = wertung * 28;
			$(".bewertungPop").css("width",wertungsAnzeigeTMP+"px");
		}
		else {
			$(".bewertungPop").css("width",wertungsAnzeige+"px");
		}
	}
	else {
		wertungsAnzeige = wertung * 28;
		$("#bewertung").attr("value",wertung);
		$(".bewertungPop").css("width",wertungsAnzeige+"px");		
	}
}

function zeigeProdBewertPopup() {
	$(".popup_overlay").css("z-index","10020");
	showOverlayLayer(1);
	arrayScrollDimension = getPageScroll();			
	$('#prodBewertPopup').css('top', arrayScrollDimension[1]+"px");
	showLayer(1,'prodBewertPopup');
}

function changeTab (element,contentId) {
	changeTab(this,2);
}

/* changeTab(this,'#tab') */
function changeTab(activatedTab,tabNumber) {
	$(".tabcontent").css("display","none");
	$("#tab"+tabNumber).css("display","block");
	$("ul.idTabs li").removeClass("selected");
	$(activatedTab).parent("li").addClass("selected");
}


/**
 * getPageSize() by quirksmode.com
 *
 * @return Array Return an array with page width, height and window width, height
 */
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ /* all but Explorer Mac */
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { /* Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari */
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	/* all except Explorer */
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { /* Explorer 6 Strict Mode */
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { /* other Explorers */
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	/* for small pages with total height less then height of the viewport */
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	/* for small pages with total width less then width of the viewport */
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	
	/* pageWidth = document.body.clientWidth; */
	/* pageHeight = document.body.clientHeight; */

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

/**
 * getPageScroll() by quirksmode.com
 *
 * @return Array Return an array with x,y page scroll values.
 */
function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 /* Explorer 6 Strict */
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) { /* all other Explorers */
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}




function testStart(layer,nexteSeite,anzeigeDauer) {
	document.getElementById(layer).style.display = "block";
	document.getElementById(layer).style.visibility = "visible";
	document.getElementById("testStart").style.display = "none";
	document.getElementById("testStart").style.visibility = "hidden";
	/* alert(anzeigeDauer*1000); */
	window.setTimeout( "window.location.href = '?seite="+nexteSeite+"'" , (anzeigeDauer*1000) );
}

function arrange(action) {
	if(action=='parallel') {
		document.getElementById("layerNummer").style.position = "absolute";
		document.getElementById("layerGegenstand").style.position = "absolute";
		document.getElementById("layerNummer").style.top = "-10px";
		document.getElementById("layerGegenstand").style.top = "-10px";
		document.getElementById("layerNummer").style.left = "-202px";
		document.getElementById("layerGegenstand").style.left = "202px";
		document.getElementById("layerNummer").style.padding = "10px 5px 10px 10px";
		document.getElementById("layerGegenstand").style.padding = "10px 5px 10px 10px";
		document.getElementById("linkNebeneinander").style.display = "none";
		document.getElementById("linkUntereinander").style.display = "inline";
	}
	if(action=='among') {
		document.getElementById("layerNummer").style.position = "relative";
		document.getElementById("layerGegenstand").style.position = "relative";
		document.getElementById("layerNummer").style.top = "0px";
		document.getElementById("layerGegenstand").style.top = "0px";
		document.getElementById("layerNummer").style.left = "0px";
		document.getElementById("layerGegenstand").style.left = "0px";
		document.getElementById("layerNummer").style.padding = "0px 0px 0px 0px";
		document.getElementById("layerGegenstand").style.padding = "0px 0px 0px 0px";
		document.getElementById("linkNebeneinander").style.display = "inline";
		document.getElementById("linkUntereinander").style.display = "none";		
	}
}


$(function() {
    $('#zoomPic a').lightBox();
    $('#zoomPicIcon a').lightBox();	
    $('.layerKampTn a').lightBox();

});



