slide_count = 3;
active_slide = 1;
next_slide = active_slide+1;
prev_slide = slide_count;


slide_switch = true;
story_switch = true;

function toggleStory() {
  story_switch = false;
  if ( $('div.story').css('left') == '0px' ) {
    $('div.story').animate({left: '850px'}, 500, 'swing', function() { story_switch = true; });
    $('#read-story').removeClass('active');
  } else {
    if ( $('div.story').css('left') == '850px' ) {
      $('div.story').animate({left: '0px'}, 500, 'swing', function() { story_switch = true; });
      $('#read-story').addClass('active');
    }
  }
}

function nextSlide() {
  slide_switch = false;
  $('#slide'+active_slide).css('z-index', '1');
  $('#slide'+next_slide).css('z-index', '10');
  $('#slide'+next_slide).fadeIn('slow', function() {
    $('#slide'+active_slide).hide();
    prev_slide = active_slide;
    active_slide = next_slide;
    if (active_slide < slide_count) next_slide += 1;
                               else next_slide = 1;
    slide_switch = true;
  });
}
function prevSlide() {
  slide_switch = false;
  $('#slide'+active_slide).css('z-index', '1');
  $('#slide'+prev_slide).css('z-index', '10');
  $('#slide'+prev_slide).fadeIn('slow', function() {
    $('#slide'+active_slide).hide();
    next_slide = active_slide;
    active_slide = prev_slide;
    if (active_slide > 1) prev_slide -= 1;
                     else prev_slide = slide_count;
    slide_switch = true;
  });
}

function slideClients() {
  $('div.logos').animate(
    {scrollLeft: $('div.logos').scrollLeft()-40},      // offset must be smaller than the smallest logo's width
    700,                                            // time in ms - smaller = faster, greater = slower
    'linear',
    function() {
      offset = $('div.logos').scrollLeft() - $('div.logos img:first').width();
      if ( offset < 0 ) {
        $('div.logos').prepend( $('div.logos img:last') );
        offset = $('div.logos').scrollLeft() + $('div.logos img:first').width();
        $('div.logos').scrollLeft( offset+18 );
      }
      slideClients();
    }
  );
}

function initMenu() {
	$("#menu").lavaLamp({ speed: 300 });
}

function initAlbums() {
	//if ($('#albums').length == 0) return false;

	//$('#albums .album:first-child').addClass('active').css('height', $('#albums .album:first-child').find('.inner').height()).find('.purchase input').show();	
	//$('#albums .active').find('a.toggle').text('hide');
		
	/*$('.album h2, .album a.toggle').click(function() {
		var albumWrapper = $(this).closest('.album');
		if (!albumWrapper.hasClass('active')) {
			$('#albums .active').find('.purchase input').fadeOut();
			$('#albums .active').animate({height: 100});
			$('#albums .active').removeClass('active')
			
			
			albumWrapper.animate(
				{height: albumWrapper.find('.inner').height()},
				function() {
					albumWrapper.addClass('active')
					$('#albums .album:not(.active) a.toggle').text('show');
					$('#albums .active a.toggle').text('hide');
				}
			);
			albumWrapper.find('.purchase input').fadeIn();
		} else {
			albumWrapper.removeClass('active')
			albumWrapper.find('.purchase input').fadeOut();
			albumWrapper.animate({height: 100});
			$('#albums .album:not(.active) a.toggle').text('show');
			$('#albums .active a.toggle').text('hide');
		}
		return false;
	});*/
}

$(document).ready(function() {
  $('a#read-story').click(function() { if (story_switch) toggleStory(); return false; });
  
  $('a#next-slide').click(function() { if (slide_switch) nextSlide(); return false; });
  $('a#prev-slide').click(function() { if (slide_switch) prevSlide(); return false; });
    
  slideClients();
  initMenu();
	initAlbums();
});
