if( document.location.href.substr(0,31) === "http://www.herrenausstatter.de/") {
    siteurl = '/herrenmode/';
} else {
    siteurl = '/';
}

function onLoadHandler() {
	$("#mainNav").load(siteurl + "template/mainNavigation.inc.php", run_after_load);
	showHint();
}

function run_after_load() {
    $('ul#menulinks li').bind('mouseover', menulinks_open);
    $('ul#menulinks').bind('mouseout', menulinks_timer);
    $('#gesamtauswahl').bind('mouseover', function() {$('#menulinks').show();menulinks_canceltimer()});
    $('#gesamtauswahl').bind('click', function() {$('#menulinks').show();menulinks_canceltimer()});

    if($('#sidebar').html().length == 0)
    {
        $('#menulinks').show();
    }
    else
    {
        $('#wrapper_gesamtauswahl').bind('mouseout', gesamtauswahl_timer);
    }
}

function GoToURL(url) {
    if (navigator.appName == 'Netscape')
        window.location = url;
    else
        window.location.href = url;
}

function ActivateFilter(filter, element, filtertype) {
	// AJAX-Loading-Grafik
	$(element).append('<img src="data:image/gif;base64,R0lGODlhDAAMAOYAAP////f39/f3/9be3s7W3sXW3sXO3sXO1r3O1r3F1rXFzrW9zpStvZSlvZSltYyltYyctYSctYScrYSUrXuUrXuUpXOUpXOMpWuMpWuEpWuEnGOEnGN7nGN7lFp7lFpzlFJzlFJzjFJrjEprjEJrhEJjhEJjjDpjhDpahDpaezFaezFSeylSeylScylKaylKcyFKcyFKaxlKayFCaxlCaxBCaxk6YxA6Ywg6YxAxYwgxWggxYwAxWggpWgApWgApUgAhUgAZSv4BAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFCgBCACwAAAAADAAMAA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append_click_etracker('Filter: '+ filtertype);

    cleanurl = document.URL.replace(window.location.search, '');
    filterurl = cleanurl + filter;
    GoToURL(filterurl);
}

function ProductDetails(pnr) {
    append_click_etracker('Detailseite');
    detailurl = 'http://www.herrenausstatter.de/php/partner/index.php?afnr=2263&pnr=' + pnr;
    GoToURL(detailurl);
}

function AddToCart(pnr) {
    append_click_etracker('Warenkorb');
    carturl = 'https://www.herrenausstatter.de/php/basket/index.php?afnr=2263&m=a&h=' + document.URL + '&p=' + pnr;
    GoToURL(carturl);
}

function GoToHA(page) {
	$(location).attr('href', 'http://www.herrenausstatter.de/php/partner/index.php?afnr=2263&page='+ page );
	return false;
}

$(document).ready(function() {

    $("#link_toggle_brands").click(function() {
            $(".toggle_brands").toggleClass('show');
            $("#link_toggle_brands").hide();
            return false;
    });

    $("#link_toggle_categories").click(function() {
            $(".toggle_categories").toggleClass('show');
            $("#link_toggle_categories").hide();
            return false;
    });

	$("#showmoredescription").click(function() {
            $(".moredescription").slideDown();
            $("#showmoredescription").hide();
            return false;
    });

    $(".button_bestellen").hover(function() {
        $(this).attr("src", siteurl + "images/bestellen_hover.gif");
    }, function () {
        $(this).attr("src", siteurl + "/images/bestellen.gif");
    });

	if($('#box1')) 
	{
		slidebox_init('box1');
		slidebox_init('box2');
		slidebox_init('box3');
		slidebox_init('box4');
	}

	// Links über Partnerscript tracken
	$('a.shoplink').click(function() {
		GoToHA(this.href);
		return false;
	});

	// Mehr ... anzeigen -> Gesamte Fläche klickbar machen
	$('.more').click(function() {
		$(location).attr('href', $(this).find('a:first').attr('href'));
	});

	// Kategorien auf Detailseiten -> Gesamte Fläche klickbar machen
	$('.kategorieliste li').click(function() {
		$(location).attr('href', $(this).find('a:first').attr('href'));
	});

	// Buttons beim Hover einblenden: DETAILS + BESTELLEN
	$('.hover').hover(function() {
		$(this).find('.buttons').toggle();
	});

	// BESTELLEN: In den Warenkorb legen
	$('.hover .buttons .b').click(function() {
		AddToCart( $(this).attr('id').replace('b','') );
		return false;
	});

	// DETAILS: Detailseite
	$('.hover').click(function() {
		ProductDetails( $(this).attr('id').replace('d','') );
	});

	// Bottom-Padding
	if ( $('#text .text').length != 0 ) {
		value = $('#text .text').height() + 80;
		if ( value < 450 ) value = 450;
		$('#text').css('padding-bottom', value );
	} else if ( $('#text #other').length != 0 ) {
		value = $('#text #other').height() + 80;
		$('#text').css('padding-bottom', value );
	}

});


function append_click_etracker(target) {
    $('body').append('<img src="http://www.etracker.de/cnt.php?et=ZbxENm&amp;v=3.0&amp;java=n&amp;et_easy=0&amp;et_pagename=Klick%20' + target + '&amp;et_areas=&amp;et_ilevel=0&amp;et_target=Klick%20' + target + ',0,,0&amp;et_lpage=0&amp;et_trig=&amp;et_se=0&amp;et_cust=0" />');
	sleep(0.2); // Dem etracker-Pixel etwas Zeit geben um laden zu können
}

function sleep (seconds) {
    var start = new Date().getTime();
    while (new Date() < start + seconds*1000) {}
    return 0;
}

function toggle_filter_menu(id)
{
    if($('#block_' + id).css('display') == 'none')
    {
        $('#block_' + id).css('display', 'block');
        $('#img_' + id).attr('src', 'images/template/arrow_up.gif');
        $('#span_' + id).css('display', 'none');
    }
    else
    {
        $('#block_' + id).css('display', 'none');
        $('#img_' + id).attr('src', 'images/template/arrow_down.gif');
        $('#span_' + id).css('display', 'inline');
    }
}

function brands_alphabetisch(buchstabe) {
	document.write(''
		+'<ul class="abc_list_brands"'+ ( buchstabe ? ' id="'+ buchstabe +'"':'' ) +'>'
		+'	<li'+ ( buchstabe == 'A' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#A">A</a></li>'
		+'	<li'+ ( buchstabe == 'B' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#B">B</a></li>'
		+'	<li'+ ( buchstabe == 'C' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#C">C</a></li>'
		+'	<li'+ ( buchstabe == 'D' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#D">D</a></li>'
		+'	<li'+ ( buchstabe == 'E' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#E">E</a></li>'
		+'	<li'+ ( buchstabe == 'F' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#F">F</a></li>'
		+'	<li'+ ( buchstabe == 'G' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#G">G</a></li>'
		+'	<li'+ ( buchstabe == 'H' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#H">H</a></li>'
		+'	<li'+ ( buchstabe == 'I' ? ' class="active"':'' ) +'>I</li>'
		+'	<li'+ ( buchstabe == 'J' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#J">J</a></li>'
		+'	<li'+ ( buchstabe == 'K' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#K">K</a></li>'
		+'	<li'+ ( buchstabe == 'L' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#L">L</a></li>'
		+'	<li'+ ( buchstabe == 'M' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#M">M</a></li>'
		+'	<li'+ ( buchstabe == 'N' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#N">N</a></li>'
		+'	<li'+ ( buchstabe == 'O' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#O">O</a></li>'
		+'	<li'+ ( buchstabe == 'P' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#P">P</a></li>'
		+'	<li'+ ( buchstabe == 'Q' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#Q">Q</a></li>'
		+'	<li'+ ( buchstabe == 'R' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#R">R</a></li>'
		+'	<li'+ ( buchstabe == 'S' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#S">S</a></li>'
		+'	<li'+ ( buchstabe == 'T' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#T">T</a></li>'
		+'	<li'+ ( buchstabe == 'U' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#U">U</a></li>'
		+'	<li'+ ( buchstabe == 'V' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#V">V</a></li>'
		+'	<li'+ ( buchstabe == 'W' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#W">W</a></li>'
		+'	<li'+ ( buchstabe == 'X' ? ' class="active"':'' ) +'>X</li>'
		+'	<li'+ ( buchstabe == 'Y' ? ' class="active"':'' ) +'>Y</li>'
		+'	<li'+ ( buchstabe == 'Z' ? ' class="active"':'' ) +'><a href="http://www.herrenausstatter.de/herrenmode/marken.htm#Z">Z</a></li>'
		+'</ul>');
}

// Nächste Box laden
function slidebox_next(id)
{
	var items = $('#' + id + ' li');
	var active_index = null;
	var next_index = null;

	if(items.length > 1)
	{
		items.each(function(index, item)
		{
			if($(item).css('display') == 'block')
			{
				active_index = index;
			}
		});

		if(active_index == items.length - 1)
		{
			next_index = 0;
		}
		else
		{
			next_index = active_index + 1;
		}

		$(items[active_index]).fadeOut();
		$(items[next_index]).fadeIn();
	}
}

// Vorherige Box laden
function slidebox_prev(id)
{
	var items = $('#' + id + ' li');
	var active_index = null;
	var next_index = null;

	if(items.length > 1)
	{
		items.each(function(index, item)
		{
			if($(item).css('display') == 'block')
			{
				active_index = index;
			}
		});

		if(active_index == 0)
		{
			next_index = items.length - 1;
		}
		else
		{
			next_index = active_index - 1;
		}

		$(items[active_index]).fadeOut();
		$(items[next_index]).fadeIn();
	}
}

function slidebox_init(id)
{
	var items = $('#' + id + ' li');
	if(items.length > 0)
	{
	   items.each(function(index, item)
	   {
		   if(index > 0)
		   {
			   $(items[index]).hide();
		   }
	   });
	}
}

function showHint() {
	if (( $("ul.auswahl").length > 0 ) && ( document.cookie.search(/ha_hint=1/) == -1 ) ) {
		// Hint anzeigen
		$('<div id="hint"><strong>HABEN SIE GEFUNDEN, WAS SIE SUCHEN?</strong><span>NUTZEN SIE DEN FILTER (LINKS) ODER DIE SUCHE (OBEN), UM IHRE AUSWAHL ZU VERFEINERN.</span></div>').prependTo('#content').hide().delay(800).slideDown('slow');

		// Cookie setzen um Hint nicht erneut anzuzeigen
		var expires = new Date();
		var lifetime = expires.getTime() + (1 * 24 * 60 * 60 * 1000);
		expires.setTime(lifetime);
		document.cookie = "ha_hint=1; expires=" + expires.toGMTString();
	}
}

function goto_brand_or_kategorie_site( element ) {
	href = $(element).next('.produktliste').find('.more a').attr('href');
	if( href !== undefined) {
		window.location = href;
	}
}

function use_title_link( element ) {
	href = $(element).parent().parent().find('.slidebox_title a').attr('href');
	if( href !== undefined) {
		window.location = href;
	}
}
