$(function() {		

	function onLoad() {
	
		// define global width
    var $width = 0;
		if ($('body').width() < $('.layout').width()) {
			$('body').css({'overflow-x' : 'auto'});	
			$width = $('.layout').width();
		} else {
			$('body').css({'overflow-x' : 'hidden'});	
			$width = $('body').width();
		}	
		
		// define width for gallery
		$('#header').width($width);
		$('.coda-slider').width($width);
		$('.coda-slider .panel').width($width);
		$('.coda-slider-wrapper').width($width);
		$('.coda-slider-wrapper.arrows .coda-slider').width($width);
		$('.coda-slider-wrapper.arrows .coda-slider .panel').width($width);
		
    var backgroundsPanel = $('#backgrounds .panel');
    backgroundsPanel.width($width);
		$('#backgrounds').width($width);
		$('#backgrounds-slider').width($width * backgroundsPanel.size());

	}

	function equalHeight(group) {
		var tallest = 0;
		group.each(function() {
			var thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}

	
	onLoad();
	equalHeight($('.article'));
					
	$(window).resize(function() {	
	 	onLoad();
	 	
    var $width = 0;
		if ($('body').width() < $('.layout').width()) {
			$width = $('.layout').width();
		} else {
			$width = $('body').width();
		}

    var codaNav = $('.coda-nav');
    if(codaNav.length)
    {
      var slide = $('.coda-slider .panel').size();
      var bg = $('#backgrounds .panel').size();
      var current = parseInt($('.current', codaNav).attr("href").slice(1));

      $('.panel-container').width($width*slide);
      $('.panel-container').css({ 'margin-left' : - $width * (current-1) });
      $('#backgrounds-slider').width($width*bg)
      $('#backgrounds-slider').css({ 'margin-left' : - $width * (current-1) });
    }

	});
	

	$('#gallery').codaSlider({ dynamicArrows: false, autoSlide: true, autoSlideStopWhenClicked: false });	

});
