$(document).ready(function(){

tb_init('a.thickbox');

/* Teaser-Boxes für IE7 optimieren ***************/
$('#teaserWrap').addClass('###');
teaser($('#teaserWrap .teaserBoxes'));
function teaser(element) {
	var e = 1;
	element.each(function(){
		$(this).addClass('nr' + e);
		e++;
	});
}

/* Produkt-Logos *********************************/

logoPfad = 'pub/Bilder/prodlogos/';

prodlogos($('.prodList h2 a'));

function prodlogos(element) {
	element.each(function(){
		firma = $(this).attr('title').split(' ');
		$(this).wrapInner('<div class="text">');
		$(this).prepend('<img class="prodlogo" src="' + logoPfad + firma[0] + '.jpg" />');
		firma = firma.splice(1);
		firma = firma.toString();
		firma = firma.replace(/,/gi," ");
		$(this).find('.text').empty().text(firma);
	});
}
	
/* Accordion *************************************/

	$('.accordion h3').each(function(){
		$(this).siblings().wrapAll('<div></div>');
	});
	$('.accordion:first-child').before('<div class="theAccordion"></div>');
	$('.accordion').appendTo('.theAccordion');
	$('.theAccordion h3').unwrap();
	$(".theAccordion").accordion({header: 'h3', autoHeight: false, active: 'h3:first-child', collapsible: true});
	
	
/* Navi ******************************************/
	
	if(!$.browser.msie) {
		$('#mainNavi').find('li').find('.dropdown').hide();
			// ggf Breite anpassen
		$('#mainNavi li ul.dropdown').each(function(){
			var pWidth = $(this).parent().outerWidth();
			var tWidth = $(this).outerWidth();
			if (pWidth > tWidth) {
				$(this).width(pWidth);
			}
		});
		$('#mainNavi').find('li').hover(function(){
			$(this).find('.dropdown').css('opacity','0').show().animate({
				opacity: 1
			},200);
		},function() {
			$(this).find('.dropdown').animate({
				opacity: 0
			},0, function(){
				$(this).hide()
			});
		});
	} else {
		$('#mainNavi').find('li').find('.dropdown').hide();
			// ggf Breite anpassen
		$('#mainNavi li ul.dropdown').each(function(){
			var pWidth = $(this).parent().outerWidth();
			var tWidth = $(this).outerWidth();
			if (pWidth > tWidth) {
				$(this).width(pWidth);
			}
		});
		$('#mainNavi').find('li').hover(function(){
			$(this).find('.dropdown').show().css('z-index', '999');
		},function() {
			$(this).find('.dropdown').hide();
		});
	}
	
	
    /* Rückruf-Anfrage
    **********************************************/    
	var callbackServiceOptions = { 
		target: '#TB_ajaxContent',
		url: 'pub/php/callBackConfirmation.php'
	};
	
	$('#showInThickbox form#mailform').submit(function() {
		$(this).ajaxSubmit(callbackServiceOptions);
		return false;
	});
	

/* MailForm ***************************************/
	$('#mailForm').find('input, textarea, select').focus(function() {
		$(this).attr('style', '');
	});

/* Icons Teaser **********************************/

	$('.teaserBoxes').each(function(){
		$(this).find('.boxHeadline span').css('background','url(' + $(this).find('.boxIcon img').attr('src') + ') no-repeat');
	});
	
/* Icons Startseite Content **********************/

	$('.startseite .csc-default').each(function(){
		bild = $(this).find('img').attr('src');
		$(this).find('h2').css('background','url('+bild+') no-repeat');
		$(this).find('.imageWithCaption').hide();
		$(this).find('.textboxAboveCenter').removeClass('textboxAboveCenter');
	});

/* Specialbox mit Slidefunktion ******************/
	$(".specialBoxen.slide").horizontalSlider({
		selector: '.csc-default',
		setWidth: '264px',
		setPosition: 'absolute',
		slideWidth: '264px'
    });

	$('.fancybox').fancybox();
	
	
/* Anforder Formulare ****************************/
$('#step2 .prevStep').click(function() {
	$('#step2').animate({'opacity' : 0}, 800, function() {
		$(this).hide();
		$('#anforderSteps').removeClass('two').addClass('one');
		$('#step1').show().animate({'opacity': 1});
	});
	
	return false;
});

$('#step2 .nextStep').click(function() {
	$('#step2').animate({'opacity' : 0}, 800, function() {
		$(this).hide();
		$('#anforderSteps').removeClass('two').addClass('three');
		$('#step3').show().animate({'opacity': 1});
	});
	
	return false;
});

$('#step3 .prevStep').click(function() {
	$('#step3').animate({'opacity' : 0}, 800, function() {
		$(this).hide();
		$('#anforderSteps').removeClass('three').addClass('two');
		$('#step2').show().animate({'opacity': 1});
	});
	
	return false;
});

});
