<!--

document.observe( 'dom:loaded', openYourIris );

var Iris =
{
	Form :
	{
		getParentForm : function( dom_node )
		{
			//Bubble up until we find the form that contains the input that raised the event
			o_dom_node = Element.extend( dom_node );

			if ( o_dom_node.tagName == 'FORM' )
			{
				return o_dom_node;
			}

			o_form_elem = null;
			o_dom_node.ancestors().each( function( elem_iterator )
			{
				if ( elem_iterator.tagName == 'FORM' )
				{
					//we found the form!
					o_form_elem = elem_iterator;
					throw $break; // Pretend this is a "break"
				}
			} );

			return o_form_elem;
		}
	}
}

function focusLogin()
{
	o_email = $('email_try');
	if ( ! o_email )
	{
		o_email = $('email');
	}

	if ( o_email )
	{
		o_email.focus();
		o_email.select();
	}
}

function openYourIris( event )
{
	initGA();

	if ($('groupon_event_date')) {
		Event.observe(
			'groupon_event_date',
			'change',
			function(e) {
				var groupon_event_date = $('groupon_event_date');
				var classes = $F(groupon_event_date).split(',');
				$('00N40000001dgHO').value = classes[0];
				$('00N40000001dgHY').value = classes[1] ? classes[1] : '';
			}
		);
	}
}

iris_watch_domains = new Array
(
	/^https?\:\/\/([\w\-]+\.)*irisreading\.com/,
	/^https?\:\/\/([\w\-]+\.)*speedreadingblogger\.com/
);

function initGA()
{

	// Determine if document.location.href matches one of the domains above
	current_domain = -1;
	for ( var i=0; i < iris_watch_domains.length; i++ )
	{
		if ( document.location.href.match( iris_watch_domains[ i ] ) )
		{
			current_domain = i;
		}
	}

	// For each link on the page, add some GA JS if the domain is different from the current one
	$$('a').each( function( elem_iterator )
	{
		for ( var i=0; i < iris_watch_domains.length; i++ )
		{
			if ( i != current_domain && elem_iterator.href.match( iris_watch_domains[ i ] ) )
			{
				elem_iterator.observe( 'click', switchDomainGA );
			}	
		}
	} );
}

function switchDomainGA( event )
{
	element = event.element();
	a_element = null;
	if ( element.tagName == 'A' )
	{
		a_element = element;
	}
	else
	{
		element.ancestors().each( function( elem_iterator )
		{
			if ( elem_iterator.tagName == 'A' )
			{
				a_element = elem_iterator;
				throw $break; // Pretend this is a "break"
			}
		} );
	}

	if ( a_element )
	{
		__utmLinker(a_element.href);
		event.stop();
		return false;
	}
}

//-->
