/*
 * Initiate Jquery Functions
 *
 */

//Kick-off / Page Load Functions
$(document).ready(function(){
		
	//NEW TAB POPUP
	$('a[rel="external"]').attr("target", "_blank");
	$('a[rel="external nofollow"]').attr("target", "_blank");
	
	//FANCYBOX
	/*
	$('a[rel="lightbox-after"]').fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'titlePosition': 'inside' });
	$('a[rel="lightbox-before"]').fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'titlePosition': 'inside' });
	*/
	$('a.popup_learn_more').fancybox({
		'autoDimensions':false,
		'width': 420,
		'height': 180,
		'overlayColor':'#000',
		'overlayOpacity': .5,
		'titleShow': false,
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300
	});
	
	
	//AUTOPOPULATE
	$(".populate").each( function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
	$(".populate").focus(function(){
		if ( $(this).val() == $(this).attr("title") ) {
			$(this).val("");
		}
	});
	$(".populate").blur(function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
	
	//EMAIL MASK/ENCRYPT
	$(".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>');
	});

});