$(function() {
  function filterPath(string) {
  return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
  }
  var locationPath = filterPath(location.pathname);
  $('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
    if (  locationPath == thisPath
    && (location.hostname == this.hostname || !this.hostname)
    && this.hash.replace(/#/,'') ) {
      var $target = $(this.hash), target = this.hash;
      if (target) {
        var targetOffset = $target.offset().top;
        
		$(this).click(function(event) {
          event.preventDefault();
		  var topoffset = $('.leftbar').offset().top;
		  if(topoffset>targetOffset){//below target
			  var dist = Math.round((topoffset-targetOffset)*3);
		  }else{//page is above target page is less than target
			  var dist = Math.round((targetOffset-topoffset)*3);
		  }
		 // alert('fromtop:'+topoffset+'  target:'+targetOffset+'  gives us:'+dist);
		 // return false;
          $('html, body').animate({scrollTop: targetOffset}, dist, function() {location.hash = target;});
        });
      }
    }
  });
	
	
	$(window).scroll(function () { 
		
		var topoffset = $('.leftbar').offset().top;
		var target1 = $('#intro').offset().top-10;
		var target2 = $('#pump').offset().top-10;
		var target3 = $('#tech').offset().top-10;
		
		if(topoffset >= target1 && topoffset < target2){
			$('#li1').addClass('on');
			$('#li2, #li3').removeClass('on');
		}else if(topoffset >= target2 && topoffset < target3){
			$('#li2').addClass('on');
			$('#li1, #li3').removeClass('on');
		}else if(topoffset >= target3){
			$('#li3').addClass('on');
			$('#li2, #li1').removeClass('on');
		};
		
		

		//$('.leftbar').append($('.leftbar').offset().top+"<br />"+$('#intro').offset().top+"<br><br>");
	
	})
	
	
	
	/*/BIND THE NAV!
	$('.navintro').bind('click', function(){
		$('#li1').addClass('on');
		$('#li2, #li3').removeClass('on');
	});
	$('.navpump').bind('click', function(){
		$('#li2').addClass('on');
		$('#li1, #li3').removeClass('on');
	});
	$('.navtech').bind('click', function(){
		$('#li3').addClass('on');
		$('#li1, #li2').removeClass('on');
	});*/
	
	
	
	$("#thepump").bind('mouseover mousemove', function(e){								 
		$('#tooltipcontent').html('Reveal Your <b>Aura</b>');
		setpos(e);
	}).bind('mouseout', function(){$('#tooltip').hide();});
	
	$("#pumpback").bind('mouseover mousemove', function(e){								 
		$('#tooltipcontent').html('Back to the top');
		setpos(e);
	}).bind('mouseout', function(){$('#tooltip').hide();});
	
	
	
	////////////////////////////
	//      Pump tooltips     //
	////////////////////////////
	//prime
	$("#pumpprime").bind('mouseover mousemove', function(e){								 
		$('#tooltipcontent').html('<b>PRIME</b> Hold down the PRIME button to rotate the roller manually and draw liquid into the tube before dosing. Simplifying dosing chemical container changeover and reducing downtime.');
		setpos(e);
	}).bind('mouseout', function(){$('#tooltip').hide();}).bind('click', function(){return false;});
	
	
	//Load Tube
	$("#pumpload").bind('mouseover mousemove', function(e){								 
		$('#tooltipcontent').html('<b>Easy Tube Load</b> Simply connect the tube and press the Tube Load button. The Verderflex Aura will do the rest. Pulling the tube round to the correct position. No need to struggle with connectors or positioning. Never need to touch any moving parts.');
		setpos(e);
	}).bind('mouseout', function(){$('#tooltip').hide();}).bind('click', function(){return false;});
	
	
	//LED
	$("#pumpled").bind('mouseover mousemove', function(e){								 
		$('#tooltipcontent').html('<b>LED Display</b> Shows at a glance if the Verderflex Aura is turned on, running or locked out.');
		setpos(e);
	}).bind('mouseout', function(){$('#tooltip').hide();}).bind('click', function(){return false;});
	
	
	//Dose
	$("#pumpdose").bind('mouseover mousemove', function(e){								 
		$('#tooltipcontent').html('<b>Timed Dosing</b> Control how long the Verderflex Aura will dose for - up to 20 minutes.');
		setpos(e);
	}).bind('mouseout', function(){$('#tooltip').hide();}).bind('click', function(){return false;});
	
	
	//Lock out
	$("#pumplock").bind('mouseover mousemove', function(e){								 
		$('#tooltipcontent').html('<b>Timed Lock Out</b> Eliminate overdosing by locking out the Verderflex Aura for up to 20 minutes after each dose cycle.');
		setpos(e);
	}).bind('mouseout', function(){$('#tooltip').hide();}).bind('click', function(){return false;});
	
	
	//Tamper Evident
	$("#pumptamper").bind('mouseover mousemove', function(e){								 
		$('#tooltipcontent').html('<b>Tamper Evident</b> Tamper evident plugs stop unwanted users changing the settings on the Verderflex Aura without being noticed, for added peace of mind.');
		setpos(e);
	}).bind('mouseout', function(){$('#tooltip').hide();}).bind('click', function(){return false;});
	
	
	
	
	////////////////////////////
	//    SPLIT THE IMAGE     //
	////////////////////////////
	$("#pumphoverbot").bind('mouseover', function(){
		$(this).hide();
		$('#pumpimage2').fadeOut();
		$('#pumphovertop').show();
		$('#pumpimage3').fadeIn();
	});
	
	
	$("#pumphovertop").bind('mouseover', function(){
		$(this).hide();
		$('#pumpimage3').fadeOut();
		$('#pumphoverbot').show();
		$('#pumpimage2').fadeIn();
	});
	
	
	
	//start the slideshow
	$('.pumppumprightside a').lightBox();
	
	
	$('.lifestyles').cycle('fade');
	
	
});


function setpos(e){
	var tooltip = $('#tooltip');
	var xoffset = Math.round(tooltip.width()/2);
	var yoffset = tooltip.height() + 40;
	tooltip.css({top:(e.pageY - yoffset)+"px",left:(e.pageX - xoffset)+"px"}).show();
}




/*


function showtooltip(e, innerhtml){
	
	
	
	$("#tooltip").remove();

	
	//<div id="tooltip"><div class="top">' + innerhtml + '</div><div class="base"></div></div>
	$("#").append('<div id="tooltip"><div class="top">' + innerhtml + '</div><div class="base"></div></div>');
	//$("body").append('<hr class="here" /><hr />'+ innerhtml);
	
	var hovereditem = $('#thepump');
	var tooltip = $('#tooltip');
	var tooltiphover = $('#tooltip, #thepump');
	var topper = $('.top');
	
	
	var xoffset = Math.round(tooltip.width()/2);
	var yoffset = tooltip.height() + 30;
	
	tooltip.css({top:(e.pageY - yoffset)+"px",left:(e.pageX - xoffset)+"px"}).show();
	
	tooltiphover.bind('mousemove', function(e){
		tooltip.css({top:(e.pageY - yoffset)+"px",left:(e.pageX - xoffset)+"px"});	 
	});
	
	tooltip.bind('mouseout', function(e){
	
		hovereditem.bind('mouseout', function(e){
			tooltip.remove();
		});
	});
};



$(function() {
  
  $('a[href*=#]').each(function() {
    	
		var targetOffset = $(this.hash).offset().top;
        $(this).click(function(event) {
          $('html, body').animate({scrollTop: targetOffset}, 'slow');
		  return false;
		});
	});
});
*/
