function fontReplace() {
	if(BrowserDetect.browser=="Explorer" && BrowserDetect.version=="6"){
		Cufon.replace('#topmenu a, #submenu a', { hover: true });
	} else {
		Cufon.replace('#topmenu a, #submenu a', { hover: true });
		Cufon.replace('h1, h2, h3, h4');
		Cufon.replace('.ldquo, .post_title a, .heading, .comment_title', { hover: true });
	}
}

Array.prototype.max = function() {
	var maxx = this[0];
	var len = this.length;
	for (var i = 1; i < len; i++) if (this[i] > maxx) maxx = this[i];
	return maxx;
}

function home_feature_box () {
	$('.home-feature-block:last').css('margin',0);
	$('.home-feature-block').wrapInner('<div class="home-feature-block-content"></div>');
	$('.home-feature-block').append('<div class="home-feature-block-btm"></div>');
	
	$(document).ready(function(){
		var h1 = $('#home-featurebox-1 .home-feature-block-content').height();
		var h2 = $('#home-featurebox-2 .home-feature-block-content').height();
		var h3 = $('#home-featurebox-3 .home-feature-block-content').height();
		var hs = [h1, h2, h3];
		var h = hs.max();
		$('.home-feature-block .home-feature-block-content').css('height',h);
	
		if (h>63) { /* bg_featurebox_top height - 10px top padding */
			$('.home-feature-block').prepend('<div class="home-feature-block-mid"></div>');
			$('.home-feature-block-mid').css('height',h-63);
		}

	});
}

function side_feature_box () {
	$('.sidequote').wrapInner('<div class="sidequote-content"></div>');
	$('.sidequote').append('<div class="sidequote-btm"></div>');
	
	var h = $('.quote-text').height()+40; /* 40 is a tweak */
	$('.sidequote-content').css('height',h);

	if (h>129) { /* bg_sidequote_top height - 10px top padding */
		$('.sidequote').prepend('<div class="sidequote-mid"></div>');
		$('.sidequote-mid').css('height',h-129);
	}
	
}

function imgBtnStyle () {
	//$("img#btn-demo").attr("src", $("img#btn-demo").attr("src").replace(".png",".gif"));
	
	$(".button img").bind("mousedown",
		function() { $(this).attr("src", $(this).attr("src").split("_static.").join("_over.")); }
	);
	$(".button img").bind("mouseup",
		function() { $(this).attr("src", $(this).attr("src").split("_over.").join("_static.")); }
	);
}

function checkForm(formObj) {
	var formOK = true;
	formOK = checkEmail (formObj.email.value, '#error_email');

	if (formObj.first_name.value == "") {
		$('#error_first_name').html("You must provide full name");
		formOK = false;
	}
	if (formObj.last_name.value == "") {
		$('#error_last_name').html("You must provide your last name");
		formOK = false;
	}
	if (formObj.phone.value == "") {
		$('#error_phone').html("You must provide your phone number");
		formOK = false;
	}
	if (formObj.company.value == "") {
		$('#error_company').html("You must provide your company");
		formOK = false;
	}
	if (formObj.city.value == "") {
		$('#error_city').html("You must provide your city");
		formOK = false;
	}
	if (formObj.country.value == "") {
		$('#error_country').html("You must privode your country");
		formOK = false;
	}

	if (formOK == true) {
		formObj.submit();
	}
}


function checkEmail(emailField, errorContainer) {
	if (emailField.length == 0) {
		$(errorContainer).html("You must provide e-mail address");
		return false;
	}
	if (emailField.indexOf(" ") > -1) {
		$(errorContainer).html("E-mail address has invalid space");
		return false;
	}
	if (emailField.indexOf("/") > -1) {
		$(errorContainer).html("E-mail address has invalid character: /");
		return false;
	}
	if (emailField.indexOf(":") > -1) {
		$(errorContainer).html("E-mail address has invalid character: :");
		return false;
	}
	if (emailField.indexOf(",") > -1) {
		$(errorContainer).html("E-mail address has invalid character: ,");
		return false;
	}
	if (emailField.indexOf(";") > -1) {
		$(errorContainer).html("E-mail address has invalid character: ;");
		return false;
	}
	if (emailField.indexOf("@") < 0) {
		$(errorContainer).html("E-mail address is missing @");
		return false;
	}
	if (emailField.indexOf("\.") < 0) {
		$(errorContainer).html("E-mail address is missing .");
		return false;
	}
	return true;
}



$(document).ready(function() {
	if(BrowserDetect.browser=="Explorer" && BrowserDetect.version=="6"){
	}
	
	$('#quote .quote-text').before('<div class="ldquo">&ldquo;</div>');
	$('#quote .quote-text h2').append('&rdquo;');
	imgBtnStyle();
	$('#header a').attr('title','');
	$('#topmenu li a:first, #submenu li a:first').css('border',0);
	$('#topmenu li a:last').addClass('last-menu');
	$('.entry').find('p:last').css('margin',0);
	/*
	$('.page').wrapInner('<div class="page-wrap-mid unitPng"></div>');
	$('.page').prepend('<div class="page-wrap-top unitPng"> </div>');
	$('.page').append('<div class="page-wrap-btm unitPng"> </div>');
	*/
	fontReplace();
});