$(document).ready(function(){ 
	
	var display;
	var color;	
	var alt;
	var src;
	
	if($(".et_td_collapsable")) {
		$(".et_td_collapsable").each(function(){
			color = ($(this).hasClass('et_td_blue'))?'et_td_blue':'et_td_grey';
			display = $(this).hasClass('et_td_collapsed')?'none':'block';
			
			$(this).children().children().each(function(){
				if($(this).hasClass('teaserhead')){
					var headline = $(this).find('h3').remove();
					alt = (display)?'ausklappen':'zuklappen';					
					src = (display=='block')?					
					((color=='et_td_grey')?'/SiteCollectionImages/minus_grey.gif':'/SiteCollectionImages/minus_blue.gif')
					:((color=='et_td_grey')?'/SiteCollectionImages/plus_grey.gif':'/SiteCollectionImages/plus_blue.gif');
					$(this).append($('<img>').attr({
							'src': src,
							'alt': alt,
							'title': alt,
							'class': 'collapsableteaserimage'
						}).css({
							'cursor': 'pointer'
						})
					).append(headline).click(function(){
						var classname;
						var newclassname;
						var color = $(this).parent().parent().hasClass('et_td_blue')?'et_td_blue':'et_td_grey';
						$(this).next('.teaserbody').toggle(); 	
						
						classname = $(this).parent().parent().hasClass('block')?'block':'none';			
						newclassname =$(this).parent().parent().hasClass('block')?'none':'block';

						$(this).parent().parent().removeClass(classname).addClass(newclassname);
						$(this).find('img').attr({
							'src': (newclassname == 'none')?					
								   ((color=='et_td_grey')?'/SiteCollectionImages/minus_grey.gif':'/SiteCollectionImages/minus_blue.gif')
						           :((color=='et_td_grey')?'/SiteCollectionImages/plus_grey.gif':'/SiteCollectionImages/plus_blue.gif')
						})
					})
				};
				
				if($(this).hasClass('teaserbody')){
					//if(display){
						$(this).css({
							display: display
						});
					//}
				}				
				
			});
		});
	}
	
	/* tabbing webpart*/
	if($('.activetab').length>0)
		$('.activetab').children('a').removeAttr('disabled');
		
	/*toggle sitemap*/	
	if($('.sitemap').length>0)
	{			
		if($('.level1').parent('ul').length > 1)
		{
			$('.level1').parent('ul').each(function()
			{					
				$(this).addClass('firstUL');
				if($(this).find('ul').length>0)
				{	
					$('<a>&nbsp;</a>').attr({
						'class' : 'collapsimage',
						'id'    : 'level1Close',
						'href'  : '#'
					}).insertBefore($(this).children('li.level1').children('a')).click(function()
					{
						$().toogleSitemapContent($(this));
					});
				}
				else
				{
					$(this).addClass('nofollowingUL');
				}
			});
			$('.level2').each(function()
			{
				$(this).parent('ul').addClass('secondUL');
				if($(this).find('ul').length>0) 
				{  
					$(this).find('ul').each(function(){
						$(this).children('li').each(function(){
							if($(this).find('ul').length>0){
								$(this).addClass('listItemWithUL');
							}	
						});
					});
					$('<a>&nbsp;</a>').attr({
						'class' : 'collapsimage',
						'id'    : 'level2Open',
						'href'  : '#'
					}).insertBefore($(this).children('a')).click(function()
					{
						$().toogleSitemapContent($(this));
					});
				}
			});
		}		
	}

	var listDisplay = 'block';
	var linkText    = 'Click here to expand all layers';
	
	$('<a>').html(linkText).attr({
		'href'  : '#',
		'class' : 'expandAllLink'
	}).insertAfter($('.mainheadline')).click(function() 
	{	
		if(listDisplay == 'block')
		{
			$('div.sitemap').find('ul').css({
				'display' : listDisplay
			});
		} 
		else 
		{
			$('.secondUL').css({
				'display' : 'block'
			}).find('ul').css({
				'display':listDisplay
			});
		}
		$('.level2').each(function()
		{
			if($(this).find('ul').length>0) 
			{
				$(this).removeClass((listDisplay == 'none')?'activeListItem':'inactiveListItem').addClass((listDisplay == 'block')?'activeListItem':'inactiveListItem').children('.collapsimage').attr({
					'id' : (listDisplay == 'none')?'level2Open':'level2Close'
				});
			}
		});		
		$('.level1').removeClass('inactiveListItem').addClass('activeListItem').children('.collapsimage').attr({
			'id' : 'level1Close'
		});	
		listDisplay = (listDisplay=='block')?'none':'block';
		$(this).html((listDisplay=='none')?'Click here to collapse all layer':'Click here to expand all layers');			
 		} 		
	);
	
	$.fn.toogleSitemapContent = function(obj)
	{	
		var display          = ($(obj).parent('li').children('ul').css('display') == 'block')?'none':'block';		
		var imgsrc           = (display == 'none')?					
							   (($(obj).parent('li').parent('ul').hasClass('firstUL'))?'level1Open':'level2Open')
					           :(($(obj).parent('li').parent('ul').hasClass('secondUL'))?'level2Close':'level1Close');
		var oldclass        = ($(obj).parent('li').children('ul').css('display') == 'block')?'activeListItem':'inactiveListItem';
		var newclass        = ($(obj).parent('li').children('ul').css('display') == 'none')?'activeListItem':'inactiveListItem';		
		$(obj).attr({
			'id' : imgsrc
		});		
		$(obj).parent('li').children('ul').css({
			'display':display
		});
		$(obj).parent('li').parent('ul').toggleClass(
			'displaynone'
		);
		$(obj).parent('li').removeClass(oldclass).addClass(newclass);
	}

	/* interactive downloadlist */
	if($("ul.interactivedownloadlist").length>0) {
		var edtmode = $('.et_tophtmleditblock').length>0?true:false;
		if(!edtmode){		
			$("ul.interactivedownloadlist li").each(function()
			{
				var img = $(this).children('a').children('img').remove();
				$(img).insertBefore($(this).children('a'));
				$(this).mouseover(function() {
			    	$(this).css({
			    		'backgroundColor' : '#e2e7f1',
			    		'cursor' : 'pointer'
			    	})
				}).mouseout(function() {
					$(this).css({
			    		'backgroundColor' : '#fff'			    		
			    	})
				});
			});
		}
	}

});

