$(document).ready(function(){
	init();
});

function init() {
	//$.preloadCssImages();
	$(document).pngFix();
	$('div#header div.nav ul').superfish(); 
	$('div#header div.nav li').hover(
		function() {
			$(this).addClass('hover');
			//$('ul', this).addClass('hover');
		},
		function() {
			$(this).removeClass('hover');
			//$('ul', this).removeClass('hover');
		}
	);
	bubbleHeight();
	//buttonLeft();
	contentBubbleHeight();
	readyForm();
}

function readyForm() {
	$("form").jqTransform().submit(function() {
		return validForm(this);
	});
	$("form :input:first").focus();
}

function validForm(form) {
	var valid = true;
	$(form).each(function() {
		$(".required :input", this).each(function() {
			if ($(this).val() == '') valid = false;
		});
	});
	if (valid == false) {
		alert('Please complete all fields');
		return false;
	}
	return true;
}

function bubbleHeight() {
	var maxHeight = 0;
	var diffHeight = 0;
	$('div#main div.content_tp div.bubble').each(function(){
		if ($(this).height() > maxHeight) maxHeight=$(this).height();
	});
	$('div#main div.content_tp div.bubble').each(function(){
		if ($(this).height() < maxHeight) {
			diffHeight = maxHeight - $(this).height();
			$('p',this).each(function(){
				$(this).height(diffHeight+$(this).height());
			});
		}
	});
}

function contentBubbleHeight() {
	var maxHeight = 0;
	var diffHeight = 0;
	$('div#main div.content_md div.bubble div.middle').each(function(){
		if ($(this).height() > maxHeight) maxHeight=$(this).height();
	});
	$('div#main div.content_md div.bubble div.middle').each(function(){
		if ($(this).height() < maxHeight) {
			diffHeight = maxHeight - $(this).height();
			$(this).height(diffHeight+$(this).height());
		}
	});
}

function buttonLeft() {
	var buttonHeight = 0;
	var buttonPadding = 0;
	$('div#main div.content_lt div.button').each(function(){
		buttonHeight = $(this).height();
		$('a',this).each(function(){
			buttonPadding = (buttonHeight - $(this).height())/2;
			$(this).css('padding-top',buttonPadding+'px');
			$(this).css('padding-bottom',buttonPadding+'px');
		});
	});
}