// JavaScript Document

// Background scaling

var $panel, $image;

function addCss(cssCode) {
  var styleElement = document.createElement('style');
  styleElement.type = 'text/css';
  if (styleElement.styleSheet) { styleElement.styleSheet.cssText = cssCode; }
  else { styleElement.appendChild(document.createTextNode(cssCode)); }
  document.getElementsByTagName('head')[0].appendChild(styleElement);
}

addCss('#background img { display:none }');

function init() {
  $panel = $('#background');
  $image = $('#background img');
  $content = $('#content');
}

function resize_listener() {
  $image.hide();
  var window_width  = $(window).width();
  if (window_width > 980){
  	$image.css('width',  window_width);
  	};
  $image.show();
}

function add_resize_listener() {
  init();
  $(window).resize(resize_listener);
  resize_listener();
}

$(document).ready(add_resize_listener);

// Rob's Bits

Shadowbox.init();

$(document).ready(function() {
	
	
	$('.panel').hide();
	$('a.hideme').hide();
	
	$('.panel_nav p.close a').click(function() {
		$('.panel').slideUp('fast', function(){
			$('#panel_background').slideUp();
		});
		$.scrollTo('0px',400);
		return false;
	});
	
	$('.panelsNav li a').click(function() {
		var panel = '#'+$(this).attr('class');
		
		$('#panel_background:hidden').show();
		
		if ($('.panel').is(':visible')) {
			currPanel = $('.panel:visible').attr('id');
			
			if (currPanel != $(this).attr('class')) {
				$('.panel').hide();
				$(panel).fadeIn();
			}
			else {
				return false;	
			}
		}
		else {
			$(panel).slideDown('fast', function(){
				$.scrollTo('500px',400);
			});
		}
		
		if ($('.panel:visible').attr('id') == 'id_here_such_as_p2'){
			
			$(panel+' .cycle').cycle({ fx: 'fade', autostop:1, after: function() {
            	$(panel+' .slideshow p').hide();
            	$(panel+' .caption').html(this.alt);
            	$(panel+' .slideshow p').fadeIn('slow');
	     	}});
		
		}
		
		else {
			
			$(panel+' .cycle').cycle({ fx: 'fade', autostop:0, before: function() {
            	$(panel+' .slideshow p').hide();
            	$(panel+' .caption').html(this.alt);
            	$(panel+' .slideshow p').fadeIn('slow');
	     	}});
		
		}
		
		
		
		return false;
	});
		
	
});				





























   
						   
