// JavaScript Document


Date.prototype.setISO8601 = function (string) {
    var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
        "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
        "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
    var d = string.match(new RegExp(regexp));

    var offset = 0;
    var date = new Date(d[1], 0, 1);
	
    if (d[3]) { date.setMonth(d[3] - 1); }
    if (d[5]) { date.setDate(d[5]); }
    if (d[7]) { date.setHours(d[7]); }
    if (d[8]) { date.setMinutes(d[8]); }
    if (d[10]) { date.setSeconds(d[10]); }
    if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
    if (d[14]) {
        offset = (Number(d[16]) * 60) + Number(d[17]);
        offset *= ((d[15] == '-') ? 1 : -1);
    }

    offset -= date.getTimezoneOffset();
    time = (Number(date) + (offset * 60 * 1000));
    this.setTime(Number(time));
};



// Featured Content: Layered Images
jQuery('.feature_layered_image').not('.feature_layered_image_simple').hover(function() {
	jQuery(this).find('.overlay').stop().fadeTo(500, .8);
	jQuery(this).find('.foreground').stop().show().css({ "left" : "-"+jQuery(this).width()+"px" }).animate({left : 0}, 300);
}
,function() {
	jQuery(this).find('.overlay').stop().fadeTo(500, 0);
	jQuery(this).find('.foreground').stop().animate({left : jQuery(this).width()}, 300);
});

jQuery('.feature_layered_image_simple').hover(function() {
	jQuery(this).find('.foreground').stop(true, true).css({ "left" : "-0px" }).fadeIn(500);
}
,function() {
	jQuery(this).find('.foreground').stop(true, true).fadeOut(500);
});

if (typeof(featureLoaded_li) == 'function') {
	featureLoaded_li();
}


// Featured Content: YouTube Slideshow
function rfc_openShadowbox(obj) {
	obj = jQuery(obj);
	
	obj.parent().find('.'+ obj.attr('class') ).css('marginTop', '0px').hide();
	obj.parents('#rfc_shadowbox').css('height', 'auto').show();
	obj.show();
	
	if (jQuery('#rfc_shadowbox').innerHeight() <= jQuery('#rfc_shadowbox_container').innerHeight()) {
		topMargin = ((jQuery('#rfc_shadowbox_container').innerHeight() - jQuery('#rfc_shadowbox').innerHeight()) / 2);
		obj.css('marginTop', topMargin+'px');
		obj.find('.close').css('marginTop', (topMargin - 20)+'px');
		jQuery('#rfc_shadowbox').css('height', jQuery('#rfc_shadowbox_container').innerHeight()+'px');
	
	} else {
		jQuery('#rfc_shadowbox_container').css('height', jQuery('#rfc_shadowbox').innerHeight()+'px');
	}
	
	if (jQuery.browser.mozilla) {
		jQuery('#rfc_shadowbox').fadeIn(500);
	} else {
		jQuery('#rfc_shadowbox').slideDown(500);
	}
	
	jQuery('.feature_image_slideshow .controlls').hide();
}

jQuery('.feature_youtube_slideshow .ul_container').each(function() {
	if (!jQuery(this).hasClass('no_jScroll')) {
		jQuery(this).jScrollPane({showArrows: true, verticalDragMinHeight: 50, verticalDragMaxHeight: 50});
	}
});

jQuery('.feature_youtube_slideshow ul li div.overlay, .feature_youtube_slideshow ul li div.foreground, .feature_youtube_slideshow ul li a, .feature_youtube_slideshow_bar ul li div.overlay, .feature_youtube_slideshow_bar ul li div.foreground, .feature_youtube_slideshow_bar ul li a').each(function() {
	jQuery(this).css('width', jQuery(this).parent().css('width'));
	jQuery(this).css('height', jQuery(this).parent().css('height'));
});

jQuery('.feature_youtube_slideshow ul li a').click(function(event) {
	event.preventDefault();
	
	video_id = jQuery(this).parents('li').first().attr('video');
	container = jQuery(this).parents('.feature_youtube_slideshow').find('.video_container').first();
	
	rfc_youtube_build( video_id, container );
});

