$(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();
	
	$("#top_section .main-li").mouseenter(function(){
		$(".sub_navigation", this).fadeIn("fast");
	}).mouseleave(function(){
		$(".sub_navigation", this).fadeOut("fast");
	});

	$('#gallery_cycle').cycle({
		fx : 'shuffle',
		random : 1,
		speed : 1000
	});
	
	$("a[href$='.jpg']," +
	  "a[href$='.JPG']," +
	  "a[href$='.gif']," +
	  "a[href$='.GIF']," +
	  "a[href$='.png']," +
	  "a[href$='.PNG']," +
	  "a[href$='.bmp']," +
	  "a[href$='.BMP']", "#content_text").has("img").attr("rel", "fancyimages");
		
	$("#content_text a[rel=fancyimages]").fancybox({
		'titleShow'		: false,
		'transitionOut'	: 'none'
	});
	
	$("#content_text img").css("border-color", "#e3c100");
	$("#content_text").css("visibility", "visible");
});

/**
 * 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);
}