	var stopScript = false;
	
	$(function() {
		/* html = '<div id="bgimage"><img src="/images/bg.jpg" /></div>';
		$('body').append(html);
		
		bgimage_width = $('#bgimage img').width();
		bgimage_height = $('#bgimage img').height();
		
		width_ratio = ($(window).width() / bgimage_width);
		height_ratio = ($(window).height() / bgimage_height);

		if(height_ratio > width_ratio) {
			h = $(window).height();
			w = Math.floor(height_ratio * bgimage_width);
			margin = {
				height: h,
				width: w,
				marginLeft: Math.floor( ($(window).width() - w) / 2 )
			}
		} else {
			w = $(window).width();
			h = Math.floor(width_ratio * bgimage_height);
			params = {
				height: h,
				width: w,
				marginTop: Math.floor( ($(window).height() - h) / 2 )
			}
		}
		
		$('#bgimage img').css(params); */
		
		$('#menu a').click(function() {
			for(var i=0;i<list.length;i++) {
				$(list[i]).find('img').stop();
			}
      stopScript = true;
			
			return true;
    });
		
		$('#superbgimage').superbgimage({
			reload: false,
			onShow: function() {
				if(typeof(imagesWhatWeDo) != "undefined")
					loadGallery(1000);
				$('#bgimage').css('display', 'none');
			}
		}).hide();
		centerWrapper();
		
		if(typeof(Shadowbox) != "undefined")
			Shadowbox.init();
			
		initLayerMovement();
		initScroller();
	});
	
	function centerWrapper() {
		marginTop = ($(window).height() - $('#wrapper').height()) / 2;
		marginLeft = ($(window).width() - $('#wrapper').width()) / 2;
		
		if(marginTop < 0)
			marginTop = 0;
		if(marginLeft < 0)
			marginLeft = 0;
			
		$('#wrapper')
			.css({'marginTop': marginTop, 'marginLeft': marginLeft})
			.show();
		setTimeout('centerWrapper()', 1000);
	}
	
	function loadGallery(speed) {
		list = $('#what-we-do ul li');
		
		slideSpeed=speed;
		imgPath = 'images/pages/what-we-do/';
		
		loadGalleryImages(0);
	}
	
	function loadGalleryImages(i) {
		if(stopScript)
			return;
	
		if(i<list.length) {
			var d = new Date;
			var unixtime_ms = d.getTime();
			var unixtime = parseInt(unixtime_ms / 1000);
			
			$("<img>")
					.attr('src', imgPath + imagesWhatWeDo[i] + '?' + unixtime)
					.load(function() {
						$(list[i])
							.find('div.image')
							.append($(this))
							.find('img')
							.animate({left:0}, slideSpeed);
						i++;
						loadGalleryImages(i);
					});
			
		}
	}
	
	function initLayerMovement() {
		var overlay = $("#wrapper-border");
		var light = $("#wrapper-light");
		var chair = $("#wrapper-chair");
		var shadow_left = $("#wrapper-shadow-left");
		var shadow_right = $("#wrapper-shadow-right");
		
		/* ORIGINAL POSITION */
		var light_position = light.position();
		var chair_position = chair.position();
		var shadow_left_position = shadow_left.position();
		var shadow_right_position = shadow_right.position();
		
		overlay.bind("mousemove", function(e){
			var x = e.pageX - $(this).offset().left;
			var center = overlay.width() / 2;
			var change = x - center;
			
			light.css({
				'left': function() {
					return Math.floor(light_position.left + (change / -10));
				}
			});
			
			shadow_left.css({
				'left': function() {
					return Math.floor(shadow_left_position.left + (change / 15));
				}
			});

		});
	}
	
	function initScroller() {
		var container = $('.profile-desc');
		var content = $('.profile-desc-container');
		var handle = $('.scroll-handle');
		
		var containerHeight = container.height();
		var contentHeight = content.height();
		var scrollerHandleHeight = handle.height();
		
		var scrollSpace = containerHeight - scrollerHandleHeight;
		var movementSpace = contentHeight - containerHeight;
		
		var moveScroll = false;
		var moveStart = 0;
		var scrollStart = 0;
		
		handle.mousedown(function(e) {
			moveScroll = true;
			moveStart = e.pageY - container.offset().top;
			scrollStart = handle.position().top;
			return false;
		})
		
		container.mouseup(function(e) {
			moveScroll = false;
			return false;
		});
		
		container.mousemove(function(e) {
			if(moveScroll) {
				var y = ((e.pageY - $(this).offset().top) - moveStart) + scrollStart;
				if(y < 0) {
					posTop = 0;
				} else if(y > scrollSpace) {
					posTop = scrollSpace;
				} else {
					posTop = y;
				}
				handle.css({'top': posTop});
				content.css({
					'margin-top' : function() {
						if(movementSpace > 0)
							return 0 - Math.floor((posTop / scrollSpace) * movementSpace);
						else
							return 0;
					}
				});
			}
		});
	}

