$(document).ready(function () {

	var sHeadline = $('.page-navigator').find('a').eq(2).html();

	if ((sHeadline==null))
		sHeadline = $('.page-navigator').find('b').html();

	if (sHeadline!="")	
	{
		$("#HeaderContainer").html( sHeadline );
	}

	// initialize Input fields
	inputInitValue();
	
	/*************************************
	Collapse and expand menu
	*************************************/
	/*
	var current = $("#swParent").text();

	swMenuHideAllSub(document.getElementById("swMenuTree"));
	
	var curMenuItem = $("div.swMenuItem[ParentId="+current+"]");
	if (curMenuItem.length > 0) {
		var curMenuItemId = curMenuItem.get(0).id;
		swMenuShowBranch(curMenuItemId);
	}
	*/
	/*************************************
	Tilføj active class topmenu
	*************************************/	
	//active class topmenu
	var iParentId = $("#parentid").text();
	var menuLinks = $("a.topMenu-main");
	var menuActive = $(".page-navigator *").eq(2);
	var subMenuActive = $(".page-navigator *").eq(4);
	var frontActive = $("#swFrontCol11").get(1);
	//alert(frontActive);
	//alert(menuLinks.length);
	//alert(menuActive.text());
	//alert(subMenuActive.text());
	
	if (iParentId!='0')
	{
		//alert((iParentId!='0') + ' - ' +iParentId);
		menuLinks.each(function(index){
			//alert(index);
			if($(this).text() == menuActive.text()) {
				//alert("found main");
				$(this).addClass("active");
			}
			//alert($(this).text());
			if($(this).text() == subMenuActive.text()) {
				//alert("found sub");
				$(this).addClass("active");
			}
		});
		if(frontActive) {
			menuLinks.eq(0).addClass("active");
		}

	}
	
});


/*******************************************
FUNCTIONS
*******************************************/


/* Clear and set initial value of input fields */
function inputInitValue() {

	$("*[@behaviours='inputInitValue']").focus(function() {

		if (!$(this).attr("oldValue")) {
			$(this).attr("oldValue", $(this).attr("value"));
		}
		
		if ($(this).attr("value") == $(this).attr("oldValue")) {
			$(this).attr("value", "");
		}
	});
	
	$("*[@behaviours='inputInitValue']").blur(function() {
	
		if (!$(this).attr("value")) {
				$(this).attr("value", $(this).attr("oldValue"));
		}
	});
}
