// This file is automatically included by javascript_include_tag :defaults
window.addEvent('load', function() {
	init();
	idealsSlider = new Fx.Slide('ideals_submenu').hide();
    $('ideals_submenu').setStyle('display','block');
	projectsSlider = new Fx.Slide('projects_submenu').hide();
    $('projects_submenu').setStyle('display','block');
	if ($('project_details')) {
		slider = new Fx.Slide('projInfo',{duration: 1500}).hide();
		setTimeout('slider.slideIn();',200);
	}
	$('ideals').addEvents({
		'mouseenter': function(){
			idealsSlider.cancel();
			idealsSlider.slideIn();
		},
		'mouseleave': function(){
			idealsSlider.cancel();
			idealsSlider.slideOut();
		}
	});
	$('projects').addEvents({
		'mouseenter': function(){
			projectsSlider.cancel();
			projectsSlider.slideIn();
		},
		'mouseleave': function(){
			projectsSlider.cancel();
			projectsSlider.slideOut();
		}
	});
});

function popupImage(sURL) {
  window.open(sURL, "", "resizable=1, scrollbars=1,menubar=1,HEIGHT=400,WIDTH=400");
}

var clipTop = 8;
var clipWidth = 270;
var clipBottom = 224;
var topper = 14;
var lyrheight = 0;
var time,amount,theTime,theHeight,DHTML;
var up_disabled = true;
var down_disabled = false;

function init()
{
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	x = $('middleContent');
	if (document.layers)
	{
		lyrheight = x.style.clip.bottom;
		lyrheight += 20;
		x.style.clip.top = clipTop;
		x.style.clip.left = 0;
		x.style.clip.right = clipWidth;
		x.style.clip.bottom = clipBottom;
	}
	else if (document.getElementById || document.all)
	{
		setTimeout("lyrheight = x.offsetHeight;", 500);
		setTimeout(" if (lyrheight > clipBottom) $('scroll_down').src = '/images/down_arrow.gif';", 600)
		x.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0px)';
	}
}

function scrollayer(layername, amt, tim)
{
	if (!DHTML) return;
	thelayer = $(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll();
}

function realscroll()
{
	if (!DHTML) return;
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	if (clipTop < 0 )
	{
	    $('scroll_up').src = '/images/up_arrow_disabled.gif';
	    up_disabled = true;
		clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return;
	}
	if (clipBottom > lyrheight)
	{
	    $('scroll_down').src = '/images/down_arrow_disabled.gif';
	    down_disabled = true;
		clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return;
	}	
	if (document.getElementById || document.all)
	{
	    checkArrows();
		clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0px)';
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper + 'px';
	}
	else if (document.layers)
	{
	    checkArrows();
		thelayer.style.clip.top = clipTop;
		thelayer.style.clip.bottom = clipBottom;
		thelayer.style.top = topper;
	}
	time = setTimeout('realscroll()',theTime);
}

function checkArrows() {
  if (up_disabled) {
    $('scroll_up').src = '/images/up_arrow.gif';
    up_disabled = false;
  }
  if (down_disabled) {
    $('scroll_down').src = '/images/down_arrow.gif';
    down_disabled = false;
  }
}

function stopScroll() {
	if (time) clearTimeout(time);
}

function contactRequest(response) {
  if ( response == 'success' ) {
    $('contactForm').hide();
    $('thankYou').show();
  } else {
    $('contactForm').innerHTML = response;
    window.alert('The information you provided was not complete. Required fields are highlighted.');
  }
}
