window.addEvent('domready', function() 
{
	/* AJAXIFY NAVIGATION
	 **/

	try 
	{ 
		$$('li.update').addEvent('click', function(e) 
		{
			e.stop();
			var children = this.getChildren('a.update');
			$$('li.update').removeClass('active');
			$$('div.contenttarget').setStyle('display','none');
			$(this.id +'content').setStyle('display','block');
			this.addClass('active');
			if (isIE) { fixPngsForIE($(this.id+'content')); }
		});	
		$$('a.inlineupdate').addEvent('click', function(e) 
		{
			e.stop();
			$$('li.update').removeClass('active');
			$$('div.contenttarget').setStyle('display','none');
			$((this.id).slice(6)+'content').setStyle('display','block');
			$((this.id).slice(6)).addClass('active');
			if (isIE) { fixPngsForIE($((this.id).slice(6) +'content')); }
		});	
	}
	catch(err)	{	/* Do nothing */ }

	/* AJAXIFY CONTACT FORM
 	 **/

	try 
	{ 
		$('contactForm').addEvent('submit', function(e) {
			e.stop();
			var log = $('response-output').empty();
			log.setStyle('display','block');
			this.set('send', {onComplete: function(response) { 
				log.set('html', response);
			}});
			this.send();
		});	
	}
	catch(err)	{	/* Do nothing */ }
	
	/* RANDOMLY SELECT BUMP
	 **/

	try { 		$('bumpandroll').innerHTML = makeBump(); }
	catch(err)	{	/* Do nothing */ }

	/* CAPTURE HASH FOR LINKING
 	 ***/

	if (location.hash != '') 
	{
		var slug = (location.hash).substr(1);
		try
		{
			$$('li.update').removeClass('active');
			$$('div.contenttarget').setStyle('display','none');
			$(slug +'content').setStyle('display','block');
			$(slug).addClass('active');
			scroll(0,0);
		}
		catch (err) { /* Do nothing */ }
	}

	/* INSERT TOP AND BOTTOM TO VERTICAL LIST IN IE 
	 **/

	if ($('rightcol'))
	{
		if (isIE()) 
		{
			var children = $('leftcol').getChildren('ul');
			if (!children[0].hasChild('toprow'))
			{
				var topRow = new Element('li', { id: 'toprow' });
				var bottomRow = new Element('li', { id: 'bottomrow' });
				topRow.inject(children[0],'top');
				bottomRow.inject(children[0],'bottom');
			}
		}
	}

	/* EXPAND ADDRESS FORM WHEN ADDITIONAL LIT CHECKBOX IS TICKED
	 **/

	if ($('requestlit'))
	{
		$('sendlit').setProperty('checked', false);
		$('sendlit').addEvent('click', function()
		{
			if ($('sendlit').getProperty('checked')) 
			{
				$('addressform').setStyle('display','block');
			}
			else
			{
				$('addressform').setStyle('display','none');
			}
		});
	}

});

function isIE()	{	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent); }

function makeBump()
{
	var bumps = new Array();
	bumps[0] = "<div class=\"bumpandroll\"><h2 class=\"bump\">\"Using VisionWorks, our finance staff has decreased the time to completion by over 40 percent.\"</h2><div class=\"roll\">&mdash; <a href=\"http://www.vision-works.com/stories/#christine\">Read Christine&#8217;s Story</a></div></div>";
	bumps[1] = "<div class=\"bumpandroll\"><h2 class=\"bump\">\"VisionWorks has reduced our Accounts Receivables by 50% in the first 12 months.\"</h2><div class=\"roll\">&mdash; <a href=\"http://www.vision-works.com/stories/#diana\">Read Diana&#8217;s Story</a></div></div>";
	bumps[2] = "<div class=\"bumpandroll\"><h2 class=\"bump\">\"VisionWorks understands of the human service industry; their software is friendly and intuitive.\"</h2><div class=\"roll\">&mdash; <a href=\"http://www.vision-works.com/stories/#tom\">Read Tom&#8217;s Story</a></div></div>";
	bumps[3] = "<div class=\"bumpandroll\"><h2 class=\"bump\">\"Our VisionWorks system has truly assisted us in improving our operational processes and service outcomes.\"</h2><div class=\"roll\">&mdash; <a href=\"http://www.vision-works.com/stories/#renee\">Read Renee&#8217;s Story</a></div></div>";
	var randomnumber = Math.floor(Math.random()*4);
	return bumps[randomnumber];
}

function fixPngsForIE(parentEl)
{
	if ($('rightcol'))
	{
		parentEl.getElements('img')[0].setStyle('height','260px');
		parentEl.getElements('img')[0].setStyle('width','350px');
	}
	else if ($('toprow') && !$('story'))
	{
		parentEl.getElements('img')[0].setStyle('height','175px');
		parentEl.getElements('img')[0].setStyle('width','175px');
	}
}