$(document).ready(function() {
	
	/* HIER SPRACHEN HINZUFÜGEN BEI BEDARF */
	
	$('a#toggle-details').toggle(function() {
		$('#teaser').animate({
			height: 410
		});
		if(PAGE_LANG == "de") {
			$(this).html("weniger Details");
		}
		if(PAGE_LANG == "en") {
			$(this).html("less details");
		}
	}, function() {
	 	$('#teaser').animate({
			height: 330
		});
		if(PAGE_LANG == "de") {
			$(this).html("mehr Details");
		}
		if(PAGE_LANG == "en") {
			$(this).html("more details");
		}
	});
	
	/* Externe Links und PDFs in neuem Fenster öffnen */
	$("a[href$=pdf]").each(
	   function(){
	      $(this).attr('target', '_blank');
	});
	$("a[href^=http]").each(
	   function(){
		  if(this.href.indexOf(location.hostname) == -1) { 
	      //$(this).attr('target', '_blank');
	    }
	});
	
	
	if($('#slides').length) {
		$('.slide.h').remove();
		$('#slides').cycle({
			prev: '#prev',
			next:   '#next',
			timeout: 4500
		});
	}
	
	// if($('#jc').length) {
	// 	$("#jc").jCarouselLite({
	// 		btnGo:
	// 			[".ec .1", ".ec .2", ".ec .3", ".ec .4",".ec .5"]
	// 	});
	// }
		
	$('#sr-zoompic .ec button').click(function(){
		$('#sr-zoompic .ec button').removeClass("active");
		id = "#zp-"+$(this).attr("class");
		$(this).addClass("active");
		$('#jc ul li').hide();
		$(id).show();
	});
	
	
	$('#srh-next').addClass("active");
	$('#srh-prev').click(function(){
		$('#sra .sra-home:lt(4)').show();
		$('#sra .sra-home:gt(3)').hide();
		$(this).removeClass("active");
		$('#srh-next').addClass("active");
		return false;
	})
	$('#srh-next').click(function(){
		$('#sra .sra-home:lt(4)').hide();
		$('#sra .sra-home:gt(3)').show();
		$(this).removeClass("active");
		$('#srh-prev').addClass("active");
		return false;
	})
	
	$('#tuning-brands ul').addClass("list-splitter");
	if($('.list-splitter').length) $('.list-splitter').easyListSplitter({ colNumber: 3 });
	
	$('#btn-top').click(function(){
		$("html").animate({scrollTop: 0},500);
	});
	
	$(".col-image a").fancybox({
		'titlePosition'		: 'outside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.7
	});
	
	$(".rcol-gallery a").fancybox({
		'titlePosition'		: 'outside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.7
	});
	
	$(".full-gallery a").fancybox({
		'titlePosition'		: 'outside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.7
	});
	
	$('.full-gallery a:nth-child(4)').css("margin-right",0);
	$('.full-gallery a:nth-child(8)').css("margin-right",0);
	$('.full-gallery a:nth-child(12)').css("margin-right",0);
	$('.full-gallery a:nth-child(16)').css("margin-right",0);
	$('.full-gallery a:nth-child(20)').css("margin-right",0);
	$('.full-gallery a:nth-child(24)').css("margin-right",0);
	$('.full-gallery a:nth-child(28)').css("margin-right",0);
	$('.full-gallery a:nth-child(32)').css("margin-right",0);
	
	
	/* Teile-Gallerie in SR Detailseiten */
	$("#sr-tuningparts a").fancybox({
		'titlePosition'		: 'outside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.7
	});
	
	/* tab ids generieren */
	
	$('.tab_container .tab_content').each(function(i){
		ancor = "tab"+(i+1);
		$(this).attr("id",ancor);
	});
	
	/* Gallerie in SR Detailseiten */
	$(".sr-gallery a").fancybox({
		'titlePosition'		: 'outside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.9
	});
	
	
	
	/* Appetizers */
	$('.sr-teasers-medium .large').addClass("h");
	$('.sr-teasers-medium .medium').removeClass("h");
	
	$('.sr-teasers-large .appetizer:even').css("margin-right","20px");
	$('.sr-teasers-large .appetizer:odd').css("margin-right",0);
	
	$('.sr-teasers-medium .appetizer:nth-child(4)').css("margin-right",0);
	$('.sr-teasers-medium .appetizer:nth-child(8)').css("margin-right",0);
	/* tabs */
	$('.tab_content').each(function(){
		$('ul.tabs').append('<li><a href="#'+$(this).attr("id")+'">'+$(this).attr("title")+'</a></li>');
		$(this).attr("title","");
	});
	
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();
		var activeTab = $(this).find("a").attr("href");
		activeTab = activeTab.replace("http://cms.ilmberger-carbon.de/", "");
		$(activeTab).show(); 
		return false;
	});
	
	$('#info-icons a').tipsy({gravity: 'n'});
});
