$(function(){

	//$("#navigation .sub_navigation a.item_selected").closest(".main-li").find(".sub_navigation").show();
	//$("#navigation .main-li a.item_selected").closest(".main-li").find(".sub_navigation").show();
	
	var sub = $("#navigation .main-li a.item_selected").closest(".main-li").find(".sub_navigation");
	if (sub.length > 0) {
		$("#submenu_helper")
			.hide()
			.html(sub.html())
			.wrapInner("<ul class='sub_navigation'></ul>")
			.show();
	} else {
		$("#submenu_helper").remove();
	}

	$('#gallery').cycle({
		fx : 'fade',
		random : 1,
		speed : 2500
	});
});

/**
 * a basic ajax request
 * replaces the content div
 * @param ajaxstring
 */
function ajaxRequest(ajaxstring) {
	var xhr_timer_delay_new = xhr_timer_delay;
	if (xhr_timer) {
		clearTimeout(xhr_timer);
	} else {
		xhr_timer_delay_new = 0;
	}
	xhr_timer = setTimeout(function(){
		$.ajax({
			type: "POST",
			data: ajaxstring,
			success: function(data){
				$("#content_text").html(data);
				setForm();
			}
		});}, xhr_timer_delay_new);
}

/**
 * Prepares a form to be send using ajax
 * 
 * replaces the content div
 */
function setForm(){ 
	alert("form set?!");
	var options = { 
        //target:        '.content',   // target element(s) to be updated with server response 
        //beforeSubmit:  showRequest,  // pre-submit callback 
        //success:       showResponse  // post-submit callback 
        success: function(data){
			$("#content_text").html(data);
			setForm();
		}
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#ajaxForm').ajaxForm(options);
}

/**
 * a basic ajax request
 * replaces the content div
 * @param ajaxstring
 */
function ajaxRequest(ajaxstring, remoteurl) {
	var xhr_timer_delay_new = xhr_timer_delay;
	if (xhr_timer) {
		clearTimeout(xhr_timer);
	} else {
		xhr_timer_delay_new = 0;
	}
	xhr_timer = setTimeout(function(){
		$.ajax({
			url: remoteurl,
			type: "POST",
			data: ajaxstring,
			success: function(data){
				$("#content_text").html(data);
				setForm();
			}
		});}, xhr_timer_delay_new);
}