// JavaScript Document


$.fn.childHeights = function() {
	var result = "";
	$(this).children().each(function() { 
		result = result + $(this).height() + ", ";
	});
	alert(result);
}

//********************************************
// equalize left and right columns
function equalize()  {
	$("div#left-column").css('min-height',0);
	$("div#right-column").css('min-height',0);
	
	var hl = $("div#left-column").height();
	var hr = $("div#right-column").height();

	if (hr > hl)
		$("div#left-column").css('min-height',hr);
	else
		$("div#right-column").css('min-height',hl - 38);
}


//********************************************
// uses the ident variable defined on the page to highlist
// the appropriate tab
function highlight()  {
	$("div.main-menu > div").removeClass('active');
	$("#" + ident).addClass('active');
}

//********************************************
// pops up a video window with a youtube video
function popupYouTubeVideo(vid_id) {
	mywindow = window.open("/biz-net-video.php?ytid=" + vid_id,"videofeed","location=0,status=0,scrollbars=0,  width=520,height=430");
  mywindow.moveTo(20, 20);

	return(false);
}

//********************************************
// retrieves a random testimonial and loads it into 
// a sidbar block
function loadTestimonial() {
	// hide testimonials on the clients page
	if (ident != "clients") {
		document.body.style.cursor = "wait";
		
		// make AJAX call
		$.ajax({
			type: "POST",
			url: "http://" + location.hostname + "/php/get-random-testimonial.php", 
			data: "",
			dataType: "json", 
			success: function(data) {	
				var testi = '<h2>What Clients Say</h2><p><a href="/biz-net-video.php"><img src="' + data.vidthumb + '" width="223" height="166" onclick="return popupYouTubeVideo(\'' + data.ytid + '\');"></a><br /><strong>' + data.name + '<br />' + data.org + '</strong></p>';
				$("#testimonial").html(testi);
				
				equalize();
				document.body.style.cursor = "default";
			},
			error: function(a, b, c) {
				document.body.style.cursor = "default";
				alert('AJAX error occurred: ' + b + '\n' + a.responseText);
				equalize();
			}
		});	
	}
	else
		$(".clienttest").css('display','none');
}

//******************************************
// show or hide the extra fields required for postal delivery
function togglePostal() {
	if ($("input#frm_use_snail_mail:checked").length > 0) 
		$("div.postal_extra").show(800, equalize);
	else 
		$("div.postal_extra").hide(800, equalize);
}

function hidePostal() {
	$("div.postal_extra").hide(0);
}

function hideRedundantForm() {
	if (ident == "newsletter") {
		$("#newsletter_rform").css('display','none');
	}
	
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

$(function() {
	hidePostal();
	hideRedundantForm();
	highlight();
	loadTestimonial();  // calls equalize() after ajax
	togglePostal();
	$("input#frm_use_snail_mail").change(togglePostal);
});
