﻿$(document).ready(function(){

	$('#slides')
		.bind('advance', function(e,num){
			if(num > 5) num = 1;
			if(num < 1) num = 5;
			var slideId = 'slide-' + num;
			$('#' + slideId).trigger('open');
		})
		.bind('next',function(){
			var $open = $('#slides .open');
			var num = Number($open.attr('id').substring(6,7)) + 1;
			$(this).trigger('advance',[num]);
		});
	
	$('.slide')
		.bind('open', function(){
			if(! $(this).hasClass('open')){
				$(this).next().trigger('open');
				$(this).addClass('open');
				$(this).animate({right: "-=766px"});
			}
			else{
				$(this).prev().trigger('close');
			}
			$(this).siblings().removeClass('active');
			$(this).addClass('active');
		})
		.bind('close', function(){
			if($(this).hasClass('open')){
				$(this).removeClass('open');
				$(this).animate({right: "+=766px"});
				$(this).prev().trigger('close');
			}
		});
		

	$('.slidebutton')
		.click(function(){
			$(this).parent().trigger('open');
			$('#content-' + $(this).parent().attr('id')).trigger('show');
		});

	$('.slidecontent').bind('show', function(){
		$('.slidecontent').removeClass('open');
		$(this).addClass('open');
	});
	
});