jQuery('.feature_youtube_slideshow_bar ul li a').click(function(event) {
	event.preventDefault();
	
	siblingAnchor = jQuery('.feature_youtube_slideshow a[name="'+ jQuery(this).attr('name') +'"][href='+ jQuery(this).attr('href') +']').first();
	siblingAnchor.parents('.youtube_slideshow_container:first').find('.video_container').css(
		'backgroundImage',
		"url('"+siblingAnchor.attr('backgroundImage')+"')"
	);
	
	rfc_openShadowbox( siblingAnchor.parents('.youtube_slideshow_container:first') );
	siblingAnchor.trigger('click');
});

jQuery('#rfc_shadowbox .close').click(function(event) {
	if (jQuery.browser.mozilla) {
		jQuery('.feature_image_slideshow .controlls').fadeIn(500);
	} else {
		jQuery('.feature_image_slideshow .controlls').show();
	}
	
	jQuery('#rfc_shadowbox').slideUp(500, function() {
		jQuery('#rfc_shadowbox iframe').remove();
	});
});

jQuery('.feature_youtube_slideshow ul li, .feature_youtube_slideshow_bar ul li').hover(function() {
	jQuery(this).find('.overlay').stop().fadeTo(500, .8);
	jQuery(this).find('.foreground').stop().show().css({ "left" : "-"+jQuery(this).width()+"px" }).animate({left : 0}, 300);
}
,function() {
	jQuery(this).find('.overlay').stop().fadeTo(500, 0);
	jQuery(this).find('.foreground').stop().animate({left : jQuery(this).width()}, 300);
});

// If YouTube API tooltips are enabled
if (jQuery('.youtube_has_apiTooltip').size() > 0) {
	function youtube_apiTooltip( video_id ) {
		video_obj = jQuery('.youtube_has_apiTooltip[video="'+video_id+'"]');
		item_offset = video_obj.offset();
		item_width = video_obj.outerWidth(false);
		
		if (jQuery('#youtube_apiTooltip').size() > 0 && jQuery('#youtube_apiTooltip').attr('rel') == video_id) {
			// Prevent the delayed fade/hide from running.
			window.clearTimeout(youtube_api_mouseLeaveTimer);
			jQuery('#youtube_apiTooltip').stop(true).show();
			
		} else {
			if (jQuery('#youtube_apiTooltip').size() > 0) {
				jQuery('#youtube_apiTooltip').remove();
			}
			
			jQuery('body').append('<div id="youtube_apiTooltip" rel="'+ video_id +'"><div class="content"></div></div>');
			jQuery('#youtube_apiTooltip')
				.css('top', (item_offset.top - jQuery('#youtube_apiTooltip').innerHeight() +'px') )
				.css('left', ((item_offset.left + item_width) +'px'))
				.mouseenter(function() {
					// Prevent the delayed fade/hide from running.
					window.clearTimeout(youtube_api_mouseLeaveTimer);
					jQuery('#youtube_apiTooltip').stop(true).show();
				})
				.mouseleave(function() {
					jQuery('#youtube_apiTooltip').stop(true).hide();
					jQuery('.feature_youtube iframe, .feature_youtube_slideshow iframe').show();
				});
		
			var request_url = jQuery('#global_var_blog_url').val() +'/?proxy_youtube_api='+ video_id +'&json=true';
			
			jQuery.ajax({
				cache: true,
				context: video_obj,
				crossDomain: true,
				dataType: 'json',
				url: request_url,
				success: function(data) {
					if (data.entry) {
						duration = parseInt(data.entry.media$group.media$content[0].duration);
						mins = Math.floor(duration / 60);
						seconds = (duration - (mins*60));
						
						jQuery('#youtube_apiTooltip .content').append('<div class="title">'
							+ data.entry.title.$t
							+' <small>('+mins+':'+seconds+')</small></div>');
						
						jQuery('#youtube_apiTooltip .content').append('<div class="author">'
							+ '<a href="'+ data.entry.author[0].uri.$t +'" target="_blank">'+ data.entry.author[0].name.$t +'</a>'
							+'</div>');
						
						
						var months = {0: 'January', 1: 'February', 2: 'March', 3: 'April', 4: 'May', 5: 'June', 6: 'July', 7: 'August', 8: 'September', 9: 'October', 10: 'November', 11: 'December'};
						if (jQuery.browser.mozilla) {
							var published = new Date( data.entry.published.$t );
						} else {
							var published = new Date();
							published.setISO8601( data.entry.published.$t );
						}
						
						// Y2K bug
						if (published.getYear() > 100 && published.getYear() < 1970) {
							year = 2000 + (published.getYear() - 100);
						} else {
							year = published.getYear();
						}
						
						jQuery('#youtube_apiTooltip .content').append('<div class="date">'
							+ months[ published.getMonth() ]
							+ ' ' + published.getDay()
							+ ', ' + year
							+'</div>');
						
						jQuery('#youtube_apiTooltip .content').append('<div class="views">'
							+ data.entry.yt$statistics.viewCount
							+' views</div>');
						
						jQuery('#youtube_apiTooltip .content').append('<div class="description">'
							+ data.entry.media$group.media$description.$t
							+'</div>');
						
						jQuery('#youtube_apiTooltip .content').css('backgroundImage', 'none');
					}
				}
			});
		}
	}
	
	var youtube_apiTimer = false;
	var youtube_api_mouseLeaveTimer = false;
	jQuery('.youtube_has_apiTooltip').mouseover(function(event) {
		window.clearTimeout(youtube_apiTimer);
		youtube_apiTimer = window.setTimeout("youtube_apiTooltip('"+ jQuery(this).attr('video') +"')", 1000);
	})
	.mouseout(function(event) {
		window.clearTimeout(youtube_apiTimer);
		window.youtube_api_mouseLeaveTimer = setTimeout("jQuery('#youtube_apiTooltip').hide(); jQuery('.feature_youtube iframe, .feature_youtube_slideshow iframe').show();", 350);
	});
}

