

function menuFloater(obj) {

 if (menuFloaterTimeout) 
   clearTimeout(menuFloaterTimeout);
   
	 var new_l = $(obj).position().left+10;
	  var new_w = $(obj).width()+16;
	  var mf_l = $('#menu_floater').position().left;
	  var mf_w = $('#menu_floater').width();
	  if (new_l > mf_l) {
	    $('#menu_floater')
	      .stop(true)
	      .animate({'width' : new_w, 'left' : new_l},{duration:400});
	  } else {
	    $('#menu_floater')
	      .stop(true)
	     .animate({'left' : new_l, 'width' : new_w},{duration:400});
	  }
}



var menuFloaterTimeout = null;
	var customers_scroll_stop = false;
	var intval = 2600;
	var customers_scroll_current = 0;
	var excitems = 4;
	var autostart = null;
	function restart_customers() {
		$("#customers_scroll").stop().trigger("start"); 
		customers_scroll_stop = false;
	}

$(document).ready(function(){
    current = $('#menu_current').get(0);
    
      if (current)
	$('#menu_floater').css({'left' : $('#menu_current').position().left+10,'width' : $('#menu_current').width()+16, 'display' : 'block'} );
      else
	$('#menu_floater').css({'left' : $('#menu a:first').position().left+10,'width' : $('#menu a:first').width()+16} );
	
      $('#menu a').hover(
	function() {
	    
	   
	    menuFloater(this);
	  }
      ,function(){
	if (current == undefined)
	  menuFloaterTimeout=setTimeout("$('#menu_floater').hide();",500);
	else
	  menuFloaterTimeout=setTimeout("menuFloater(current);",500);

      });
      

	$("#customers_scroll").serialScroll({
		items:'li',
		duration: intval,
		constant:false,
		interval:1,
		cycle:true,
		force:true,
		step:1,
		easing:'linear',
		cycle:true,
		exclude:excitems,
		constant:true,
		onBefore : function( e, elem, $pane, $items, pos ) {
		  
		  if (customers_scroll_stop == true) {
		  
		    if (customers_scroll_current == $items.length - 1 - excitems && pos == 0)
		      return false;
		    if (customers_scroll_current == 0 && pos == $items.length - 5)
		      return false;

		  }
		  customers_scroll_current = pos;
		}
	});
	

	
	$('#customers_scroll').hover(function(){
		$(this).trigger('stop').stop();
	},function(){
		if (customers_scroll_stop == false) $(this).trigger('start');
	});

	
	$('#customers .scroll_left').click(
	  function(){
	    clearTimeout(autostart);
	    customers_scroll_stop = true;
	    $('#customers_scroll').stop().trigger('stop').trigger('prev');
		autostart=setTimeout('restart_customers()',5000);
	  }
	);

	$('#customers .scroll_right').click(
	  function(){
	  	clearTimeout(autostart);
	    customers_scroll_stop = true;
 	    $('#customers_scroll').stop().trigger('stop').trigger('next'); 
 	    autostart=setTimeout('restart_customers()',5000)
	  }
	);

	$("#portfolio_latest_scroll").serialScroll({
		items:'li',
		duration:1000,
		step:4,
		exclude:3,
		easing:'linear',
		cycle:false
	});
	
	$('#portfolio_latest .scroll_left').click(
	  function(){
	    $('#portfolio_latest_scroll').trigger('prev');
	  }	
	)

	$('#portfolio_latest .scroll_right').click(
	  function(){
	    $('#portfolio_latest_scroll').trigger('next');
	  }	
	)
	
	$('.portfolio_list .list .image').mouseover(
	  function() {
	    $(this).parent().next().css({'z-index' : 80});
	    $(this).parent().find('.description').css('display','block').stop().animate({left : '230px'})
	  }).mouseout(
	  function() {
	    
	    $(this).parent().find('.description').stop().animate({left : '0px'},'normal',
	    	function(){
	    		$(this).parent().next().css({'z-index' : 90});
	    		$(this).css('display','none')
	    	}
	   );
	    
	  }
	);
	
	$('.portfolio_list .list_even .image').mouseover(
	  function() {
	    $(this).parent().prev().css({'z-index' : 80});
	    $(this).parent().find('.description').css('display','block').stop().animate({left : '-240px'})
	  }).mouseout(
	  function() {
	    
	  	$(this).parent().find('.description').stop().animate({left : '0px'},'normal',
	    		function(){
	    			$(this).parent().prev().css({'z-index' : 90});
	    			$(this).css('display','none')
	    		}
	   	);
	    
	  }
	)
	
	$('#portfolio_slideshow').cycle({
		fx: 'fade',
		timeout: 1000,
		containerResize: true,
		height: 'auto'
		
		
	});
  

	$('#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');
	  }
	})



  

})

function fadeP(o) {
	$(o).fadeTo('normal',1);
}

$(window).load(
  function() {
  	if ($('.subpage #top .container_12').height() < 460) $('.subpage #top .container_12').height(460);
  	var pCounter = -1;
  	$('p,ul,td,h1,h2,h3,h4,h5,.date,.list,.list_even').each(function() {
  		$(this).css('opacity',0).delay(pCounter++ * 100).fadeTo(1000,1, function() {
  			if ($.browser.msie) $(this).css('opacity','');
  		});
  	})
  })
