

initSubNav = function(){
	var subNavLinks = jQuery('#subNavList a');
	var sumSubNavLinks = subNavLinks.size();
	
	if (sumSubNavLinks > 0) {
		//console.log(subNavLinks.size());
		if (subNavLinks[0].hasClass('active')) {
			jQuery(subNavLinks[0]).attr('class', 'active firstActive');
			jQuery('.subNavHeadline a').attr('class', 'bottomActive');
		}
		else {
			jQuery(subNavLinks[0]).attr('class', 'firstPassive');
		}
		
		if (subNavLinks[sumSubNavLinks - 1].hasClass('active')) {
			jQuery(subNavLinks[sumSubNavLinks - 1]).attr('class', 'active lastActive');
		}
		else {
			jQuery(subNavLinks[sumSubNavLinks - 1]).attr('class', 'lastPassive');
		}
	}
	
	jQuery('#subNavList a').each(function(i){
		if (this.hasClass('active')) {
			if (i < (sumSubNavLinks - 1)) {
				if (i + 1 == (sumSubNavLinks - 1)) {
					jQuery(subNavLinks[i + 1]).attr('class', 'lastPassiveTopActive');
				}
				else {
					jQuery(subNavLinks[i + 1]).attr('class', 'topActive');
				}
			}
			if (i > 0) {
				jQuery(subNavLinks[i - 1]).attr('class', 'bottomActive');
			}
		}
	});
}

initLayout = function() {
  contentHeight = jQuery('#content').height();
  sidebarHeight = jQuery('#containerSidebar').height()-64;
  //console.log(sidebarHeight+"\n"+contentHeight);
  
  if( contentHeight < sidebarHeight ) {
  	jQuery('#content').height(sidebarHeight-5+'px');
  }
  else { jQuery('#sidebar').height((contentHeight+60)+'px'); }
  
  jQuery('#containerContentWrap').height(jQuery('#containerSidebar').height()-137+'px');
  
  initSubNav();
}





jQuery('div#footerToTop a').click(function(){
		jQuery.scrollTo( 0, 300 );
	});


/*
jQuery('#subNavList a').hover(function() {
	if( !jQuery(this).hasClass('active') ) {
		jQuery(this).attr('class', 'active');
		initSubNav();
	}
}, function() {
	if( jQuery(this).hasClass('active') ) {
		jQuery(this).removeClass('active');
		jQuery('#current').attr('class', 'active');
		initSubNav();
	}
});*/





function fillQuickAnfrageForm($, lang) {
	if( lang=='en' ) {
		monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	}
	else {
		monthNames = new Array("Jannuar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
	}
	
	// days
	var dayOptionsHtml = '';
	for( i=0; i<=31; i++ ) {
		if( i==0 ) {
			dayOptionsHtml = dayOptionsHtml + "\n"+'<option value="0">--</option>';
		}
		else {
			dayOptionsHtml = dayOptionsHtml + "\n"+'<option value="'+i+'">'+i+'</option>';
		}
	}
	$("#from_d").html(dayOptionsHtml);
	$("#to_d").html(dayOptionsHtml);
	
	// month
	var monthOptionsHtml = '';
	for( i=0; i<=11; i++ ) {
		monthOptionsHtml = monthOptionsHtml + "\n"+'<option value="'+(i+1)+'">'+ monthNames[i] +'</option>';
	}
	$("#from_m").html(monthOptionsHtml);
	$("#to_m").html(monthOptionsHtml);
	
	// year
	var yearOptionsHtml = '';
	var yearDateObj = new Date();
	var currYear = yearDateObj.getFullYear();
	for( i=currYear; i<=currYear+4; i++ ) {
		yearOptionsHtml = yearOptionsHtml + "\n"+'<option value="'+i+'">'+i+'</option>';
	}
	$("#from_y").html(yearOptionsHtml);
	$("#to_y").html(yearOptionsHtml);
	
	//preselect
	//getNextSaturday("to_d", "to_m", "to_y", getNextSaturday("from_d", "from_m", "from_y"));
    var currPageID = getURLParam(location.href, "id");
    var fromDay = getURLParam(location.href, "from_d");

    if( currPageID==4 && fromDay>0 ) {
        var fromDate = getURLParam(location.href, "from_d")+"."+getURLParam(location.href, "from_m")+"."+getURLParam(location.href, "from_y");
        var toDate = getURLParam(location.href, "to_d")+"."+getURLParam(location.href, "to_m")+"."+getURLParam(location.href, "to_y");

		document.getElementById("uid1_hr").value = fromDate;
		document.getElementById("uid2_hr").value = toDate;

		document.getElementById("from_d").value   = getURLParam(location.href, "from_d");
		document.getElementById("from_m").value = getURLParam(location.href, "from_m");
		document.getElementById("from_y").value  = getURLParam(location.href, "from_y");

		document.getElementById("to_d").value   = getURLParam(location.href, "to_d");
		document.getElementById("to_m").value = getURLParam(location.href, "to_m");
		document.getElementById("to_y").value  = getURLParam(location.href, "to_y");
    }
    else {
		getNextSaturday("to_d", "to_m", "to_y", getNextSaturday("from_d", "from_m", "from_y"));
    }

	
	
	
}


function getNextSaturday(dayId, monthId, yearId, giveDate) {
	giveDate = giveDate||false;

	if( giveDate ) { today = giveDate; }
	else { today = new Date(); }

	year = today.getFullYear();
	month = today.getMonth()+1;
	day = today.getDate();
	dayOfWeek = today.getDay();

	if( dayOfWeek == 6 ) {
		newDay = day+7;
	}
	else {
		addDays = 6-dayOfWeek;
		newDay = day+addDays;
	}

	newDate = new Date( year, month-1, newDay );

	newDay = newDate.getDate();
	newMonth = newDate.getMonth()+1;
	newYear = newDate.getFullYear();

	document.getElementById(dayId).value = newDay;
	document.getElementById(monthId).value = newMonth;
	document.getElementById(yearId).value = newYear;

	return( newDate );
}

function getURLParam(srch, strParamName) {
	var strReturn = "";
	var strHref = srch;
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if ( aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ) {
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return unescape(strReturn);
}








