$(document).ready(function(){ 
  // change background image and show according quote
  $('.page-change a').click(function(){
	var header = $(this).attr('rel'); // variable of what quote to show
	var image = $(this).attr('data-id'); // variable of what image to show
	// if content section is open empty it and close it
	if ($('.main-site-content').hasClass('open')) {
	  $('.content').animate({width:'toggle'},500);
	  $('.main-site-content').empty();
	  $('.main-site-content').removeClass('open');
	  $('.main-site-content').addClass('closed');	 
	}
	// if image isn't already on toggle it to fade in a new one
	if ($('#'+image).hasClass('hide')) {	
	  toggle_image(image);
	}
	// show/hide quotes
	$('#'+header).siblings().addClass('hide');
	$('#'+header).removeClass('hide');
	// fade quote back in
	$(".panel:not(.hide)").fadeIn('fast');
	$(".panel:not(.hide)").css('display','');
	// call toggle image (change background image)
	return false;
  });  

  // slide content in and out // hide quote so content is more readable
  $('.internal').click(function(){
	var path = $(this).attr('rel');	
	$(".panel:not(.hide)").fadeOut('fast');	
	if ($('.main-site-content').hasClass('closed')) {
	  $('.main-site-content').load(path);
	  $('.content').animate({width:'toggle'},500);
	  $('.main-site-content').removeClass('closed');
	  $('.main-site-content').addClass('open');	 
	} else if ($('.main-site-content').hasClass('open')) {	
	  $('.main-site-content').empty();
	  $('.main-site-content').load(path);				
	}	
    return false;	
  });

  // close content slider and empty it // fade quote back in
  $('.close').click(function(){
	$('.main-site-content').empty();
	$('.main-site-content').removeClass('open');
	$('.main-site-content').addClass('closed');
	$('.content').animate({width:'toggle'},500);	
	$(".panel:not(.hide)").fadeIn('fast');
	$(".panel:not(.hide)").css('display','');	
	return false;
  });
});

// change right side background image depending on clicked link	
function toggle_image(image_id){
  $("#ryan_slide img").css('display','none');
  $("#ryan_slide img").addClass('hide');
  $('#' + image_id).fadeIn(800);
  $('#' + image_id).removeClass('hide');
}
