$(document).ready(function(){
	//###############   Image slideshow   ###############
	$('#slideshow').cycle({
		timeout:8000,	// milliseconds between slide transitions (0 to disable auto advance) 
		speed:650,	// speed of the transition
		pause:1		// true (1) to enable "pause on hover" 
	});

	//###############   PRETTYPHOTO: Zoom functionality throughout content   ###############
	$("a[rel^='prettyPhoto']").prettyPhoto({
		showTitle: true
	});

	//###############   Tooltips (Downloads & Installations pages)   ###############
	if ($("#content .downloads a, #content .installations a.primary").length > 0) {
		$("#content .downloads a, #content .installations a.primary").tooltip({
			effect: 'slide',
			bounce:true,
			predelay: 200,
			offset:[22, 0]
		});
	}

	//###############   Survey page   ###############
	if ($("#content #survey-form").length > 0) {
		//###   Continue/Back buttons initailly hidden for non-JavaScript version   ###
		$("#survey-form .coda-nav-left, #survey-form .coda-nav-right").show();

		$("#content #survey-form").codaSlider({
			dynamicArrows: false,
			crossLinking: false,
			dynamicTabs: false
		});

		$("#content #survey-form label.other, #content #survey-form input.other").fadeOut("fast");
		$("#content #survey-form input.other").attr("disabled","true");
		$("#content #survey-form .other-option:checked").parent().next().fadeIn().next().fadeIn().removeAttr("disabled");

		$("#survey-form .coda-nav-left, #survey-form .coda-nav-right").click(function () {
			$.scrollTo("#coda-slider", {
				duration:750,
				offset:{left:0,top:-50}
			});
/* doesn't work			$(this).parents("form").validate(); */
		});

		//###   Showing a text box if other option selected   ###
		$("#content #survey-form .other-option").bind(($.browser.msie ? "click" : "change"), function () {
			if ($(this).attr("checked")) {
				$(this).parent().next().fadeIn("slow").next().fadeIn("slow").removeAttr("disabled");
				if ( parseInt($("#survey-form").css("height")) < 1100) {
					$("#survey-form").css("height", (parseInt($("#survey-form").css("height"))+50)+"px");
				}
			}
		});
	}

	//###############   Form focus & default text   ###############
	$("form input.required, form textarea.required").each(function(i) {
		$ParentForm = $(this).parents("form");
		if ($ParentForm.attr("name") == "search") {
			DefaultValue = "Enter your search term";
		} else {
			DefaultValue = "required";
		}
		$(this).attr("notequal", DefaultValue);
		if ($(this).val() == "") {$(this).val(DefaultValue).addClass("empty");}
		$(this).focus(function () {
			if ($(this).val() == DefaultValue) {
				$(this).val("").removeClass("empty");
			}
		}).blur(function () {
			if ($(this).val() == "") {
				$(this).val(DefaultValue).addClass("empty");
			}
		});
	});
});