/*---------------------------------
 * Initiate Jquery Functions
 *---------------------------------
 */

//Kick-off / Page Load Functions
$(document).ready(function(){

	$("#contact").validate();

	$("a.popup_external").click(function(){
		var e=window.open($(this).attr("href"), 'external_popup', 'width=800, height=500, scrollbars=yes, menubar=yes, toolbar=yes');
		e.focus();
		return false;
	});
	
	// FancyBox Popups
	$("a.fb_video").fancybox({
		'overlayOpacity': .6,
		'frameWidth': 425,
		'overlayColor': '#222'
	});
	$("a.fb_video_widescreen").fancybox({
		'overlayOpacity': .6,
		'frameWidth': 560,
		'overlayColor': '#222'
	});


	//AutoPopulate by Andy Stratton (http://www.andystratton.com/)
	$("input.populate").each( function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
	$("input.populate").focus(function(){
		if ( $(this).val() == $(this).attr("title") ) {
			$(this).val("");
		}
	});
	$("input.populate").blur(function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});

	// Encrypt Email Addresses
	$(".mask").each(function(){
		var ats, dots, address, i;
		ats = [ ' at ', ' (at) ', ' [at] ' ];
		dots = [ ' dot ', ' (dot) ', ' [dot] ' ];
		address = $(this).html();
		for ( i = 0; i < ats.length; i++ ) {
			address = address.replace(ats[i], '@');
		}
		for ( i = 0; i < dots.length; i++ ) {
			address = address.replace(dots[i], '.');
		}
		$(this).html('<a href="mailto:' + address + '">' + address + '</a>');
	});
	
	//Fix leadgenform button
	$(".gform_wrapper input[type='submit']").val("");


});