// If custom scrollers are enabled
if (jQuery('.has_youtube_slideshow .custom_scroller_first').size() > 0) {
	function innovChild_scroll( obj, dir ) {
		container = obj.siblings('.ul_container');
		container_width = container.innerWidth();
		
		ul = container.find('ul');
		by = ul.find('li:first').outerWidth(true);
		ul_left = Math.abs( parseInt(ul.css('left').replace('px','')) );
		ul_width = ul.innerWidth();
		
		not_to_exceed = (ul_width - container_width);
		
		if (dir == 'fwd') {
			if (ul_left >= not_to_exceed) {
				// It's already as far back as it can go. Do nothing.
				
			} else if ((ul_left + by) >= not_to_exceed) {
				// Go back to not_to_exceed
				ul.stop(true, true).animate({left: '-'+not_to_exceed+'px'}, 300);
				
			} else {
				// Go back to ul_left - by
				ul.stop(true, true).animate({left: '-'+(ul_left + by)+'px'}, 300);
			}
		}
		
		if (dir == 'back') {
			if (ul_left != 0) {
				if ((ul_left - by) < 0) {
					// Do nothing
					
				} else {
					ul.stop(true, true).animate({left: '-'+(ul_left - by)+'px'}, 300);
				}
			}
		}
	}
	
	jQuery('.has_youtube_slideshow .custom_scroller_first, .feature_youtube_slideshow_bar .custom_scroller_first').click(function() {
		innovChild_scroll(jQuery(this), 'back');
	});
	
	jQuery('.has_youtube_slideshow .custom_scroller_last, .feature_youtube_slideshow_bar .custom_scroller_last').click(function() {
		innovChild_scroll(jQuery(this), 'fwd');
	});
	
	// Normalize margins
	jQuery('.feature_youtube_slideshow_bar').each(function() {
		jQuery(this).find('ul li').last().css('marginRight', '0px');
	});
}


if (typeof(featureLoaded_ytss) == 'function') {
	featureLoaded_ytss();
}


//if (jQuery('.feature_youtube, .feature_youtube_slideshow, .load_youtube_api').size() > 0) { // load the youtube api always.
	if (jQuery('#youtube_player_api').size() == 0) {
		var tag = document.createElement('script');
		tag.src = "http://www.youtube.com/player_api";
		tag.id = 'youtube_player_api';
		var firstScriptTag = document.getElementsByTagName('script')[0];
		firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
	}
//}


function rfc_youtube_getTarget( video_url ) {
	var event_target = false;
	
	if (!jQuery.browser.msie || (jQuery.browser.msie && parseInt(jQuery.browser.version) > 8)) {
		video_url = video_url.substr(0, video_url.indexOf('&'));
		video_id = video_url.substr(video_url.indexOf('?v=') + 3);
		search_url = 'www.youtube.com/embed/'+ video_id;
		
		jQuery('iframe').each(function(){
			if (jQuery(this).attr('src').indexOf(search_url) > 0) {
				event_target = jQuery(this);
			}
		});
	}
	
	if (event_target == false) {
		known_videos = jQuery('iframe[src*="www.youtube.com/embed/"]');
		if (known_videos.size() > 0) {
			event_target = known_videos.first();
		}
	}
	
	return event_target;
}


