// preload image
pic1 = new Image(116,15); 
pic1.src="/images/client_login_w.gif";

function upDn(ud) {
	if (ud == 'down') {
		Effect.BlindDown('login_box', {duration: .5});
		$('login_label').update('<a href="#" onclick="upDn(\'up\'); return false;"><h2 id="clientlogin_header_w">Client Login</h2></a>');
	} else if (ud == 'up') {
		Effect.BlindUp('login_box', {duration: .5});
		$('login_label').update('<a href="#" onclick="upDn(\'down\'); return false;"><h2 id="clientlogin_header">Client Login</h2></a>');
	}
}

function wupDn() {
	if (document.vals.wud.value == 'down') {
		document.vals.wud.value = 'up';
		Effect.BlindDown('sub-work', {duration: .5});
	} else if (document.vals.wud.value == 'up') {
		document.vals.wud.value = 'down';
		Effect.BlindUp('sub-work', {duration: .5});
	}
}

document.observe("dom:loaded", function() {
	
	if ($('BigBox')) {
		if ($('BigBox').getHeight() < $('ScrollBox').getHeight()) {
			$('downarrow', 'uparrow', 'content_track').invoke('hide');
		}	
	}
		
	// THIS hides the process and shows the video
	if ($('video_link')) {
			$('video_link').observe('click', function(event){
				$('work_teaser').show();
				$('ScrollBox').hide();
				$('downarrow', 'uparrow').invoke('hide');
			});
		}
		
		$('uparrow').observe('click', function(event){
			var handtop = parseInt($('content_handle').getStyle('top').substr(0,($('content_handle').getStyle('top').length - 2)));
			var divtop = parseInt($('BigBox').getStyle('top').substr(0,($('BigBox').getStyle('top').length - 2)));
			var divheight = $('BigBox').getHeight();
			var listrange = divheight - 380;
			var handtarget = handtop - 38;
			
			var listtarget = divtop + Math.ceil(listrange / 10);
			
			if (handtarget <= 0) {
				$('content_handle').setStyle({ 'top' : '0px' });
				$('BigBox').setStyle({ 'top' : '0px' });
			} else {
				$('content_handle').setStyle({ 'top' : handtarget + 'px' });
				$('BigBox').setStyle({ 'top' : listtarget + 'px' });
				//alert(handtarget);
			}
		});
			
		$('downarrow').observe('click', function(event){
			var handtop = parseInt($('content_handle').getStyle('top').substr(0,($('content_handle').getStyle('top').length - 2)));
			var divtop = parseInt($('BigBox').getStyle('top').substr(0,($('BigBox').getStyle('top').length - 2)));
			var listheight = parseInt($('BigBox').getHeight());
			//var steps = Math.ceil(divheight / 100);
			//var divheight = steps * 100;
			//var divtarget = 380 - divheight;

			var listrange = listheight - 380;
			listgoal = - listrange;
			var handtarget = handtop + 38;
			
			var listtarget = divtop - Math.ceil(listrange / 10);

			if (handtarget >= 316) {
				$('content_handle').setStyle({ 'top' : '316px' });
				$('BigBox').setStyle({ 'top' : listgoal + 'px' });
			} else {
				$('content_handle').setStyle({ 'top' : handtarget + 'px' });
				$('BigBox').setStyle({ 'top' : listtarget + 'px' });
				//alert(handtarget);
			}
			
			// if it's short, keep it at 0
			/*if (divheight < 380) {		
							$('BigBox').setStyle({ 'top' : '0px' });	
						} else {
							if ((divtop - 100) > divtarget) {
								new Effect.MoveBy('BigBox', -100, 0, {duration: 0.4,  transition: Effect.Transitions.sinoidal});
							} else {
								$('BigBox').setStyle({ 'top' : divtarget + 'px' });
							}
						}*/
		});
});



function navup() {
	var handtop = parseInt($('work_handle').getStyle('top').substr(0,($('work_handle').getStyle('top').length - 2)));
	var listtop = parseInt($('work_list').getStyle('top').substr(0,($('work_list').getStyle('top').length - 2)));
	var listheight = parseInt($('work_list').getHeight());
	var listrange = listheight - 246;
	var handtarget = handtop - 20;

	var listtarget = listtop + Math.ceil(listrange / 10);

	if (handtarget <= 0) {
		$('work_handle').setStyle({ 'top' : '0px' });
		$('work_list').setStyle({ 'top' : '0px' });
	} else {
		$('work_handle').setStyle({ 'top' : handtarget + 'px' });
		$('work_list').setStyle({ 'top' : listtarget + 'px' });
		//alert(handtarget);
	}
}

function navdown() {
	var handtop = parseInt($('work_handle').getStyle('top').substr(0,($('work_handle').getStyle('top').length - 2)));
	var listtop = parseInt($('work_list').getStyle('top').substr(0,($('work_list').getStyle('top').length - 2)));
	var listheight = parseInt($('work_list').getHeight());
	var listrange = listheight - 246;
	listgoal = - listrange;
	var handtarget = handtop + 20;

	var listtarget = listtop - Math.ceil(listrange / 10);

	if (handtarget >= 190) {
		$('work_handle').setStyle({ 'top' : '190px' });
		$('work_list').setStyle({ 'top' : listgoal + 'px' });
	} else {
		$('work_handle').setStyle({ 'top' : handtarget + 'px' });
		$('work_list').setStyle({ 'top' : listtarget + 'px' });
		//alert(handtarget);
	}
}

function slideScroll(y,slider) {
	var divtop = parseInt($('work_list').getStyle('top').substr(0,($('work_list').getStyle('top').length - 2)));
	var divheight = parseInt($('work_list').getHeight());
	var divmin = 246 - divheight;
	var divtarget = (divmin * y) + 'px';
	$('work_list').setStyle({ 'top' : divtarget });	
}

function contentScroll(y,slider) {
	var divtop = parseInt($('BigBox').getStyle('top').substr(0,($('BigBox').getStyle('top').length - 2)));
	var divheight = parseInt($('BigBox').getHeight());
	var divmin = 380 - divheight;
	var divtarget = (divmin * y) + 'px';
	$('BigBox').setStyle({ 'top' : divtarget });	
}


// THESE ARE SHARED! DO NOT EDIT.
function arrowright() {
	var ctop = parseInt($('work_container').getStyle('top').substr(0,($('work_container').getStyle('top').length - 2)));
	if (ctop <= -100) {
		new Effect.MoveBy('work_container', 100, 0, { duration: 0.4, transition: Effect.Transitions.sinoidal });	
	}
}

function arrowleft() {
	new Effect.MoveBy('work_container', -100, 0, { duration: 0.4, transition: Effect.Transitions.sinoidal });	
}

