 $(document).ready(function(){

   $("div.action-container").click(
      function() {
        location.href = $(this).attr("rel");
      }
    )

	$("div.action-container").hover(function(){
	  $(this).addClass("hover");
    var currentTop = parseInt($(this).find("img.action-icon").css("top"),10);
    newTop = currentTop + 300;
    $(this).find("img.action-icon").css("top",newTop)

	},function(){
	  $(this).removeClass("hover");
    var currentTop = parseInt($(this).find("img.action-icon").css("top"),10);
    newTop = currentTop + -300;
    $(this).find("img.action-icon").css("top",newTop)
	});


	$("div.buttonSubmit").hover(function(){
	  $(this).addClass("buttonSubmitHover");

	},function(){
	  $(this).removeClass("buttonSubmitHover");
	});

  if ($.browser.safari == true) {
    $("body").addClass("safari");
  }


	$(".inlineLink").click
	(
		function(){
      window.open($(this).attr('rel'));
      return false;
    }
	);


/* dont include for blog
$("ul.blogUL").load("/includes/rssblog.php",
  function() {
    $("ul.blogUL").css("background","none");
  }
);
*/
//form validation



	$("form input").focus
	(
		function(){$(this).parents("tr").removeClass("errorRow")}
	);


	//email validation
	$("input[@uitype=email]").blur
	(
		function() {

			var x = this.value;
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (filter.test(x) || x == "") //passed or empty
			{
				$(this).parents("tr").removeClass("errorRow")
			}
			else // failed
			{
				$(this).attr("value","")
			   	$(this).parents("tr").addClass("errorRow")
			}


		}
	);


	// check for required Fields
	$(".formButton").click
	(
		function()
		{

			var oTable = $(this).parents("table")[0];
		   	var inputArrayEmpty = $(oTable).find("tr.required input[@value='']");
			var trArray = $(inputArrayEmpty).parents("tr");

			if (trArray.length > 0)
			{
				$(trArray).addClass("errorRow");
				$(".error").show();

				if (trArray.length < 2)
				{
					$(".error span").html(trArray.length + ' field.  It has been highlighted below');
				}
				else
				{
					$(".error span").html(trArray.length + ' fields.  They have been highlighted below');
				}

				return false;
			}

			else
			{
				this.disabled = 'true';
				this.value = 'Please wait';
				$('form').submit();
			}


		}
	);



$("input.phone").keyup( function() {
	formatPhoneNumberInput(this)
 } );

/* don't include for blog
$('#scrollup').cycle({
    fx:    'scrollUp',
    pause:  1,
    random:  1,
    speed:  2500,
    timeout:  15000
});
*/

   hideOverlay();

 });





function hideOverlay() {
	$(".resize").equalHeight();
	$("#page-container:hidden").css("visibility","visible");

}



/*
 * EqualHeight 1.0
 * Requires the dimensions plug-in (.outerHeight())
 * Copyright (c) 2007 Andreas Lagerkvist (exscale.se)
 */
jQuery.fn.equalHeight = function()
{
	var maxHeight = 0;

	// Store the tallest element's height
	this.each(function()
	{
		var height = jQuery(this).outerHeight();
		maxHeight = (height > maxHeight) ? height : maxHeight;
	});

	// Always return each...
	return this.each(function()
	{
		// Set element's min-height to tallest element's height
		var mh = maxHeight - parseInt(jQuery(this).css('paddingBottom'), 10) - parseInt(jQuery(this).css('paddingTop'), 10);
		jQuery(this).css({minHeight: mh +'px'});

		/* Use this code if you care about IE<7
		// Adjust all elements' bottom padding to make them equal height (why do this instead? for IE6 perhaps...)
		var pb = maxHeight - jQuery(this).outerHeight() + parseInt(jQuery(this).css('paddingBottom'), 10);
		jQuery(this).css({paddingBottom: pb +'px'});
		*/
	});
};




// This taks a number and formats it using the given mask. The mask
// is composed of any characters, but the character "9" is used as a
// place holder for the digits in the number passed.
function numberMask(strNumber, strMask)
{
	var strOutput = "";
	var intIndex = 0;
	var intNumIndex = 0;

	// Make sure that the number is a string
	strNumber = strNumber.toString();

	// Loop through the mask characters
	for (intIndex = 0 ; intIndex < strMask.length ; intIndex++)
	{
		// Check to see if the current character is a place holder
		// "9" or just another character. If we have a place holder, then
		// we also have to check to make sure we have a digit available.
		// If the digit is not available (ie. we have used up all of our number)
		// then let's break out of the loop.
		if (intNumIndex < strNumber.length)
		{
			// We have a number, so check the mask
			if (strMask.charAt(intIndex) == "9")
			{
				// We have a place holder and an avilable digit, so grab another
				// character from the number and add it to the output.
				strOutput = (strOutput + strNumber.charAt(intNumIndex++));
			}
			else
			{
				// We don't have a place holder, so just take the number from
				// the mask and add it to the output.
				strOutput = (strOutput + strMask.charAt(intIndex));
			}
		}
		else
		{
			// We have run out of numbers, so just break out of the loop
			break;
		}
	}

	// The mask has been applied, so return the output
	return(strOutput);
}

function formatPhoneNumberInput(objInput)
{
	// ONLY RUN THIS SCRIPT IF COUNTRY = USA.  Otherwise, this script needs to be internationalized.
	var strValue = objInput.value;
	var strPreValue = strValue;

	// Strip out the non-integer values
	//strValue = StripNonInteger(strValue);
	strValue = strValue.replace(new RegExp("[^0-9]{1,}", "gi"), "");
	strValue = strValue.substring(0, 10);

	// Strip out leading and training spaced
	strValue = strValue.replace(new RegExp("(^[ ]{1,})|([ ]{1,}$)", "gi"), "");

	// Check to see if the first digit is one. If so, then we have to delete it
	strValue = strValue.replace(new RegExp("(^[1]{1})", "gi"), "");
	// Check to see what length we have
	if (strValue.length <= 7)
	{
		// Format the number to be 999-9999
		objInput.value = numberMask(strValue, "999-9999");
	}
	else if (strValue.length <= 10)
	{
		// Forma the number to be (999) 999-9999
		objInput.value = numberMask(strValue, "999-999-9999");
	}
	else
	{
		// This is an invalid length, so just put old value back in
		objInput.value = strPreValue;
	}
}

