function layoutChanged(){
	var winHeight = $(window).height();
    var winWidth = $(window).width();
	//Change width of all cells to be the same as the view. Watch out for vertical scrollbars - may cause problems.
	//Check for min width first
	winWidth = winWidth > 799 ? winWidth : 800;
	$(".cell").css('width',winWidth);
	$("#logoCell").css('height',winHeight);
	//logoCell is different - only want the size of the view
	
	//Make wrap width = winWidth *  number of cells + (braceWidth * number of cells - 1)
	var wrapWidth = (winWidth * $(".cell").length) + (377 * $(".cell").length - 1);
	$("#wrap").css('width',wrapWidth);
	
	//align braces
	$(".braces").css('top', (winHeight/2) - 230); //239px is half height
}

function closeTray(e, elem, $pane){
	if(aboutVisible){
		$('#aboutTray').slideToggle('fast');
		aboutVisible = !aboutVisible;
	}
}

function checkTop(){
	if($(window).scrollTop() != 0){
		//We're not at the top
		$.scrollTo('0px', 'slow', {easing:'easeInOutExpo', axis: 'y'});
	}
}

var aboutVisible = false;
var mapLoaded = false;

$(document).ready(function(){
	//Setup slider - not sliders. this is not a wormhole.
	$('#slider-code').tinycarousel({axis:'y'});
	
	$(window).bind("resize", layoutChanged);
	layoutChanged(); //Gotta call it once duh.
	
	//Fade in the text
	$('#wcc').fadeIn(1000,'easeInExpo');
	//$('#sonoma').fadeIn(1000,'easeInExpo');
	setTimeout ( "$('#sonoma').fadeIn(1000,'easeInExpo')", 1000 ); 
	//$('#ivv').fadeIn(1000,'easeInExpo');
	setTimeout ( "$('#ivv').fadeIn(1000,'easeInExpo')", 2000 ); 
	
	//Setup scrolling
	$('#navbar').localScroll({easing:'easeInOutExpo', stop: true, axis: 'x', onBefore:closeTray, onAfter:checkTop});
	
	//Setup about tray
	$('#aboutLink').click(function() {
		$.scrollTo($('#logoCell'), 'fast', {easing:'easeOutExpo', onAfter:function(){
			$('#aboutTray').slideToggle('slow', 'easeInOutExpo', function() {
				aboutVisible = !aboutVisible;
				if(!mapLoaded){
					//$("#mapInner").html("<iframe marginheight='0' marginwidth='0' src='http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Wine+Country+Cyclery,+262+West+Napa+Street,+Sonoma+CA+95476+&amp;sll=41.046217,-95.712891&amp;sspn=39.588578,93.076172&amp;ie=UTF8&amp;hq=&amp;hnear=Wine+Country+Cyclery,+262+W+Napa+St,+Sonoma,+California+95476&amp;t=h&amp;z=14&amp;ll=38.303207,-122.458506&amp;output=embed' frameborder='0' height='300' scrolling='no' width='500'></iframe>");
					$("#mapInner").html("<iframe width='500' height='300' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Wine+Country+Cyclery,+262+West+Napa+Street,+Sonoma,+CA+95476&amp;aq=0&amp;sll=36.161102,-86.77738&amp;sspn=0.011382,0.022724&amp;vpsrc=6&amp;ie=UTF8&amp;hq=Wine+Country+Cyclery,&amp;hnear=262+W+Napa+St,+Sonoma,+California+95476&amp;t=h&amp;cid=14211568906082758914&amp;ll=38.303409,-122.461681&amp;spn=0.020206,0.04283&amp;z=14&amp;iwloc=A&amp;output=embed'></iframe><br /><small><a href='http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=Wine+Country+Cyclery,+262+West+Napa+Street,+Sonoma,+CA+95476&amp;aq=0&amp;sll=36.161102,-86.77738&amp;sspn=0.011382,0.022724&amp;vpsrc=6&amp;ie=UTF8&amp;hq=Wine+Country+Cyclery,&amp;hnear=262+W+Napa+St,+Sonoma,+California+95476&amp;t=h&amp;cid=14211568906082758914&amp;ll=38.303409,-122.461681&amp;spn=0.020206,0.04283&amp;z=14&amp;iwloc=A' style='text-align:left'>View Larger Map</a></small>");
					mapLoaded = !mapLoaded;
				}
			});
		}});
	});
});
