$(document).ready(function($){
	
	//add browser checking to jitter overlap on css capable browsers.
	if (jQuery.browser.msie) {
		$(window).resize(function () { 
			var w = $(window).width() 
			if(w <= 991){
				//alert("smaller")
				$('#main').css('left', '187px')
				$('#main').css('margin-left' , '0')
			}
			if(w >= 991){
				//alert("smaller")
				$('#main').css('left', '-306px')
				$('#main').css('margin-left' , '50%')
			}
		});
	}
	
	$.supersized({
		// Functionality
		slide_interval          :   8000,
		transition              :   1, 
		transition_speed		:	700,
		min_width				: 	991,
		min_height				: 	700,
		fit_always				: 	0,
		random					: 	0,
		start_slide				: 	1,
		image_protect			: 	0,
		performance				: 	1, 
		horizontal_center		: 	1,

		// Components							
		slide_links				:	'blank',	// Individual links for each slide (Options: false, 'num', 'name', 'blank')
		slides 					:  	[			// Slideshow Images
											{	image : 'images/slides/01_Nvidia.jpg', 
												title : '<p><strong>Nvidia Headquarters<br>Santa Clara, CA </strong>Workplace<br>2000<br>500,000 sq. ft.</p>'},
											{	image : 'images/slides/02_Netflix.jpg', 
												title : '<p><strong>Netflix Headquarters<br>Los Gatos, CA</strong>Workplace<br>2006<br>160,000 sq. ft.</p>'},	
											{	image : 'images/slides/03_Vmware.jpg', 
												title : '<p><strong>VMware Campus Commons Building<br>Palo Alto, CA</strong>Workplace<br>2007<br>485,000 sq. ft.</p>'},	
											{	image : 'images/slides/04_FallingLotus.jpg', 
												title : '<p><strong>Falling Lotus Blossom<br>Pune, India</strong>Workplace<br>Designed 2004<br>4 million sq. ft.</p>'},  
											{	image : 'images/slides/05_TechDrive.jpg', 
												title : '<p><strong>Technology Drive<br>San Jose, CA</strong>Workplace<br>Designed 2004<br>400,000 sq. ft.</p>'},
											{	image : 'images/slides/06_LyricalSeashore.jpg', 
												title : '<p><strong>Lyrical Seashore<br>Kaohsiung, Taiwan</strong>Cultural<br>Designed 2010<br>1 million sq. ft.</p>'},
											{	image : 'images/slides/07_CrashingWaves_s.jpg', 
												title : '<p><strong>Crashing Waves / Tongyeong <br>Concert Hall<br>Tongyeong, Korea</strong>Cultural<br>Designed 2009<br>500,000 sq. ft.</p>'},
											{	image : 'images/slides/08_BeachHouse.jpg', 
												title : '<p><strong>Beach House<br>San Francisco, CA</strong>Residential<br>2010<br>3,300 sq. ft.</p>'},
											{	image : 'images/slides/09_HBL.jpg', 
												title : '<p><strong>House of <br>Borrowed Light<br>San Francisco, CA</strong>Residential<br>2003<br>2,000 sq. ft.</p>'},
											{	image : 'images/slides/10_Ark.jpg', 
												title : '<p><strong>The Ark<br>Walnut Creek, CA</strong>Residential<br>Designed 2006<br>16,000 sq. ft.</p>'},
											{	image : 'images/slides/11_StJohns.jpg', 
												title : '<p><strong>St. John the Baptist Episcopal Church<br>Aptos, CA </strong>Religious<br>2008<br>6,000 sq. ft.<br>Design Architect: Warren Callister<br>Architect of Record: Form4 Architecture</p>'},
											{	image : 'images/slides/12_CVC.jpg', 
												title : '<p><strong>Carmel Valley Club<br>San Diego, CA</strong>Fitness<br>2001<br>98,000 sq. ft.</p>'}

												
									]
		
	});
	
	
	// Ajax Page Loads
	var hash = window.location.hash.substr(1);
	var href = $('#main_nav a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-5)){
			var toLoad = hash+'.html #content_wrapper';
			loadContent(toLoad);
		}											
	});
	
	
	$('#main_nav a').click(function(){
		$('#main_nav a').removeClass('current');
		console.log("click");
		
		// Add class current to anything but home.
		if($(this).attr('href') != 'index.html'){
			$(this).addClass('current')
		};
    	
		var toLoad = $(this).attr('href')+' #content_wrapper';
		
	    $('#main').fadeOut('fast', function(){loadContent(toLoad);});
	    $('#pre_loader').delay(150).fadeIn('normal');
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);

	    return false;
    });
	
	function loadContent(toLoad) {
		console.log("loadContent called:"+toLoad);
		$('#main').load(toLoad,'',function(){showNewContent()});
    }
    function showNewContent() {
		console.log("show content called");
		if ($('a.email').length > 0){
			$.getScript('js/mailto.js',function(){ 
				$('a.email').mailto();
			});
		};
		$("#main").clearQueue();
    	$('#main').delay(200).fadeIn('slow',function(){hideLoader()});
    }
    function hideLoader() {
		$("#pre_loader").clearQueue();
    	$('#pre_loader').fadeOut('normal');
		
    }
	
	$('img.close').live('click', function(){
		console.log("--> close")
	 	$('#main').fadeOut('slow');
		$('#main_nav a').removeClass('current');
		window.location.hash = '';
	});

	
});


// disable site for IE6 Browsers. Everything does not work.
var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;
if(IE6){

	$(function(){
		
		$("<div>")
			.css({
				'position': 'absolute',
				'top': '0px',
				'left': '0px',
				backgroundColor: 'black',
				'opacity': '0.85',
				'width': '100%',
				'height': '100%',
				zIndex: 5000
			})
			.appendTo("body");
			
		$("<div id='no-ie-6'><img src='images/no-ie6.png' alt='' style='float: left;'/><p><br /><strong>Sorry! This page doesn't support Internet Explorer 6.</strong><br /><br />If you'd like to read our content please <a href='http://getfirefox.org'>upgrade your browser</a>.</p>")
			.css({
				backgroundColor: 'white',
				'top': '50%',
				'left': '50%',
				marginLeft: -210,
				marginTop: -100,
				width: 410,
				paddingRight: 10,
				height: 200,
				'position': 'absolute',
				zIndex: 6000
			})
			.appendTo("body");
	});		
}

	