function rfc_youtube_build( video_id, container ) {
	supports_video = true;
	supports_flash = true;
	supports_html5_video = false;
	
	// Get Flash support
	if (typeof(swfobject) == 'object') {
		flashVersion = swfobject.getFlashPlayerVersion();
		if (typeof(flashVersion) == 'object') {
			if (parseInt(flashVersion.major) <= 0) {
				supports_flash = false;
			} else {
				//alert('Supports Flash '+flashVersion.major+'.'+flashVersion.minor+'.'+flashVersion.release);
			}
		} else {
			supports_flash = false;
		}
	} else {
		alert("Please contact the administrator.\nrfc_youtube_build: swfobject not found.");
	}
	
	
	if (supports_flash == false) {
		// This browser/device doesn't support Flash.
		
		if (Modernizr.video == false) {
			// This browser/device also doesn't support HTML5 video.
			supports_video = false;
		
		// If supports HTML5, but YouTube only supports some browsers
		} else {
			if (jQuery.browser.mozilla && parseInt(jQuery.browser.version) >= 4) {
				// Firefox 4+ is supported.
				supports_html5_video = true;
				
			} else if (jQuery.browser.msie && parseInt(jQuery.browser.version) >= 9) {
				// IE 9+ is supported.
				supports_html5_video = true;
				
			} else if (jQuery.browser.opera && parseInt(jQuery.browser.version) >= 10.6) {
				// Opera 10.6+ is supported.
				supports_html5_video = true;
				
			} else if (jQuery.browser.webkit) {
				// YouTube may support this browser, but we're not sure yet.
				
				if (navigator.vendor.indexOf('Google') >= 0) {
					// Google Chrome is supported.
					supports_html5_video = true;
					
				} else if (navigator.userAgent.indexOf('Safari') >= 0 && navigator.vendor.indexOf('Apple') >= 0 && (navigator.platform.indexOf('Win') >= 0 || navigator.platform.indexOf('Mac') >= 0)) {
					// Desktop versions of Safari are supported.
					supports_html5_video = true;
					
				} else {
					// HTML5 Video may be supported, but YouTube is not.
					supports_video = false;
				}
			} else {
				// HTML5 Video may be supported, but YouTube is not.
				supports_video = false;
			}
		}
	}
	
	if (supports_video == false && supports_html5_video == true) {
		// Analytics Tracking Option: Supports HTML5 Video, but isn\'t supported by YouTube.
	}
	
	if (supports_video == false) {
		var youtube_url = 'http://www.youtube.com/watch?v='+video_id;
		var myTest = window.open(youtube_url, '', '');
		
		// New window/tab failed, open YouTube in this window/tab.
		if (!myTest) window.location.href = youtube_url;
		return;
	}
	
	if (supports_flash == true) {
		// Analytics Tracking Option: Flash Video
	}
	
	if (supports_flash == false && supports_html5_video == true) {
		// Analytics Tracking Option: HTML5 Video
	}
	
	// Congrats, the browser supports some form of YouTube video.
	if (typeof(YT) == 'object') {
		// Remove any videos already in the container
		container.find('iframe').remove();
		
		if (typeof(window['youtube_videos']) != 'object') {
			window['youtube_videos'] = new Array();
		}
		
		if (jQuery.browser.msie && parseInt(jQuery.browser.version) <= 8) {
			container.css('overflow', 'hidden');
			width = parseInt(container.css('width').replace('px','')) + 4;
			height = parseInt(container.css('height').replace('px','')) + 4;
		} else {
			width = container.css('width').replace('px','');
			height = container.css('height').replace('px','');
		}
		
		window['youtube_videos'][ container.attr('id') ] = new Object();
		window['youtube_videos'][ container.attr('id') ].state = -1;
		window['youtube_videos'][ container.attr('id') ].container = jQuery(this);
		window['youtube_videos'][ container.attr('id') ].player = new YT.Player(
			container.attr('id'),
			{
				width: width,
				height: height,
				videoId: video_id,
				playerVars: {
					border: 0,
					wmode: 'opaque'
				},
				events: {
					'onReady': function(event) {
						if (jQuery.browser.msie && parseInt(jQuery.browser.version) <= 8) {
							target = rfc_youtube_getTarget( event.target.getVideoUrl() );
							target.css('position', 'absolute').css('top', '-2px').css('left', '-2px');
						}
						
						event.target.playVideo();
					},
					'onStateChange': function(event) {
						target = rfc_youtube_getTarget( event.target.getVideoUrl() );
						
						container = target.parents('.video_container').first();
						if (container.size() == 0) container = target.parents('#video_container').first();
						
						if (container.size() == 1) {
							window['youtube_videos'][ container.attr('id') ].state = event.data;
						}
					}
				}
			}
		);
	}
}