function showHideLayer(layerid, disp) {
	
	var layercontent = $('#' + layerid);
	var scrollPos;
	var scrollelem = ($.browser.msie)?'html':'body';
	var edtmode = $('.editorinput').length>0?true:false;
	//set layer block/none
	$('div.fullPageLayer').css({
	  'display': disp
	}).append($(layercontent).css({
	  'display': disp
	}));
	$('div.fullPageLayerBackground').css({
	  'display': disp,
	  'height': $(document).height()
	});	
	// get scroll position	
	if(document.defaultView)
	   scrollPos = document.defaultView.pageYOffset;
	else
	   scrollPos = document.documentElement.scrollTop;
	// set scroll position
	$('.fullPageLayer').css({'top': (scrollPos>0)?scrollPos+160:160});
	// set layerstyles 
	if($(window).height()>parseInt($('.fullPageHiddenLayerContent').height())+160){
		if(!edtmode)
			$(scrollelem).addClass((disp=='block')?'hideSiteOverflow':'noclass').removeClass((disp=='block')?'noclass':'hideSiteOverflow');
	}	
	if(disp == 'block'){	
		$('#' + layerid + ' div.layercontent').css({'overflowX' : edtmode?'visible':'hidden'});
		if($('#' + layerid + ' div.layercontent div.contentarea').height()>parseFloat($('#' + layerid + ' div.layercontent').css('height')))
			$('#' + layerid + ' div.layercontent').css({
				'overflowY' : 'scroll'
			});
		else
			$('#' + layerid + ' div.layercontent').css({
				'overflowY' : edtmode?'visible':'hidden',
				'height'    : edtmode?396:146
			});			
	}

}

