function menuFloater(obj) {
	if (menuFloaterTimeout) 
		clearTimeout(menuFloaterTimeout);
	var new_l = $(obj).offset().left+3;
	var new_w = $(obj).width()+22;
	var mf_l = $(mf).offset().left;
	var mf_w = $(mf).width();
	
	$('#menu a.selected').removeClass('selected');

	if (mf_l==0) {
		$(obj).addClass('selected');
	}
	if (new_l > mf_l) {
		$(mf)
		.stop(true)
		.animate({'width' : new_w, 'left' : new_l},200,'',function(){$(obj).addClass('selected');});
	} else {
		$(mf)
		.stop(true)
		.animate({'left' : new_l, 'width' : new_w},200,'',function(){$(obj).addClass('selected');});
	}

}

	var scroll = document.getElementById('scroll'), 
	customers = document.getElementById('customers'),
	current = document.getElementById('menuCurrent'),
	menuFloaterTimeout = null,
	mf = document.getElementById('menuFloater'),
	customersSpeed = 1,
    customersHover = false,
	customersManual = 0,
	customersViewport,
	customersWidth = 0;



$(document).ready(function () {

    var backgroundHeight = $('div',scroll).height();
	
	
	

	scroll.scrollTop = backgroundHeight;
	
	setInterval(function () {
		scroll.scrollTop -= 5;
		if (scroll.scrollTop==0) {
			scroll.scrollTop = backgroundHeight;
		}
		
	}, 70); 
	
	
	
	
	
	$('#customers').hover(function() {
			customersHover = true;
		},
		function() {
			customersHover = false;
		}
	);
	$('#customersLeft, #customersRight').click(function(e) {
		e.preventDefault();
		return false;
	});
	$('#customersLeft').hover(function() {
		customersManual = -5;
		customersSpeed = -1;
		},
		function() {
		customersManual = 0;
		}
	);

	$('#customersRight').hover(function() {
		customersManual = 5;
		customersSpeed = 1;
		},
		function() {
		customersManual = 0;
		}
	);



   
	
    $('#menu a').hover(
		function() {
			
			menuFloater(this);

		}
		,function(){
			if (current == undefined)
				menuFloaterTimeout=setTimeout("$(mf).hide();$('#menu a.selected').removeClass('selected');",500);
			else
				menuFloaterTimeout=setTimeout("menuFloater(current);$('#menu a.selected').removeClass('selected');",500);
			
			}
	);
	
	$('#menu a').each(function() {
		o = $(this).outerWidth();
		m = $(this).outerWidth() - $(this).width();
		w = o + (Math.ceil($(this).text().length/7)-1)*24-m;
		$(this).width(w);
	});
	
	if (current) {
		$(mf).css({'left' : $(current).offset().left+3,'width' : $(current).width()+22, 'display' : 'block'} );
		$(current).addClass('selected');
	} else
		$(mf).css({'left' : $('#menu a:first').offset().left,'width' : $('#menu a:first').width()+22,'display' : 'none'} );
	$(mf).css({'top' : $('#menu').offset().top});

	$('.portfolio_list .list .image, .portfolio_list .list_even .image').hover(
	  function() {
	  	$(this).parent().find('.description').show().stop().fadeTo('fast',1);
	  },
	  function() {
	  	    $(this).parent().find('.description').stop().fadeTo('fast',0,function() {$(this).hide();});
	  }
	);

	
	$('#portfolio_slideshow').cycle({
		fx: 'fade',
		timeout: 1000
	});
  
$('#EmailFormAdd').click(function(e){
	  e.preventDefault();
	  var fieldsets = $('#people fieldset.person:hidden');
	  fieldsets.eq(0).fadeIn('normal');
	  
	  if (fieldsets.length <= 1)
		$(this).fadeOut('slow');
	 
	  if (fieldsets.length >= 9 )
		$('#EmailFormDelete').fadeIn('slow');
	  
	  return false;
	});

	$('#EmailFormDelete').click(function(e){
	  e.preventDefault();
	  $('#people fieldset.person:visible:last').fadeOut('normal',function(){
		$(this).find('input').each(function(){
		  $(this).val('');
		})
		var fieldsets = $('#people fieldset.person:visible');
		if (fieldsets.length <= 1)
		  $('#EmailFormDelete').fadeOut('slow');
		if (fieldsets.length >= 9)
		  $('#EmailFormAdd').fadeIn('slow');

	  });
	  return false;
	}).fadeOut('fast');

	$('#people fieldset.person').each(function() {
	  if ($(this).find('input[value!=]').val()) {
		$(this).fadeIn('normal');
		$('#EmailFormDelete').fadeIn('normal');
	  }
	});

	$('#EmailForm input, #EmailForm textarea, #EmailForm select')
		.bind('focus',function() {
			$(this).parent().addClass('selected');
		})
		.bind('blur',function() {
			$(this).parent().removeClass('selected');
		});

	
});

$(window).load(function() {
	var allCustomers = $('li',customers),
	customersViewport = $(customers).width();
	
	for (i=0;i<allCustomers.length;i++)
		customersWidth += $(allCustomers[i]).outerWidth();
	
	setInterval(function () {
		if (customersManual !== 0) {
			if (customers.scrollLeft < customersWidth - customersViewport)
				customers.scrollLeft += customersManual;
			return false;
		}
			
		if (customersHover) return;
		customers.scrollLeft += customersSpeed;
		
		if ((customers.scrollLeft==0) || (customers.scrollLeft >= customersWidth - customersViewport)) {
			customersSpeed *= -1;
		}
	}, 50); 

});



