/*********************************************************
 * NaaN Grafix - We rock the web                         *
 * Projekt: woodridge.at                                      *
 *********************************************************/
 
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(function( $ ){
	var sidebarHeight = $('div#sidebarContent').height();
	var contentHeight = $('div#containerContentInner').height();	
		//alert('content Height: '+contentHeight+"px\nSidebar Height: "+sidebarHeight+'px');
	if( contentHeight < (sidebarHeight-398) ) {
		$('div#containerContent').height(sidebarHeight-398+'px');
	}
	else {
		$('div#containerContent').height(contentHeight+'px');
		$('div#sidebarContent').height(contentHeight+398+'px');
	}
	
	$('ul.imgSlideshow').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '352px'
	});

	
});

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==28 && 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);
}





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;
	}
}

