/*-------------------------------------------------------------------- 
* JQuery Plugin: "EqualHeights"
* by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
*
* Copyright (c) 2008 Filament Group
* Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
--------------------------------------------------------------------*/

$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) { currentTallest = currentTallest.pxToEm(); } //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

/*-------------------------------------------------------------------- 
* javascript method: "pxToEm"
* by:
Scott Jehl (scott@filamentgroup.com) 
Maggie Wachs (maggie@filamentgroup.com)
http://www.filamentgroup.com
*
* Copyright (c) 2008 Filament Group
* Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
--------------------------------------------------------------------*/

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
/* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size.
For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size.
When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size)
to get an accurate em value. */
				
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); }
			
	var result = (settings.reverse === true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};

$(document).ready( function() {
    // home page learn more boxes
    $( ".box" ).hover( function() {
        $(this).css( {cursor:"pointer"} );
        /* find out what page we're on by getting the parent element's
           id and grabbing the string before the "_" */
        var pg = $(this).parent().get(0).id;
        pg = pg.substr( 0, pg.indexOf( "_" ) );
        var target = $(this).children(".slideDn");
        $(target).stop().animate( {top:"-15px"}, 250, null, function() { 
            target.siblings("."+pg+"BoxBot").css( {backgroundImage:"none"} );
        } );
        target.siblings("."+pg+"BoxBodBorders").children("."+pg+"BoxBod").css( {backgroundImage:"url('/images/"+pg+"_box_grad_hover.gif')", cursor:"pointer"} );
        target.siblings("."+pg+"BoxTop").css( {backgroundImage:"url('/images/"+pg+"_box_hover_top.png')", cursor:"pointer"} );
    }, function() {
        var pg = $(this).parent().get(0).id;
        pg = pg.substr( 0, pg.indexOf( "_" ) );
        $(this).children("."+pg+"BoxBot").css( {backgroundImage:"url('/images/"+pg+"_box_bot.png')", cursor:"auto"} );
        $(this).children(".slideDn").stop().animate( {top:"-52px"}, 250 );
        $(this).children("."+pg+"BoxBodBorders").children("."+pg+"BoxBod").css( {backgroundImage:"url('/images/"+pg+"_box_grad.gif')", cursor:"auto"} );
        $(this).children("."+pg+"BoxTop").css( {backgroundImage:"url('/images/"+pg+"_box_top.png')", cursor:"auto"} );
    } ).click( function() {
        var goto = $(this).children(".slideDn").children("a").get(0);
        //location.href = "/"+$(goto).attr("href");+".php";
    } );

    // left nav, non-critical but desired appearance stuff
    $( ".itemOff").not( ".navIcon").hover( function() {
        $(this).css( {cursor:"pointer"} );
        $(this).children( "a" ).css( {color:"#FF7700"} );
    }, function() {
        $(this).css( {cursor:"auto"} );
        $(this).children( "a" ).css( {color:"#0282C4"} );
    } ).click( function() {
        location.href = $(this).children( "a" ).attr( "href" );
    } );

    $(function(){ $('#equalize').equalHeights('true'); });
    
    $( ".learn-more .box-body" ).hover( function() {
        $(this).css( {backgroundImage:"url('/images/box_learn-more_body-hover.png')"} );
        $(this).parent().siblings(".learn-more .box-top").css( {backgroundImage:"url('/images/box_learn-more_top-hover.png')"} );
    }, function() {
        $(this).css( {backgroundImage:"url('/images/box_learn-more_body.png')"} );
        $(this).parent().siblings(".learn-more .box-top").css( {backgroundImage:"url('/images/box_learn-more_top.png')"} );
    } );
    

	// Image maps for products
	$( "area" ).hover( function() {
		var classy = $(this).attr("class");
        $("#diagram-map").attr("class",classy);
      }, 
      function () {
      	var classy = $(this).attr("class");
        $("#diagram-map").removeClass(classy);
      }
    );
    
	$(function() {
		$('#leftNavUl li').hover(function(){
			$(this).addClass('over');
		}, function() {
			$(this).removeClass('over');
		});
	});
} );

$(document).ready(
	function()
	{
		if($('#contact-us-form').length)
		{
			var notice = function(obj)
			{
				$(obj).css('background-color','#FF668C');
				setTimeout(function(){$(obj).css('background-color','white');},2000);
			}
			var submit = function()
			{
				var result = true;
				$('#contact-us-form input, #contact-us-form textarea').each(
					function(obj)
					{
						if($(this).val() == '')
						{
							//notice($(this));
							result = false;
							return;
						}
					}
				);
				if(result == false)
				{
					alert("Please fill out every field to submit");
				}
				return result;
			}
			$('#contact-us-form').submit(submit);
		}
	}
);


