var slides_length;

current_slide = 0;

var slow = 7500;
var fast = 2000;
var slide_delay = slow;

function show_next_slide() {
	current_id = "slide_" + current_slide;
	current = document.getElementById(current_id);

	next_slide = current_slide + 1;
	
	if (next_slide > (slides_length-1)) {
		next_slide = 0;
	}
	
	next_id = "slide_" + next_slide;
	next = document.getElementById(next_id);
	
	if (current != null) {
		current.style.display = "none";
	}
	
	if (next != null) {
		next.style.display = "block";
	}
	
	current_slide = next_slide;

	cmd = "show_next_slide()";
	slide_timer = setTimeout(cmd, slide_delay);

}

function start_slides() {
	current_id = "slide_" + current_slide;
	current = document.getElementById(current_id);
	if (current != null) {
		current.style.display = "block";
	}

	cmd = "show_next_slide()";
	slide_timer = setTimeout(cmd, slide_delay);
}

$(document).ready(function() { 
	$("#content_slides").click(function() {
		$("#content_slides_click").click();
	});

	$("#content_slides_click").click(function() {
		doc_height = $(document).height();
		doc_width = $(document).width();
		
		$("#contact_form_overlay").css("height", doc_height + "px");
		$("#contact_form_overlay").css("width", doc_width + "px");
				
		//$("#contact_form_overlay").fadeIn("slow");
		$("#contact_form_overlay").show();


		win_height = $(window).height();
		win_width = $(window).width();
		
		win_top = $(window).scrollTop();
		win_left = $(window).scrollLeft();
		
		form_top = ((win_height - 400) / 2) + win_top;
		form_left = ((win_width - 550) / 2) + win_left;
		
		//console.log(form_top + ":" + form_left);

		$("#contact_form_div").css("top", form_top + "px");
		$("#contact_form_div").css("left", form_left + "px");

		//$("#contact_form_div").fadeIn("100");
		$("#contact_form_div").show();
	});
	
	$("#contact_form_overlay").click(function() {
		contact_close();
		
	});
	
	
	$("#contact_form").submit(function() {
	
		var field_name = $("#contact_name").attr("value");
		var field_org = $("#contact_org").attr("value");
		var field_email = $("#contact_email").attr("value");
		var field_phone = $("#contact_phone").attr("value");
		var field_comments = $("#contact_comments").attr("value");
		
		var field_submit = true;
		
		if ($.trim(field_name).length==0) {
			$("#contact_name").css("border", "1px solid #c72e15");
			
			field_submit = false;
		
		} else {
			$("#contact_name").css("border", "1px solid #464646");
		
		}
		
		if ($.trim(field_email).length==0) {
			$("#contact_email").css("border", "1px solid #c72e15");

			field_submit = false;
			
		} else {
			$("#contact_email").css("border", "1px solid #464646");

		}
		
		//console.log("posting...");

		if (field_submit) {
			$("#contact_msg").hide();
		
			$.post("listener_contact.php", { contact_name: field_name, contact_org: field_org, 
				contact_email: field_email, contact_phone: field_phone, contact_comments: field_comments },
				function(data) {
					//console.log("returned: " + data);

					//$("#contact_form_div_inside").html(data);

					$(".contact_form_text_pre").hide();
					$(".contact_form_text_post").show();

					if (data==1) {
						$("#contact_form_result_success").show();

					} else {
						$("#contact_form_result_error").show();

					}

				});

		}  else {
			$("#contact_msg").show();
		
		}

		return false;
	
	});

});

function contact_submit() {
	$("#contact_form").submit();
}

function contact_close() {
	$("#contact_name").attr("value", "");
	$("#contact_org").attr("value", "");
	$("#contact_email").attr("value", "");
	$("#contact_phone").attr("value", "");
	$("#contact_comments").attr("value", "");

	$("#contact_form_result_success").hide();
	$("#contact_form_result_error").hide();

	$(".contact_form_text_pre").show();
	$(".contact_form_text_post").hide();

	$("#contact_form_div").hide();
	$("#contact_form_overlay").hide();
	
}