$(function() {
  
  	$('a[href*=#]:not(a[href=#])').click(function() {
          if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
          && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target
            || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
              var targetOffset = $target.offset().top;
			  
			  var topoffset = $('.nav').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);
			  }
			  $('#jquery-lightbox').remove();$('#jquery-overlay').fadeOut(function(){$('#jquery-overlay').remove();});$('embed, object, select').css({'visibility':'visible'});
              $('html,body')
              .animate({scrollTop: targetOffset}, dist);
			  
             return false;
            }
          }
        });
    
	
		$('#launch1').bind('click', function(){
				var array = [
							 ['images/commercial/elizabethdev.jpg','COMMERCIAL - The Elizabeth Jane Office Development'],
							 ['images/commercial/gatewaydev.jpg','COMMERCIAL - The Gateway Retail Development'],
							 ['images/commercial/racheldev.jpg','COMMERCIAL - The Rachel Anne Business Centre'],
							 ['images/commercial/regattadev.jpg','COMMERCIAL - The Regatta Office Development'],
							 ['images/commercial/sailsdev.jpg','COMMERCIAL - The Sails Office Development'],
							 ['images/commercial/sailsdev2.jpg','COMMERCIAL - The Sails Office Development'],
							 ['images/commercial/tulskdev.jpg','COMMERCIAL - The Tulsk Business Park'],
							 ['images/commercial/tulskdev2.jpg','COMMERCIAL - The Tulsk Business Park'],
							 ['images/commercial/wavedev.jpg','COMMERCIAL - The Wave Office Development Leeds'],
							 ['images/commercial/wavedev2.jpg','COMMERCIAL - The Wave Office Development Leeds']
							]
		dynamicLightBoxinit(array);return false;});
		
		
	
	
		$('#launch2, .projectstab').bind('click', function(){
				var array = [
							 ['images/residential/banksidehouse.jpg','RESIDENTIAL - Bankside House'],
							 ['images/residential/bridgeside.jpg','RESIDENTIAL - Bridgeside Apartments'],
							 ['images/residential/skyhouse.jpg','RESIDENTIAL - Sky House'],
							 ['images/residential/thomashouse.jpg','RESIDENTIAL - Thomas House'],
							 ['images/residential/glenfarnehouse.jpg','RESIDENTIAL - Glenfarne House'],
							 ['images/residential/kellyhouse.jpg','RESIDENTIAL - Kelly House'],
							 ['images/residential/lakehouse.jpg','RESIDENTIAL - Lake House'],
							 ['images/residential/lakehousenight.jpg','RESIDENTIAL - Lake House at Night'],
							 ['images/residential/lesliehouse.jpg','RESIDENTIAL - Leslie House'],
							 ['images/residential/meadowhouse.jpg','RESIDENTIAL - Meadow House'],
							 ['images/residential/swalehouse.jpg','RESIDENTIAL - Swale House'],
							 ['images/residential/thomashouse.jpg','RESIDENTIAL - Thomas House'],
							 ['images/residential/thomashousenight.jpg','RESIDENTIAL - Thomas House at Night'],
							 ['images/residential/francishouse.jpg','RESIDENTIAL - Francis House']
							]
		dynamicLightBoxinit(array);return false;});
		
		
		$('#launch3').bind('click', function(){
				var array = [
							 ['images/leisure/spiral.jpg','LEISURE - The Spiral Museum'],
							 ['images/leisure/green.jpg','LEISURE - The Green Acres Sports Club']
							]
		dynamicLightBoxinit(array);return false;});
	
	

	
	
	
});

function dynamicLightBoxinit(array){
	$('#jquery-lightbox, #jquery-overlay').remove();$('embed, object, select').css({'visibility':'visible'});
        images = array;
        var imageBuilder='';
        for (var i = 0; i  < images.length; i++)  {

                imageBuilder += '<a href="'+images[i][0]+'" title="'+images[i][1]+'"><img src="';
                imageBuilder += images[i];
                imageBuilder += '" \></a>';
          }

          var lb = $(imageBuilder);
          lb.lightBox({containerBorderSize:13, fixedNavigation:true});
          lb.filter('a:first').click();
		  
};