jQuery('.feature_youtube .video_container').click(function(event) {
	if (jQuery(this).get(0).nodeName == 'A') {
		event.preventDefault();
	}
	
	rfc_youtube_build( jQuery(this).attr('video'), jQuery(this) );
});

if (typeof(featureLoaded_yt) == 'function') {
	featureLoaded_yt();
}




function image_slideshow_next() {
	jQuery('.feature_image_slideshow').each(function() {
		_image_slideshow_next( jQuery(this).attr('id') );
	});
}

function _image_slideshow_next( id ) {
	current = jQuery('#'+id).find('.image:visible').first();
	
	if (current.not(':animated').size() > 0) {
		if (jQuery('#'+id+'[to]').size() > 0) {
			speed = 300;
		} else {
			speed = 600;
		}
		
		next = current.next('.image');
		
		if (next.size() == 1) {
			is_last = false;
		} else {
			is_last = true;
			next = jQuery('#'+id).find('.image').first();
		}
		
		jQuery('#'+id).find('.controlls span').removeClass('on');
		jQuery('#'+id).find('.controlls span:nth-child('+ (next.index()+1) +')').addClass('on');
		
		current.stop().css('left', '0px');
		next.stop().css('left', jQuery('#'+id).width()+'px');
		
		current.animate({left : '-'+jQuery('#'+id).width()+'px'}, speed);
		next.show().animate({left : '0px'}, speed, function() {
			// If this is the last one...
			if (jQuery(this).index() == jQuery(this).siblings().size()) {
				jQuery(this).siblings('.image:visible').last().hide();
			} else {
				jQuery(this).siblings('.image:visible').first().hide();
			}
			
			container = jQuery(this).parents('#'+id+'[to]').first();
			
			if (container.size() > 0) {
				if (container.attr('to') != jQuery(this).index()) {
					setTimeout("_image_slideshow_next('"+container.attr('id')+"');", 5);
					return true;
				} else {
					// Remove the target index
					container.removeAttr('to');
					
					// Restart the interval
					intervals_imageSlideShow[ id ] = window.setInterval("_image_slideshow_next('"+id+"')", 6000);
				}
			}
		});
	}
}

function image_slideshow_to(id, to) {
	if (!id) {
		id = jQuery('.feature_image_slideshow').first().attr('id');
	}
	
	if (typeof(to) != 'number' && !to) {
		to = 1;
	}
	
	current = jQuery('#'+id).find('.image:visible');
	
	if (current.index() != to) {
		// Clear the interval on this slideshow
		window.clearInterval( intervals_imageSlideShow[ id ] );
		
		// Set the target index
		jQuery('#'+id).attr('to', to);
		
		// Go there
		_image_slideshow_next(id);
	} else {
		jQuery('#'+id).removeAttr('to');
	}
}

var intervals_imageSlideShow = new Object();

jQuery('.feature_image_slideshow').each(function(index) {
	jQuery(this).find('.image').css('left', jQuery(this).width()+'px').hide();
	jQuery(this).find('.image').first().css('left', '0px').show();
	
	for (x=0; x<jQuery(this).find('.image').size(); x++) {
		jQuery(this).find('.controlls').append('<span title="Go to slide #'+(x+1)+'"></span>');
	}
	
	jQuery(this).find('.controlls').append('<div class="arrow left"></div><div class="arrow right"></div>');
	
	jQuery(this).find('.controlls span').first().addClass('on');
	intervals_imageSlideShow[ jQuery(this).attr('id') ] = window.setInterval("_image_slideshow_next('"+jQuery(this).attr('id')+"')", 6000);
	
	if (index == (jQuery('.feature_image_slideshow').size() - 1)) {
		if (typeof(featureLoaded_iss) == 'function') {
			featureLoaded_iss();
		}
	}
});

