$(window).load(function () {
	$('.teaserSfir .headline h2').css('visibility', 'visible');
	

	if ($('body').is("#SubNavSecondType")) {
		objNav = $('#SubNavSecondType');
	}
	else {
		objNav = $('#SubNav');
	}
	

	objContent = $('#ContentArea').find('.box-content-wrapper').find('div.content');
	heightNav = objNav.height();
	heightContent = objContent.height();
	if(heightNav >= heightContent) {
		//alert('onload');
		objContent.css('height', heightNav + 'px');
	}	
	
});

$(document).ready(function() {
	
	if ($('body').is("#SubNavSecondType")) {
		objNav = $('#SubNavSecondType');
	}
	else {
		objNav = $('#SubNav');
	}	
	
	objNav.find('a').click(function(){
	 		return leftNav.itemAction(this);
 	 });	
	leftNav.init();


});


var leftNav = {

	itemList: false,
	itemListTemp: false,

	init: function () {
		this.itemList = new Array();
		this.itemListTemp = new Array();
		this.openCurrentRootline(currentRootline);
		
		
	},
	
	closeAllNodes: function () {
		$('#SubNav').find('a').attr('class', '');
		$('#SubNav').find('ul').css('display', 'none');
	},
	
	openCurrentRootline: function (currentRootline) {
		
		for(var i = 0; i < currentRootline.length; i++) {
			objLi = document.getElementById('li-' + currentRootline[i]);
			if(!objLi) {
				continue;	
			}
			objA = objLi.getElementsByTagName('a')[0];
			objA.className = 'active';
			objUL = objLi.getElementsByTagName('ul')[0];
			if(objUL && objUL.tagName == 'UL') {
				if(objUL.style.display == 'none' || objUL.style.display == '') {
					objUL.style.display = 'block';
				}
				else {
					//objUL.style.display = 'none';
				}
			}
		}		
	}, 
	
	
	getRootlineByItem: function (objLi) {
		idLi = objLi.getAttribute('id');	
		if(!idLi) {
			return;	
		}
		this.itemListTemp.push(idLi.substr(3));
		objLi = objLi.parentNode.parentNode;
		if(objLi && objLi.tagName == 'LI') {
			this.getRootlineByItem (objLi);
		}
	},
	
	itemAction: function (obj) {
		//alert(obj.tagName);
		x = obj.getAttribute('href');
		raute = x.substring(x.length-1, x.length);
		objLi = obj.parentNode;
		//idLI = objLi.getAttribute('id');
		objUL = objLi.getElementsByTagName('ul')[0];
		if(objUL && objUL.tagName == 'UL' && raute == '#') {
			this.closeAllNodes();
			this.itemListTemp = new Array();
			this.getRootlineByItem(objLi);
			this.openCurrentRootline(this.itemListTemp);
			return false;
		}
		else {
			return true;
		}		
	}
} 