$(window).load(function(){
	slideShow();
	setInterval('slideShow()',25000);
	setOverlays();
	calcBg();
});

$(window).resize(function() {
	calcBg();
});

actimg = 0;
function slideShow(){
	totalImages = 0;
	$('.fp_slideshow_holder').each(function(i){
		if(i == actimg){
			//$('#tooltip_'+i).show();
			$(this).animate({
			    opacity: 1.00
			}, 1000, function() {
				$(this).css('z-index','50');
			});
		}else{
			//$('#tooltip_'+i).hide();
			$(this).animate({
			    opacity: 0.00
			}, 1000, function() {
				$(this).css('z-index','1');
			});
		}
		totalImages++;
	});
	//alert('totalImages = '+totalImages);
	actimg++;
	if(actimg == totalImages){
		actimg = 0;
	}
	
}

function setOverlays(){
	//SET OVERLAY POSITION
	$('.front-page-overlay').each(function(i){
		newTopMargin = 552-$(this).height()-20;
		$(this).css('top',newTopMargin+'px');
		//TWITTERBOX
		innerHeight = $(this).find('.tw_middle').height();
		//alert($(this).find('.tw_middle').height());
		$(this).find('.twbox_holder').css('margin-top','-'+(innerHeight+50)+'px');
		//$(this).find('.twbox_holder').css('margin-top','-280px');
		hideBox(i);
	});
	//SET CONTACTINFO POSITION
	$('.fpo_content').each(function(i){
		elementHeight = $(this).height();
		$(this).find('.fpo_content_right').find('p').css('margin-top',elementHeight-125+'px');
	});
	//SET CONTENT BLOCKS WIDTH
	$('.fp_block').each(function(i){
		$(this).width($(this).find('span').width()+2);
	});
	//SET BUTTON POSITION
	maxHeight = 0;
	$('.fp_block_inner').each(function(i){
		if(maxHeight < $(this).height()){
			maxHeight = $(this).height();
		}
	});
	$('.fp_block').each(function(){
		var diff = parseInt(maxHeight - $(this).find('.fp_block_inner').height());
		//alert('diff = '+diff);
		//diff = diff*1;
		//diff = 10;
		$(this).find('.button_fp').css('margin-top',diff+13+'px');
	});
}

function calcBg(){
	$('.bg-fp').each(function(i){
		vh = $(this).find('img').width() / $(this).find('img').height();
		nh = $(window).width()/vh;
		if(nh < 552){
			//kkleiner
		}else{
			$(this).find('img').width($(window).width());
			$(this).height(nh);
		}
		$(this).height(552);
	});	
}

function showBox(elementId){

	$('#twbox_'+elementId).css('display','block');
}

function hideBox(elementId){
	$('#twbox_'+elementId).css('display','none');
}