jQuery('.feature_image_slideshow .controlls span').click(function() {
	image_slideshow_to( jQuery(this).parents('.feature_image_slideshow:first').attr('id'), jQuery(this).index() );
});


jQuery('.feature_flash').each(function(index) {
	if (jQuery(this).find('div:first').size() > 0 && jQuery(this).find('div:first').attr('swf') != '') {
		obj = jQuery(this).find('div:first');
	} else if (jQuery(this).attr('swf') != '') {
		obj = jQuery(this);
	} else {
		obj = false;
	}
	
	if (obj) {
		swfobject.embedSWF(
			obj.attr('swf'),
			obj.attr('id'),
			obj.css('width').replace('px',''),
			obj.css('height').replace('px',''),
			"9",
			jQuery('#global_var_stylesheet_directory').val()+'/swf/expressInstall.swf',
			{},
			{wmode: 'opaque'},
			{}
		);
		
		if (index == (jQuery('.feature_flash').size() - 1)){
			if (typeof(featureLoaded_f) == 'function') {
				featureLoaded_f();
			}
		}
	}
});

/* cforms additions */

// validate email regex
function validateEmail(email) { 
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return email.match(re) 
}
								
function cform_openFeedback(message, iserror) {
	// create a new DOM element with a particular ID
	var cl = (iserror) ? "error" : "";
	$('body').prepend("\
		<div id='instant-lightbox' class='cforms " + cl + "'>\
			<div id='instant-lightbox-background'></div>\
			<div id='instant-lightbox-content-container'>\
				<div id='instant-lightbox-content'>\
					<div id='instant-lightbox-message' class='cform_message'>\
						<div id='instant-lightbox-status'></div>\
						<div id='instant-lightbox-copy' class='cufon'>"+message+"</div>\
					</div>\
					<div id='instant-lightbox-close' class='close' title='Close'></div>\
				</div>\
			</div>\
		</div>\
	");
		
	
	// add the ability to close it
	$('#instant-lightbox-background, #instant-lightbox-close').live('click', function() {
		$('#instant-lightbox').remove();
	});

	Cufon.replace('#instant-lightbox-copy h3', {fontFamily: 'HelveticaNeue CondensedBlack'});
	Cufon.replace('#instant-lightbox-copy p', {fontFamily: 'HelveticaNeue CondensedBold'});
	Cufon.refresh();
	return false;
}


if($('#cforms5form')){
	// hijack the 'submit' button click event to validate 'ask thad' form
	jQuery('#sendbutton5').live('click',function(e){
		var errors = [];
	    $('#cforms5form').find('.fldrequired').each(function(){
	    	var m = $(this);
	        if(m.val() == ''){
	        	errors.push(true);
	            m.addClass('cf_error');
			} else {
	        	m.removeClass('cf_error');
			}
		});
	            	
	    if (errors.length > 0){
	    	cform_openFeedback(unescape($('#cf_failure5').val()),true);
	        e.preventDefault();
		}
	            	
	});
	   
	// on document load, look to see if cforms has any messages available to show the user
	$(document).ready(function(){
		var m = $('#ask_thad').find('#usermessage5a');
		var h = m.html();
		if (h != "" && h != null){
			m.css('display','none');
			if(m.hasClass('failure')){
				cform_openFeedback(unescape(h),true);
			} else {
				cform_openFeedback(unescape(h),false);
			}
		}
	});
}
	
// hijack the 'go' button click event to add proper email validation
if($('#cforms2form')){
	jQuery('.email_signup .sendbutton').val('GO').attr('title', 'GO').live('click',function(e){
		if( !validateEmail( jQuery('#cf2_field_2').val() ) ){
	    	// show lightbox error valid email address from cform data
			cform_openFeedback('<h3 class="headline">'+unescape($('#cf_failure2').val())+'</h3>',true);
	    	e.preventDefault();
	        return false;
		}
	});
   
   
	// on document load, look to see if cforms has any messages available to show the user
	$(document).ready(function(){
		var m = $('.email_signup').find('#usermessage2a');
		var h = m.html();
		if (h != "" && h != null){
			m.css('display','none');
			if (m.hasClass('failure')){
				cform_openFeedback(unescape(h),true);
			} else {
				cform_openFeedback(unescape(h),false);
			}
		}
	});
}
