function folgeseiten(){
	jQuery("#mainNav").children('li').mouseover(function(e) {
		if(!jQuery(this).hasClass('active')){
			jQuery('#mainNav li.active ul').hide();
			jQuery(this).addClass("hover");
			jQuery(this).children('ul').show();
		}
	}).mouseleave(function() {
		if(!jQuery(this).hasClass('active')){
			jQuery(this).children('ul').hide();
			jQuery(this).removeClass("hover");
			jQuery('#mainNav li.active').children('ul').show();
		}
	}).click(function(){
		jQuery('#mainNav').children('li').each(function(){
			jQuery(this).removeClass('active');
		});
		jQuery(this).addClass('active');
	});
}

function setVisible(mainElement){
	jQuery('.subnav').each(function(){jQuery(this).hide();});
	mainElement.children('ul.subnav').show(); 
}

function setActiveLink(index){
	jQuery('#mainNav').children('li').each(function(){
		jQuery(this).removeClass('active');
	});
	jQuery('#subnav').each(function(){
		jQuery(this).hide();
	});
	if(!jQuery('#mainNav').children('li').hasClass('active')){
		var element = jQuery('#mainNav').children('li').eq(index); 
		element.addClass('active');
		setVisible(element);
	}
}

var contentHeight; 
jQuery(document).ready(function(){
	contentHeight =  getPageSize()[3] - 220; 
	jQuery('.arrow').click(function(){
		if(jQuery(this).hasClass('down')) {
			jQuery('.contentWrapper').wrap("<div class='relativeWrapper'><div class='absoluteWrapper'></div></div>");
			jQuery('.relativeWrapper').css('height', jQuery('.contentWrapper').css('height')); 
			jQuery('.relativeWrapper').animate({height: contentHeight}, 1000);
			jQuery('.absoluteWrapper').animate({height: 32}, 1000, function(){
				jQuery('.arrow').removeClass('down');
				jQuery('.arrow').addClass('up');
			});
		} else {
			jQuery('.absoluteWrapper').animate({height: jQuery('.relativeWrapper').css('height')}, 1000, function(){
				jQuery('.arrow').removeClass('up');
				jQuery('.arrow').addClass('down');
				jQuery('.contentWrapper').unwrap().unwrap();
			});
		}
	});
});

jQuery(window).load(function(){
	resizeContainer();
	resizeBackground();
}).resize(function(){
	resizeContainer();
	resizeBackground();
}).scroll(function(){
	resizeContainer();
});

function resizeContainer(){
	contentHeight =  getPageSize()[3] - 220; // margin-top
	var pageContentHeight = contentHeight - (24 + 40 + 100);  // (header + innere margins)
	jQuery('#content').css('height', contentHeight);
	jQuery('.relativeWrapper').css('height', contentHeight);
	if(parseInt(jQuery('.text').css('height'))+140+24 < contentHeight){
		jQuery('.pageContent').css('height', pageContentHeight);
	} else {
		jQuery('.pageContent').css('height', 'auto');
	}
}

function resizeBackground(){
	var campaign_bg = jQuery('#campaign_bg');
	var image = jQuery('#imageID');
	image.width(campaign_bg.width());
	if(getNewHeight(image.width()) < campaign_bg.height()){
		image.height(campaign_bg.height());
		image.width(getNewWidth(image.height()));
	} else {
		image.height(getNewHeight(image.width()));
	}
}

var originalWidth = 1622;
var originalHeigth = 950; 

function getNewWidth(newHeight){
	return parseInt(originalWidth * newHeight / originalHeigth); 
}

function getNewHeight(newWidth){
	return parseInt(originalHeigth * newWidth / originalWidth); 
}
