jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};


NAAN = {
	common: {
		getUrlParam: function(strParamName, currentUri) {
			currentUri = currentUri||false;
			strReturn = '';
			
			if( currentUri ) { procCurrentUri = currentUri; }
			else { procCurrentUri = location.href; }
			
			if ( procCurrentUri.indexOf("?") > -1 ){
				var strQueryString = procCurrentUri.substr(procCurrentUri.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);
		},
		openPopup: function(url, title, width, height) {
			if (screen.availWidth) {
				popupCenterX = screen.availWidth / 2 - width / 2;
				popupCenterY = screen.availHeight / 2 - height / 2;
			}
			else {
				popupCenterX = 0;
				popupCenterY = 0;
			}
			
			var popupArgs = 'width='+width+',height='+height+',status=no,location=no,left='+popupCenterX+',top='+popupCenterY+',screenX='+popupCenterX+',screenY='+popupCenterY;
			var newPopupWindow = window.open( url, '', popupArgs );
			newPopupWindow.focus();
			
			return false;
		},
		openPopupLink: function(linkElem) {
			popupUrl = jQuery(linkElem).attr('href');
			popupTitle = jQuery(linkElem).attr('rel');
			popupSizeRaw = jQuery(linkElem).attr('rev');
			popupWidth = 400;
			popupHeight = 400;
			
			if( popupSizeRaw ) {
				var popupSizeArr = popupSizeRaw.split(',');
				popupWidth = popupSizeArr[0];
				popupHeight = popupSizeArr[1];
			}
			
			this.openPopup( popupUrl, popupTitle, popupWidth, popupHeight );
			
			return false;
		},
		scrollToAnchor: function() {
			var urlAnchorHash = self.document.location.hash;
			
			if( urlAnchorHash ) {
				//console.log(urlAnchorHash);
				jQuery.scrollTo( jQuery(urlAnchorHash), 300 );
			}
		},
		getNextSaturday: function(giveDate) {
			giveDate = giveDate||false;

			if( giveDate ) { today = giveDate; }
			else { today = new Date(); }
		
			year = today.getFullYear();
			month = today.getMonth();
			day = today.getDate();
			dayOfWeek = today.getDay();
		
			if( dayOfWeek == 6 ) {
				newDay = day+7;
			}
			else {
				addDays = 6-dayOfWeek;
				newDay = day+addDays;
			}
		
			newDate = new Date( year, month, newDay );
			return( newDate );
		},
		fillQuickAnfrageForm: function(lang) {
			if( lang=='en' ) {
				monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
			}
			else if(lang=='it') {
				monthNames = new Array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre");
			}
			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>';
				}
			}
			jQuery("#from_d").html(dayOptionsHtml);
			jQuery("#to_d").html(dayOptionsHtml);
			
			// month
			var monthOptionsHtml = '';
			for( i=0; i<=11; i++ ) {
				monthOptionsHtml = monthOptionsHtml + "\n"+'<option value="'+(i+1)+'">'+ monthNames[i] +'</option>';
			}
			jQuery("#from_m").html(monthOptionsHtml);
			jQuery("#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>';
			}
			jQuery("#from_y").html(yearOptionsHtml);
			jQuery("#to_y").html(yearOptionsHtml);
			
			//preselect
		    var fromDay = this.getUrlParam("from_d");
		
		    if( fromDay>0 ) {
				var fromDate = this.getUrlParam("from_d")+"."+this.getUrlParam("from_m")+"."+this.getUrlParam("from_y");
		        var toDate = this.getUrlParam("to_d")+"."+this.getUrlParam("to_m")+"."+this.getUrlParam("to_y");
		
				document.getElementById("uid1_hr").value = fromDate;
				document.getElementById("uid2_hr").value = toDate;
		
				document.getElementById("from_d").value   = this.getUrlParam("from_d");
				document.getElementById("from_m").value = this.getUrlParam("from_m");
				document.getElementById("from_y").value  = this.getUrlParam("from_y");
		
				document.getElementById("to_d").value   = this.getUrlParam("to_d");
				document.getElementById("to_m").value = this.getUrlParam("to_m");
				document.getElementById("to_y").value  = this.getUrlParam("to_y");
		    }
		    else {
				nextSaturdayDate = this.getNextSaturday();
				nextNextSaturdayDate = this.getNextSaturday(nextSaturdayDate);
				
				if (document.getElementById("uid1_hr") && document.getElementById("uid2_hr")) {
					var fromDate = nextSaturdayDate.getDate() + "." + (nextSaturdayDate.getMonth() + 1) + "." + nextSaturdayDate.getFullYear();
					var toDate = nextNextSaturdayDate.getDate() + "." + (nextNextSaturdayDate.getMonth() + 1) + "." + nextNextSaturdayDate.getFullYear();
					
					document.getElementById("uid1_hr").value = fromDate;
					document.getElementById("uid2_hr").value = toDate;
				}
				
				document.getElementById("from_d").value = nextSaturdayDate.getDate();
				document.getElementById("from_m").value = nextSaturdayDate.getMonth()+1;
				document.getElementById("from_y").value = nextSaturdayDate.getFullYear();
		
				document.getElementById("to_d").value   = nextNextSaturdayDate.getDate();
				document.getElementById("to_m").value   = nextNextSaturdayDate.getMonth()+1;
				document.getElementById("to_y").value   = nextNextSaturdayDate.getFullYear();
		    }
		}
	},
	layout: {
		init: function() {
			this.correctContentSidebar();
			this.adjustMainNavBg();
			NAAN.common.scrollToAnchor();
		},
		correctContentSidebar: function() {
		  var contentId = '#content'
		  var sidebarLeftId = '#containerSidebarLeft';
		  var sidebarRightId = '#containerSidebarRight';
		  var newContentHeight = 0;
		  var newSidebarLeftHeight = 0;
		  
		  var contentHeight = jQuery(contentId).height();
		  var sidebarLeftHeight = jQuery(sidebarLeftId).height();
		  var sidebarRightHeight = jQuery(sidebarRightId).height();
		  var sidebarLeftCalcHeight = sidebarLeftHeight - 300;
		  
		  if( sidebarRightHeight > contentHeight ) {
		  	newContentHeight = sidebarRightHeight;
			contentHeight = newContentHeight;
		  }
		  
		  if( contentHeight < sidebarLeftCalcHeight ) {
		  	newContentHeight = sidebarLeftCalcHeight;
			contentHeight = newContentHeight;
		  }
		  
		  if( newContentHeight > 0 ) { jQuery(contentId).height(newContentHeight+'px'); }
		  
		  contentWrapHeight = (contentHeight) + jQuery('#containerFooter').height() + jQuery('#containerContentNav').height() + 25;
		  
		  jQuery('#containerContentWrap').height(contentWrapHeight+'px');
		  
		  return;
		},
		adjustMainNavBg: function() {
			if( !jQuery('ul#mainNavList li:first-child').not('ul#subNav li').hasClass('active') ) {
				jQuery('ul#mainNavList li:first-child').not('ul#subNav li').addClass('passiveFirst');
				jQuery('ul#mainNavList li:nth-child(2)').not('ul#subNav li').addClass('passiveSecond');
			}
		}
	}
}


NAAN_SUBSCRIPTION =  {
	submitForm: function(formObj) {
		var callUri = jQuery(formObj).attr('action');
		var formParams = jQuery(formObj).serialize();
		
		jQuery.get( formObj.action, formParams, function(callAnswer) {
			if (!callAnswer.error) {
				alert(callAnswer.success);
				formObj.reset();
			}
			else {
				var errorFields = callAnswer.error_fields;
				var errorMsg = '';
				for( i in errorFields ) {
					errorMsg = errorMsg+errorFields[i]+"\n";
				}
				alert(errorMsg);
			}
		}, 'json' );
		
		return false;
	}
}



