//sync height of Content and Sidebar
function syncheight(){
	$('#sidebar').height('auto');
	$('#content').height('auto');
	$('.product_details').height('auto');
	$('.product_info').height('auto');

	var sidebar_h = $('#sidebar').height();
	var content_h = $('#content').height();
	var proddet_h = $('.product_details').height();
	var prodinfo_h = $('.product_info').height();

	var site_h;
	var page_h;
	var full_h;
	
	sidebar_h = sidebar_h+107; //107 = Höhe der Subscribe-Box
	prodinfo_h = prodinfo_h+116;
	
	//Abgleich aller möglichen Elemente (sidebar/proddet/prodinfo)
	if (sidebar_h >= content_h){
		site_h = sidebar_h;
	} else {
		site_h = content_h;
	}
	
	if (proddet_h >= prodinfo_h){
		page_h = proddet_h;
	} else {
		page_h = prodinfo_h;
	}
	
	page_h = page_h+68;
	
	if (site_h >= page_h){
		full_h = site_h;
	} else {
		full_h = page_h;
	}
	
	//setze alles auf gleiche Hoehe (+Anpassungen)
	$('#sidebar').height(full_h-107);
	$('#content').height(full_h);
	$('.product_details').height(full_h-68);
	$('.product_info').height(full_h-68);

}

//Popup
$(function(){
    $('.largeImg a').click(function(){
      
	var image = '<img alt="largeimage" src="' + $('.largeImg a').attr('href') + '"/>';
	var legend = '<div class="sub_legend">' + $('.sub_legend').html() + '</div>';
	var content;
	
	content = image + legend;
	
	$('.popup').html(content);
	$('.popup').show();
	
	return false;
    });
});

$(function(){
    $('.popup').click(function(){
	$('.popup').hide();
	return false;
    });
});

var tabs = null;

//---------------------------------------------------
//			Accordion
//---------------------------------------------------
$(document).ready(function(){
	//alle Container verstecken beim Seitenstart
	$(".toggle_container").hide();
	
	//wenn klick, dann auf-/zuklappen
	$(".trigger").click(function(){
		//warten bis Animation fertig, dann erneut syncheight
		$(this).next(".toggle_container").slideToggle("slow,",function(){syncheight();});
	});
	
	//Klasse setzen/entfernen je nach Zustand
	$(".trigger").toggle(function(){
		$(this).addClass("active"); 
		}, function () {
		$(this).removeClass("active");
	});
	
	
	//erstes mit oeffnen-klasse versehen
	$("#page_content h2.trigger:first").addClass("toggle_head");
	
	//Container mit dieser Klasse werden geoeffnet 
	$(".toggle_head").click();
	
	
	// Tabs
	tabs = $('#tabs').tabs();

	//Gallery
	$(".thumbs a").click(function(){
	  var largePath = $(this).attr("href");
	  $("#largeImg a img").attr({ src: largePath });
	  return false;
	});

	//leere divs und uls löschen
	$('.sub_advantages h2:empty,.sub_advantages ul:empty,.sub_legend dl:empty').remove();
	$('.sub_advantages:empty,.sub_legend:empty').remove();
	$('.toggle_container a:empty').remove();
	$('.toggle_container li:empty,.toggle_container p:empty').remove();
		
	//danach syncheight
    setTimeout(function(){ syncheight() },1000);	
	//syncheight();

	$('.tabmenu li').click(function(){
	  setTimeout(function(){ syncheight() },1000);
	  //syncheight();
	});
});

//---------------------------------------------------
//		NEWS - Welcome - Slider
//---------------------------------------------------
$(document).ready(function() {	

	if($('.slideshow').length)
	$('.slideshow').cycle({ 
		fx: 'scrollHorz', 
		speed: 1500, 
		timeout: 6000,
		prev: '#prev2', 
		next: '#next2'
	});

});

//---------------------------------------------------
//		D/I -Search
//---------------------------------------------------
$(document).ready(function() {	

	//Aktivlogo löschen, wenn mehrere vorhanden
	$('.company_detail .aplogo').each(function(i,e){ if(i>0) $(e).remove(); });
	
	// Keine Suche wenn Suchergebnisse angezeigt werden.
	if ($('#dealersearch_list').children().length > 0) {
		$('#dealersearch').hide();
		$('#dealersearched').show();
	}
	
	//Neue Suche Link füllen
	if ($('#dealersearch').length > 0) {
		var dsurl = $('#dealersearch').attr('action');
		$('#dealersearchbacklink').attr('href' , dsurl.substring(0, dsurl.indexOf('?')))
	}
	
});