
// common effects for all pages
// this will activate on page loaded if jquery is ready
$(function(){

	// roundedbox div, do this first so things inside are not broken
	$(".roundedbox").wrap(
	"<div style=\"margin: 0.6em 0 0.6em 0; text-align: center;\">"
	+"<div class=\"roundedboxA\">"
	+"<div class=\"roundedboxB\">"
	+"<div class=\"roundedboxC\">"
	+"</div></div></div></div>"
	).css({padding: "0px 20px 0px 20px", border: "0px none transparent", margin: "0px 0px 0px 0px"});
	
	// disappearing text for form fields
	$(".contact-field").blur(function(){
		if (!this.value) {
			$(this).css("color","#808080").css("text-align","center");
			this.value = this.defaultValue;
		}
	}).focus(function(){
		if (this.value == this.defaultValue) this.value = '';
		$(this).css("color",$(this).parent().css("color")).css("text-align","left");
	}).css("color","#808080").css("text-align","center");
	
	// form validation
	$("form").submit(function(){
		error = '';
		$(".required", this).each(function(){
			if ((this.value == '') || ((this.value == this.defaultValue) && $(this).hasClass("contact-field"))) {
				var label = $("label[for="+this.id+"]").text() || this.defaultValue || this.name;
				error = error + label + " is required.\r\n";
				$(this).addClass("error");
			}
			else {
				$(this).removeClass("error");
			}
		});
		if (error) {
			alert(error);
			return false;
		}
	});
	
	// automated submission
	$("select.auto-submit").change(function(){
		if (this.options[this.selectedIndex].value != this.options[this.selectedIndex].innerHTML) this.form.submit();
	});
	$("input.auto-submit").hide();
	
	// callout balloons
	$("a").mouseover(function(){
		var name = $(this).attr("rel");
		if (name) $("#" + name + ".callout").fadeIn("fast");
	}).mouseout(function(){
		var name = $(this).attr("rel");
		if (name) $("#" + name + ".callout").fadeOut("fast");
	}).mousemove(function(e){
		var name = $(this).attr("rel");
		if (name) $("#" + name + ".callout").css({left: (e.pageX + 5) + "px", top: (e.pageY + 5) + "px"});
	});

	$(".tabs .tab a").click(function(){
		$(this).parent().addClass("activetab").siblings(".tab").removeClass("activetab").children("a").each(function(){
			$(this.hash).hide();
		});
		$(this.hash).show();
		return false;
	}).eq(0).click();

	$(".slider-buttons").each(function(){
		var buttons = $(this);
		var sliderbox = buttons.siblings(".sliderbox");
		sliderbox.children(".slider").each(function(i){
			var button = $("<a/>").attr("href", "#"+this.id).html(i+1).click(function(){
				sliderbox.height(sliderbox.height());
				$(this).addClass("activebutton").siblings("a").removeClass("activebutton");
				sliderbox.children(".activeslider").not(this.hash).fadeOut().removeClass("activeslider");
				$(this.hash).stop().fadeIn("normal", function(){
					$(this).addClass("activeslider");
					sliderbox.height("auto");
				});
				sliderbox.animate({height: $(this.hash).height() + "px"});
				return false;
			});
			buttons.append(button);
			if (i == 0) button.addClass("activebutton");
		});
	}).load(function(){$(this).children("a").eq(0).click();});
});

