		// JavaScript Document
$(document).ready(function(){
	//check for iPad
	if(isiPad()){
		//user is on an iPad. what to do what to do...
	}
	
	function isiPad(){
		return (navigator.platform.indexOf("iPad") != -1);
	}
	
	
	// what page is this?
	var page = $.url.attr('file');
	
	
	////////////////////////////////////////////////////////
	//                                                    //
	//   Client Side Includes                             //
	//                                                    //
	////////////////////////////////////////////////////////
	
	$.get('includes/header.html', function(data){
		$('#wrapper').before(data);
		$.get('includes/main_nav.html', function(data){
			$('#main-nav').after(data);
			$('html').css('display', 'block');
			
	////////////////////////////////////////////////////////
	//                                                    //
	//   VARIOUS STYLE AND ROUNDED CORNER SETTINGS        //
	//                                                    //
	////////////////////////////////////////////////////////
	
	$('#logo').click(function(){
		window.location.href = 'http://www.lundeng.com';
	});
	
	
	$('#main-nav').css('opacity', '0.5');
	if(!$.browser.msie){ //only for cool broswers
		$('#nav ul li a:first').corner('tl 5px');
		$('#main-nav').corner('tl tr 5px');
	}
	$('.subnavBG').corner('bl br 10px').css('opacity', '0.7');
	$('#homepage-contact').corner('tl bl');
	
	//IE fixes :/
	if($.browser.msie){
		$('#nav ul li a').css('padding-top','9px');
	}
	
	
	////////////////////////////////////////////////////////
	//                                                    //
	//   MAIN NAVIGATION CONTROL                          //
	//                                                    //
	////////////////////////////////////////////////////////
	
	var mainNav = $('#nav ul li a').get();
	
	//highlight current page
	$.each(mainNav, function(){
		var navLink = $(this).attr('href');
		if(page == navLink || page == 'projects.html'){
			if(page == navLink){
				$(this).css('background-color', '#181c27');
			} else{
				$('.trigger').css('background-color', '#181c27');
			}
		}
	});
	
	var height = 0;
	// create custom tooltip effect for jQuery Tooltip
	$.tools.tooltip.addEffect("dropdown",
		// opening animation
		function(done) {
			var trigger= this.getTrigger();
			trigger.css('background-color', '#202534');
			var tip = this.getTip();
			height = tip.height();
			tip.height(0);
			var value = '+=' + height;
			tip.show();
			tip.animate({height: value}, 500, 'easeOutExpo', done);
		},
	
		// closing animation
		function(done) {
			var trigger= this.getTrigger();
			trigger.css('background-color', '#333A4C');
			this.getTip().fadeOut(300);
		}
	);
	
	$(".trigger").tooltip({
		relative: true,
		position: "bottom center",
		effect: 'dropdown',
		predelay: 200,
		events: {def: 'click, mouseleave',tooltip: 'mouseenter, mouseleave click'}
	});
	
	///////////////////////////Main Nav click
	$('#nav ul li a').click(function(){
		
	});
	
	///////////////////////////subnav click
	var projectIsShowing = false;
	$('.subnav ul li').click(function(){
		if(page != 'projects.html' || projectIsShowing){
			projectIsShowing = false;
			var projCat = 'projects.html?pane=' + $(this).index();
			window.location.href = projCat;
		}else if (page == 'projects.html'){
			api.seekTo($(this).index(), 200);
		}
	});
	
	$('#projects-mainnav ul li').click(function(){
		api.seekTo($(this).index(), 1000);
	});
	
	/*if(page == 'index.html'){
		$.getScript('scripts/jquery.cycle.min.js', function() {
		   $('#homepage-gallery').cycle({
				fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			});
		});
	}*/


	
	////////////////////////////////////////////////////////
	//                                                    //
	//   PROJECTS PAGE                                    //
	//                                                    //
	////////////////////////////////////////////////////////
	
	
	
	if(page == 'projects.html'){
		
		//////////////////////////////////////////////////////////////////////////////BEGIN projNAV CONTROL
		
		$(".scrollable").scrollable({
			speed: 1000,
			easing: 'easeInOutQuint'
		});
		
		var api = $(".scrollable").data("scrollable");
		
		var selection = $.url.param('pane');
		if(selection){
			api.seekTo(selection, 0);
		}
		
		
		
		//image preloader function
		(function($) {
		  var cache = [];
		  $.preLoadImages = function() {
			var args_len = arguments.length;
			for (var i = args_len; i--;) {
			  var cacheImage = document.createElement('img');
			  cacheImage.src = arguments[i];
			  cache.push(cacheImage);
			}
		  }
		})(jQuery)
		
		
		var path = 'images/site_images/';
		$.preLoadImages(path + 'project-viewer-bg.png', path + 'project-default-image.png', path + 'staff_bg.jpg');
		
	
		
	
	
	//////////////////////////////////////////////////////////////////////////////END NAV CONTROL
	
	//////////////////////////////////////////////////////////////////////////////BEGIN OVERLAY CONTROL
	
	
	var contentHolder;
	
	$('.project-list ul li a').click(function(event){
		event.preventDefault();
		projectIsShowing = true;
		var selected = $(this).attr('href');
		contentHolder = $('#projects-container');
		contentHolder.fadeOut('fast', function(){
			$.get(selected, function(data){
				var content = $('#content-wrapper');
				content.fadeOut('fast', function(){
					content.append(data);
					$('#proj-thumb-scroll').scrollable({
						speed: 1000,
						easing: 'easeInOutExpo',
						next: '.proj-thumb-next',
						prev: '.proj-thumb-prev'
					});
					
					var projScrollApi = $("#proj-thumb-scroll").data("scrollable");
					var thumbsSize = projScrollApi.getSize();
					
					// Set to the number of visible items
					  var numThumbs = 5;
						
					//show nav if size is bigger than canvas
					if(projScrollApi.getSize() > numThumbs){
						$('.pnav-next, .pnav-prev').fadeIn();
					}
						
					  // Handle the Scrollable control's onSeek event
					  projScrollApi.onSeek(function(event, index) {
					
						// Check to see if we're at the end
						if (this.getIndex() >= this.getSize() - numThumbs) {
					
						  // Disable the Next link
						  jQuery("a.next").addClass("disabled");
					
						}
					
					  });
					
					  // Handle the Scrollable control's onBeforeSeek event
					  projScrollApi.onBeforeSeek(function(event, index) {
					
						// Check to see if we're at the end
						if (this.getIndex() >= this.getSize() - numThumbs) {
					
						  // Check to see if we're trying to move forward
						  if (index > this.getIndex()) {
					
							// Cancel navigation
							return false;
					
						  }
					
						}
					
					  });

					
					$('#proj-thumb-scroll img').click(function(){
						var thumbPath = $(this).attr('src');
						var parsed = thumbPath.split('/thumbs');
						var image = parsed[1];
						var imgUpdate = image.split('_thumb');
						var src = parsed[0] + imgUpdate[0] + imgUpdate[1];
						
						var curImage = $('img.project-viewer').attr('src');
						
						if(curImage != src){
							$('img.project-viewer').fadeOut('fast', function(){
								$(this).attr('src', src);
							}).load(function(){$(this).fadeIn();});
						}
					}).hover(function(){
						$(this).siblings().css('opacity', '0.8');
					}, function(){
						$(this).siblings().css('opacity', '1');
					});
					
					
					if(!$.browser.msie){
						$('#back-to-cat').corner('tr br 5px;');
					}
					$('#back-to-cat').hover(function(){
						$(this).css('opacity', '0.6');
					}, 
					function(){
						$(this).css('opacity', '0.4');
					});
					
				}).fadeIn('slow');
				$('#back-to-cat').live('click', function(){
					$('.project-content').fadeOut('fast', function(){
						$(this).remove();
						contentHolder.fadeIn('fast');
					});
				});
			});
		});
	});
	
	}
	
	
	
	
	if(page == 'staff.html'){
		
		$('.overlay').corner();
		var overlayAPI = $('.overlay').overlay({api:true, mask: {color: '#000', opacity: 0.7, loadSpeed: 0, closeSpeed: 0}, fixed: false, top: 20});
		
		$('#staff-list ul li').click(function(){
										  
			var selected = $(this).next();
			newHeight = selected.height() + 'px';
			overlayAPI.onBeforeLoad(function(){
				$('.overlay').empty();	
				selected.contents().clone().appendTo('.overlay');
			});
			
			overlayAPI.load();
		});
	}
	
	
	
    ////////////////////////////////////////////////////////
	//                                                    //
	//   end script                                       //
	//                                                    //
	////////////////////////////////////////////////////////
		
			
		});
	});
});
